JaccoR / hass-entso-e

Integration for Home Assistant to fetch day ahead energy prices from European countries via ENTSO-e Transparency Platform
Apache License 2.0
185 stars 31 forks source link

Apexcharts series labels showing the wrong value #66

Closed MrOzzOnline closed 2 years ago

MrOzzOnline commented 2 years ago

When you have multiple sensors on the one apexcharts graph series sames are added at the bottom toghether with the current value. Since moving the atrributes to the everage price today entitry the value shown is the last value of the series and not the value at the current time.

Using the code from the readme example and adding a second entity I get this:

image

The circled values ar those from the last bar.

I'm not 100% sure this is an ENTSO-E issue or an apexcharts one, but this integration has changed most recently, so I'm betting on this one.

Code:

type: custom:apexcharts-card
graph_span: 24h
span:
  start: day
now:
  show: true
  label: Now
header:
  show: true
  title: Electriciteitsprijzen Vandaag (€/kwh)
series:
  # This is the entity ID with no name configured.
  # When a name is configured it will be sensor.<name>_average_electricity_price_today.
  - entity: sensor.average_electricity_price_today
    stroke_width: 2
    float_precision: 3
    type: column
    opacity: 1
    color: ''
    data_generator: |
      return entity.attributes.prices_today.map((record, index) => {
        return [record.time, record.price];
      });
  - entity: sensor.injectie_average_electricity_price_today
    stroke_width: 2
    float_precision: 3
    type: column
    opacity: 1
    color: ''
    data_generator: |
      return entity.attributes.prices_today.map((record, index) => {
        return [record.time, record.price];
      });
sfstar commented 2 years ago

In previous releases the apexchart was based on the current hour pricing entity. In order to optimize DB usage only the average electricity price entity now has the attributes with todays prices.

Apexchart uses (with the above config) the state value as the displayed value. Since you're now using the average entity the value doesn't correspond with the latest entry per se but it's the average value of all prices during that day. I see no bug in the behaviour of this integration and apexcharts. You could check if apexchart has the ability to override the displayed value so that the now value is used instead.

MrOzzOnline commented 2 years ago

This is not correct. I've made a new sensor to test and this still is an issue. I've pulled the value from the current price and added the attributes of the average price.

  - platform: template
    sensors:
      testsnsr:
        friendly_name: "test sensor"
        value_template: "{{ states('sensor.current_electricity_market_price') | float }}"
        attribute_templates:
          prices_today: "{{ state_attr('sensor.average_electricity_price_today' , 'prices_today') }}"
          prices_tomorrow: "{{ state_attr('sensor.average_electricity_price_today' , 'prices_tomorrow') }}"

image

MrOzzOnline commented 2 years ago

Filed as a bug at the Apexcharts respository:

https://github.com/RomRider/apexcharts-card/issues/432