Dynamic Energy Cost

Hi all,

I’ve been exploring the Dynamic Energy Cost Integration and as far as I understand, it calculates the average price for the selected timeframe (hour, day, week, month, year), and only resets its internal values when the automation service dynamic_energy_cost.reset_cost is called.

That works fine — but it sparked an idea:

What if the cost data per sensor could be stored before each reset?

This way, we could build:

  • Monthly bar charts showing energy costs per device
  • Daily/hourly breakdowns for specific sensors
  • Year-to-date overviews with historical comparisons
  • Maybe even correlate usage vs. price spikes


(Image source: ApexCharts Tutorial: Advanced Graphs For Your HA UI - SmartHomeScene)

Instead of just resetting and losing the past values, Home Assistant could store them in a long-term statistics entity or expose them for use in dashboards or export.

What do you think?
Would this be a useful feature?
Are there any workarounds already for this?

Looking forward to your thoughts!

Another idea I’d like to share:

I have 20+ energy sensors in my house, covering many appliances – but obviously, not everything is metered. Lamps, sockets, the oven and stove, for example, aren’t (yet) connected to energy sensors.

Still, I do have an overall consumption and cost sensor from the electricity meter at the main supply.

So here’s what I’d like to achieve:

Create a calculated entity that shows the energy cost of “other/unmonitored devices”, by subtracting the total cost of all metered devices from the main meter cost.

Formula idea (pseudocode):

other_device_cost = total_cost_from_main_meter
                    - sum(cost_from_all_known_sensors)

This should be dynamic, so as I add more sensors over time, they’re automatically included in the subtraction.

Use Case: This would give a much clearer view of where energy disappears — and help prioritize what to meter next.

Questions:

  • Has anyone already done this via a template sensor or utility meter setup?
  • Would you find such a feature useful if built into the integration?

Looking forward to ideas and feedback!

I am getting tons of these errors:

2025-04-14 18:48:01.468 ERROR (MainThread) [custom_components.dynamic_energy_cost.sensor] Failed to update energy costs due to an error: unsupported operand type(s) for +: 'NoneType' and 'float'

I am using this sensor for the energy cost:

And this is how i configured integration

What to do?

Same problem here… did someone found some kind of solution?

Guys I need some help

That’s the best way to create the automation to reset the Dynamic Energy Cost counters: hourly, daily, weekly, monthly, and yearly for all entities with the according name

sensor.“VARIABLE ENTITY NAME”_kwh_hourly_energy_cost
sensor.“VARIABLE ENTITY NAME”_kwh_daily_energy_cost
sensor.“VARIABLE ENTITY NAME”_kwh_weekly_energy_cost
sensor.“VARIABLE ENTITY NAME”_kwh_monthly_energy_cost
sensor.“VARIABLE ENTITY NAME”_kwh_yearly_energy_cost

How did you guys do it?

Which release you were using at that time?
I downloaded version 0.6.2, made the change you were talking and now the errors are disappeared…
Maybe the problem lies in the versions after this.
And now which release are you using?
If you have a newer release that is working, please tell me which changes did you made and if possible send me the modified sensor.py.
Thanks in advance

For this you can use the HACS integration Powercalc more info see link below
https://docs.powercalc.nl/quick-start/

Good idea, as a temporary solution you can create a sensor in Home Assistant see Template - Home Assistant

Currently, I myself think it is best to create code testing for the integration, so that we can take out any errors currently in the code and try to mitigate future errors.

Hey Guys, I am struggling with the Automation for the reset.
It looks like it works … each hour / day / week / month / year the dynamic_energy_cost.reset_cost is triggered and the Value goes to 0€/h day week month year…

but seconds later all the “old” values come back and the prices go up again to roughly the same value than before the reset.

I reset the “Action” manually but that DEC Sensor of the Projector did not reset to 0 and stayed at 0,51€

target:
  entity_id:
    - sensor.beamer_kwh_hourly_energy_cost
action: dynamic_energy_cost.reset_cost
data: {}

Hourly Reset

alias: Dynamic Energy Cost - Reset costs of all hourly Sensors
description: >
  Trigger: Jede volle Stunde, Aktion: Reset aller *_kwh_hourly_energy_cost Sensoren
trigger:
  - platform: time_pattern
    hours: "*"
    minutes: 0
    seconds: 0
condition:
  - condition: template
    value_template: >
      {{ states.sensor | selectattr('entity_id', 'match',
      '_kwh_hourly_energy_cost$') | list | length > 0 }}
