RomRider / apexcharts-card

đŸ“ˆ A Lovelace card to display advanced graphs and charts based on ApexChartsJS for Home Assistant
MIT License
1.14k stars 78 forks source link

Daily average energy price using statistics... #542

Closed salzrat closed 1 year ago

salzrat commented 1 year ago

Checklist

Is your feature request related to a problem? Please describe. I use an integration that adds hourly power consumption from my smartmeter to a statistics entity. Since the data comes 1 day late, the entity has only statistics, no state. I can display this nicely with apexcharts. However, I cannot (or do not know) how to do any calculations with it.

Since apexcharts knows how to access the statistics, maybe there is some way how to add some functionality to access statistical data to calculate averages.

Describe the solution you'd like Concretely, I would like to calculate my daily average energy price based on an hourly tariff (from Epex), i.e.: hour1_consumptionhour1_price + hour2_consumptionhour2_price + ... /total_daily_consumption. I'd like to plot the result in a chart and compare with the average energy price.

Describe alternatives you've considered I can't think of any.

Additional context The smartmeter integration is described here: https://github.com/DarwinsBuddy/WienerNetzeSmartmeter and the spot energy prices here: https://github.com/mampfes/ha_epex_spot

Currently, I'm plotting the energy price and consumption over one day like this:

type: custom:apexcharts-card
header:
  show: true
  title: Spot vs Energy
graph_span: 1day
span:
  start: day
  offset: '-2day'
yaxis:
  - id: kw
    min: 0
    opposite: true
  - id: price
    min: auto
all_series_config:
  show:
    legend_value: false
  curve: stepline
  stroke_width: 2
series:
  - entity: sensor.epex_spot_at_price
    yaxis_id: price
    unit: ct/kWh
    type: line
    transform: return x * 1.2 * 1.03 / 10
    show:
      extremas: true
  - entity: sensor.atxxx_statistics
    yaxis_id: kw
    type: line
    statistics:
      type: state

image

rakimi commented 1 year ago

Dear @salzrat, I'm not the owner of this product or it code. I just came across this bug. It is possible to have calculated variables for sensors: like this: sensor:

salzrat commented 1 year ago

Yes, that is possible. But what I would need is to compute an average based on historical values of sensor states. Actually, a combination of statistics values for each hour of a day (because the smartmeter integration provides an entity that has only statistics, but no state), and the corresponding values from the epex spot-price...

rakimi commented 1 year ago

Dear @salzrat, I'm not the owner of this product or it code. I just came across this bug. It is possible to have calculated variables for sensors: like this:

sensor:
  - platform: template
    sensors:
      mysensorname:
        friendly_name: "Water usage cost"
        unit_of_measurement: "EUR"
        icon_template: "mdi:currency-eur"
        value_template: >-
          {% set a = states('sensor.waterverbruik_vandaag') | float %}
          {% set b = states('input_number.cost_per_liter') | float %}
          {% set c = states('input_number.vat') | float  %}
          {% set d = states('input_number.fixedcosts') | float / 365 %}
          {{ (((a * b) + a * c) + d) | round(2) }}

Disclaimer: I'm not an expert in Homeassistant setups at all, so please don't ask any detailed questions. I just want to point out that it is possible to define a new calculated value based on other values

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

salzrat commented 1 year ago

I ended up writing a huge sql query with the sql query integration, that works now...

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 10 days with no activity.