JonasPed/homeassistant-eloverblik

Help with the eloverblik/Nordpool template sensor

Closed this issue · 12 comments

I have integrated the template sensor from the readme and it works really well. But I would really like to try to implement a bar chart showing the price our by hour over the current day. I have been looking at Apexchart, but as far as I can tell I need to add start/end time for the rates - right now I only have a comma separated list of rates.

I have been looking at the template to see if I could create an array along the lines of the raw data from the Nordpool integration, but I am struggling how to do this. Any pointers on how to do this?

I am having the exact same issue. Did you figure it out?

I'm having the same issue. The amounts doesn't make any sense either. Right now the price including tariffs, taxes etc. is around DKK 1.5, but the template sensor reports 3.02.

I'd really love to have this fixed! :-)

I've attached the examples. My raw nordpool data is "tainted" with iirc 1.4 as a manual tariff added. Thus I'd love the more correct integration to work. :-)

Raw nordpool data:
raw_nordpool

Raw template sensor data:
raw_eleccost

I'm having the same issue. The amounts doesn't make any sense either. Right now the price including tariffs, taxes etc. is around DKK 1.5, but the template sensor reports 3.02.

I'd really love to have this fixed! :-)

I don't see this is an issue with Eloverblik integration?

Unfortunately Apexchart configuration.

I don't see this is an issue with Eloverblik integration?

You just had the bad luck of including the code for it on your Github front page I guess 😅

I don't see this is an issue with Eloverblik integration?

You are right, it is not. And maybe the wrong place to bring up the discussions, probably should have been raised in the HA forums, which I have now done.

For what it is worth and if anybody should stumble over this issue looking for something similar, I have managed to make it work in a very crude hacky manner by pulling out the data in NodeRed and with a function node add a timestamp for each value and injecting it back into a new sensor in HA. I am certain that my solution is not the most efficient nor elegant, but with my abilities this was what I could make work. But as Jonas correctly states, this is not an issue with this custom integration and probably should be closed.

Mine looks like this:

