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

I downgraded to 0.6.3 and that seems to work.

Yes we are awere that the code isn’t stable anymore.
We are currently implementing tests to get the current code back stable and hopefully detect future bugs in advance.

1 Like

In the latest version V0.8.2 the reset problem should be solved.

1 Like

Normally you should now be able to find this integration in the HACS store.

1 Like

Hi,

For my vehicle it took a few days before I got it to work. Now I’d like to use the sensor.charge_laadstation_kwh_charge_point_delivered_session_manual_energy_cost which the integration created to get a offset so the value of the year and month sensor are correct again with the home charge app.

I don’t see anything in the documentation for manual_energy_cost.

Can someone explain it to me?

Hello,

I have some problems with this. Some of my integrations is not updating with daily, weekly and monthly prices. Why is that? Is it normal that it can take several days before the numbers start appearing?

Thanks in advance!

Hey guys,

i think i have an beginner question but i hope someone can point me in the correct direction.
I use this Integration, but i would like to keep all the history data from the integration. My recorder setting is purging everything after X days.
What would i need to setup to keep the Dynamic Energy Cost History for longer?

Is this sensor able to take care of the net vs solar consumption? My ev charges mostly on solar but on a cloudy day there always is a little net consumption.

Hi,

I need some help.

When I try to enter the electricity_price_sensor, I get the error ‘Entity None is neither a valid entity ID nor a valid UUID’.

Why is that?
I used a simple helper input_number.
I also tried it with a sensor.

The error keeps coming up.
Am I misunderstanding something?

Thank you very much.

1 Like

I had the same error (‘Entity None is neither a valid entity ID nor a valid UUID’) when trying to change input sensors. The solution for me was to completely delete the entry and create a new entry with the new input sensors (for price an energy).
HTH

For me the same.

1 Like

I have a price sensor that updates in realtime as my tariff changes throughout the day, will this integration calculate the price correctly as the rate changes?