action:
  - service: dynamic_energy_cost.reset_cost
    target:
      entity_id: >
        {% set sensors = states.sensor
            | selectattr('entity_id', 'match', '_kwh_hourly_energy_cost$')
            | map(attribute='entity_id')
            | list %}
        {{ sensors if sensors | length > 0 else ['sensor.dummy_does_not_exist'] }}
    data:
      label_id: kosten_stundlich
mode: single


Daily reset

alias: Dynamic Energy Cost - Reset costs of all daily Sensors
description: >
  Trigger: Jeden Tag um Mitternacht, Aktion: Reset aller *_kwh_daily_energy_cost
  Sensoren
triggers:
  - at: "00:00:00"
    trigger: time
conditions:
  - condition: template
    value_template: >
      {{ states.sensor | selectattr('entity_id', 'match',
      '_kwh_daily_energy_cost$') | list | length > 0 }}
action:
  - service: dynamic_energy_cost.reset_cost
    target:
      entity_id: >
        {% set sensors = states.sensor
            | selectattr('entity_id', 'match', '_kwh_daily_energy_cost$')
            | map(attribute='entity_id')
            | list %}
        {{ sensors if sensors | length > 0 else ['sensor.dummy_does_not_exist'] }}
    data:
      label_id: kosten_taglich
mode: single

Weekly Reset

alias: Dynamic Energy Cost - Reset costs of all weekly Sensors
description: >
  Trigger: Jeden Sonntag um Mitternacht, Aktion: Reset aller
  *_kwh_weekly_energy_cost Sensoren
triggers:
  - at: "00:00:00"
    trigger: time
conditions:
  - condition: and
    conditions:
      - condition: template
        value_template: |
          {{ now().weekday() == 6 }}
      - condition: template
        value_template: >
          {{ states.sensor | selectattr('entity_id', 'match',
          '_kwh_weekly_energy_cost$') | list | length > 0 }}
action:
  - service: dynamic_energy_cost.reset_cost
    target:
      entity_id: >
        {% set sensors = states.sensor
            | selectattr('entity_id', 'match', '_kwh_weekly_energy_cost$')
            | map(attribute='entity_id')
            | list %}
        {{ sensors if sensors | length > 0 else ['sensor.dummy_does_not_exist'] }}
    data:
      label_id: kosten_wochentlich
mode: single

Monthly Reset

alias: Dynamic Energy Cost - Reset costs of all monthly Sensors
description: >
  Trigger: Am 1. jeden Monats um Mitternacht, Aktion: Reset aller
  *_kwh_monthly_energy_cost Sensoren
triggers:
  - at: "00:00:00"
    trigger: time
conditions:
  - condition: and
    conditions:
      - condition: template
        value_template: |
          {{ now().day == 1 }}
      - condition: template
        value_template: >
          {{ states.sensor | selectattr('entity_id', 'match',
          '_kwh_monthly_energy_cost$') | list | length > 0 }}
action:
  - service: dynamic_energy_cost.reset_cost
    target:
      entity_id: >
        {% set sensors = states.sensor
            | selectattr('entity_id', 'match', '_kwh_monthly_energy_cost$')
            | map(attribute='entity_id')
            | list %}
        {{ sensors if sensors | length > 0 else ['sensor.dummy_does_not_exist'] }}
    data:
      label_id: kosten_monatlich
mode: single

Yearly Reset

alias: Dynamic Energy Cost - Reset costs of all yearly Sensors
description: >
  Trigger: Am 1. Januar um Mitternacht, Aktion: Reset aller
  *_kwh_yearly_energy_cost Sensoren
triggers:
  - at: "00:00:00"
    trigger: time
conditions:
  - condition: and
    conditions:
      - condition: template
        value_template: |
          {{ now().month == 1 and now().day == 1 }}
      - condition: template
        value_template: >
          {{ states.sensor | selectattr('entity_id', 'match',
          '_kwh_yearly_energy_cost$') | list | length > 0 }}
action:
  - service: dynamic_energy_cost.reset_cost
    target:
      entity_id: >
        {% set sensors = states.sensor
            | selectattr('entity_id', 'match', '_kwh_yearly_energy_cost$')
            | map(attribute='entity_id')
            | list %}
        {{ sensors if sensors | length > 0 else ['sensor.dummy_does_not_exist'] }}
    data:
      label_id: kosten_jahrlich
mode: single