- name: "Electricity Cost"
  unique_id: electricity_cost
  device_class: monetary
  unit_of_measurement: "DKK"
  state: >
    {{ (1.25 * float(states('sensor.eloverblik_tariff_sum'))) + float(states('sensor.nordpool')) }}
  attributes:
    today: >
      {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool', 'raw_today') -%}
        {%- set ns = namespace (prices=[]) -%}
        {%- for item in state_attr('sensor.nordpool', 'raw_today') if item is defined -%}
          {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
          {%- set price = item.value + tarif -%}
          {%- set hour = as_timestamp(item.start) | int -%}
          {%- set ns.prices = ns.prices + [[hour, price]] -%}
        {%- endfor -%}
        {{ ns.prices }}
      {%- endif -%}
    tomorrow: >
      {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool', 'raw_tomorrow') -%}
        {%- set ns = namespace (prices=[]) -%}
        {%- for item in state_attr('sensor.nordpool', 'raw_tomorrow') if item is defined -%}
          {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
          {%- set price = item.value + tarif -%}
          {%- set hour = as_timestamp(item.start) | int -%}
          {%- set ns.prices = ns.prices + [[hour, price]] -%}
        {%- endfor -%}
        {{ ns.prices }}
      {%- endif %}

I am using the apex charts plugin to show my charts, the data that that is using, looks like this:

type: custom:apexcharts-card
experimental:
  color_threshold: true
series:
  - entity: sensor.electricity_cost
    name: Pris
    type: column
    float_precision: 4
    data_generator: |
      return entity.attributes.today
        .concat(entity.attributes.tomorrow)
        .filter((x) => !!x)
        .map(([hour, price]) => {
          return [new Date(hour * 1000), price];
          });
    color_threshold:
      - value: 1
        color: hsl(100, 60%, 70%);
      - value: 2
        color: hsl(60, 50%, 70%);
      - value: 2.3
        color: hsl(30, 50%, 70%);
      - value: 2.7
        color: hsl(10, 70%, 70%);
      - value: 3
        color: hsl(0, 90%, 70%);
      - value: 5
        color: hsl(0, 90%, 60%);
graph_span: 2d
span:
  start: day
  offset: '-0d'
now:
  show: true
  label: Nu
apex_config:
  chart:
    type: area
    height: 300
  stroke:
    show: true
    width: 3
  legend:
    show: false
  dataLabels:
    enabled: false
  yaxis:
    min: 1
    labels:
      formatter: |
        EVAL:function(value) {
          return `${value.toPrecision(3).toLocaleString('da-DK')} kr`;
        }
  xaxis:
    type: datetime
    labels:
      datetimeFormatter:
        month: ddd
        day: ddd

Turns into a chart that looks like this:
image

Mine looks like this:

- name: "Electricity Cost"
  unique_id: electricity_cost
  device_class: monetary
  unit_of_measurement: "DKK"
  state: >
    {{ (1.25 * float(states('sensor.eloverblik_tariff_sum'))) + float(states('sensor.nordpool')) }}
  attributes:
    today: >
      {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool', 'raw_today') -%}
        {%- set ns = namespace (prices=[]) -%}
        {%- for item in state_attr('sensor.nordpool', 'raw_today') if item is defined -%}
          {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
          {%- set price = item.value + tarif -%}
          {%- set hour = as_timestamp(item.start) | int -%}
          {%- set ns.prices = ns.prices + [[hour, price]] -%}
        {%- endfor -%}
        {{ ns.prices }}
      {%- endif -%}
    tomorrow: >
      {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool', 'raw_tomorrow') -%}
        {%- set ns = namespace (prices=[]) -%}
        {%- for item in state_attr('sensor.nordpool', 'raw_tomorrow') if item is defined -%}
          {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
          {%- set price = item.value + tarif -%}
          {%- set hour = as_timestamp(item.start) | int -%}
          {%- set ns.prices = ns.prices + [[hour, price]] -%}
        {%- endfor -%}
        {{ ns.prices }}
      {%- endif %}

I am using the apex charts plugin to show my charts, the data that that is using, looks like this:

type: custom:apexcharts-card
experimental:
  color_threshold: true
series:
  - entity: sensor.electricity_cost
    name: Pris
    type: column
    float_precision: 4
    data_generator: |
      return entity.attributes.today
        .concat(entity.attributes.tomorrow)
        .filter((x) => !!x)
        .map(([hour, price]) => {
          return [new Date(hour * 1000), price];
          });
    color_threshold:
      - value: 1
        color: hsl(100, 60%, 70%);
      - value: 2
        color: hsl(60, 50%, 70%);
      - value: 2.3
        color: hsl(30, 50%, 70%);
      - value: 2.7
        color: hsl(10, 70%, 70%);
      - value: 3
        color: hsl(0, 90%, 70%);
      - value: 5
        color: hsl(0, 90%, 60%);
graph_span: 2d
span:
  start: day
  offset: '-0d'
now:
  show: true
  label: Nu
apex_config:
  chart:
    type: area
    height: 300
  stroke:
    show: true
    width: 3
  legend:
    show: false
  dataLabels:
    enabled: false
  yaxis:
    min: 1
    labels:
      formatter: |
        EVAL:function(value) {
          return `${value.toPrecision(3).toLocaleString('da-DK')} kr`;
        }
  xaxis:
    type: datetime
    labels:
      datetimeFormatter:
        month: ddd
        day: ddd

Turns into a chart that looks like this: image

Can you put a screendump of you config?

My conf.yaml wont accept it. :(

same here... Phimour can you paste your complete sensor-part of config?

Hi

Here is my code:

sensor:

template:
  - sensor:
    - name: "Electricity Cost"
      unique_id: electricity_cost
      device_class: monetary
      unit_of_measurement: "kr/kWh"
      state: >
        {{ (1.25 * float(states('sensor.eloverblik_tariff_sum'))) + float(states('sensor.nordpool_kwh_dk1_dkk_3_095_025')) }}
      attributes:
        today: >
          {% if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'today') %}
            {% set ns = namespace (prices=[]) %}
            {% for h in range(24) %}
              {% set ns.prices = ns.prices + [(1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[h]) + float(state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'today')[h])) | round(5)] %}
            {% endfor %}
            {{ ns.prices }}
          {% endif %}
        tomorrow: >
          {% if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'tomorrow') %}
            {% set ns = namespace (prices=[]) %}
            {% for h in range(24) %}
              {% set ns.prices = ns.prices + [(1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[h]) + float(state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'tomorrow')[h])) | round(5)] %}
            {% endfor %}
            {{ ns.prices }}
          {% endif %}
        raw_today: >
          {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'raw_today') -%}
            {%- set ns = namespace (prices=[]) -%}
            {%- for item in state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'raw_today') if item is defined -%}
              {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
              {%- set price = item.value + tarif | round(5) -%}
              {%- set start =item.start|string -%}
              {%- set end =item.end|string -%}
              {%- set ns.prices = ns.prices + [{"start": start, "end":end, "value": price}] -%}
            {%- endfor -%}
            {{ ns.prices }}
          {%- endif -%}
        raw_tomorrow: >
          {%- if state_attr('sensor.eloverblik_tariff_sum', 'hourly') and state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'raw_tomorrow') -%}
            {%- set ns = namespace (prices=[]) -%}
            {%- for item in state_attr('sensor.nordpool_kwh_dk1_dkk_3_095_025', 'raw_tomorrow') if item is defined -%}
              {%- set tarif = 1.25 * float(state_attr('sensor.eloverblik_tariff_sum', 'hourly')[loop.index0]) -%}
              {%- set price = item.value + tarif | round(5) -%}
              {%- set start =item.start|string -%}
              {%- set end =item.end|string -%}
              {%- set ns.prices = ns.prices + [{"start": start, "end":end, "value": price}] -%}
            {%- endfor -%}
            {{ ns.prices }}
          {%- endif -%}

apexcharts

type: custom:apexcharts-card
graph_span: 2d
header:
  title: Energy price today (dkk/kWh)
  show: true
span:
  start: day
  offset: '-0h'
now:
  show: true
  label: Nu
series:
  - entity: sensor.electricity_cost
    type: column
    float_precision: 2
    data_generator: |
      return entity.attributes.raw_today
        .concat(entity.attributes.raw_tomorrow)
        .map((start, index) => {
        return [new Date(start["start"]).getTime(), start["value"]];
      });
apex_config:
  chart:
    type: area
    height: 300
  stroke:
    show: true
    width: 2
  yaxis:
    min: 1
    labels:
      formatter: |
        EVAL:function(value) {
          return `${value.toPrecision(3).toLocaleString('da-DK')} kr`;
        }
  xaxis:
    type: datetime
    labels:
      datetimeFormatter:
        month: ddd
        day: ddd

image

There hasn't been any activity on this issue recently. Issue will be marked as stale and closed after 7 days without any activity.