[Custom Integration] Dynamic Energy Cost — Track real-time and interval electricity costs per device

Dynamic Energy Cost — Real-time energy cost tracking per device

Home Assistant’s Energy Dashboard still doesn’t support individual device cost tracking with dynamic electricity prices (like Nord Pool, Tibber, Amber etc.). If you have a fixed price, a template sensor works fine — but with changing prices it gets complex fast.

This custom integration solves that. Point it at any power or energy sensor + your electricity price sensor, and it creates automatic cost sensors that track what each device actually costs you.

GitHub: GitHub - martinarva/dynamic_energy_cost: A Home Assistant integration to provide real-time and cumulative energy cost tracking, optimized for dynamic electricity prices like Nord Pool. · GitHub


How it works

Two calculation modes:

Mode Input Best for
Energy-based (kWh sensor) Energy sensor + price sensor Most precise, preferred method
Power-based (kW sensor) Power sensor + price sensor Devices without energy sensor

Both modes automatically create cost sensors for 15-min, hourly, daily, weekly, monthly, and yearly periods — all resetting automatically.


Key features (v1.0)

  • Installs via HACS — search “Dynamic Energy Cost”
  • Full UI configuration — no YAML needed, entity picker with search
  • Cost sensors appear under the source device — your heat pump’s cost sensors show up right on the heat pump’s device page, not as a separate device
  • Supports dynamic pricing — works with Nord Pool, Tibber, Amber, Octopus, or any sensor that provides current electricity price
  • Supports negative prices and feed-in — handles solar feed-in and negative spot prices correctly
  • Multiple instances — track costs for as many devices as you want
  • Precise calculations — energy-based mode captures every reading change, power-based mode uses sub-second precision

Installation

  1. Open HACS in Home Assistant and search for “Dynamic Energy Cost”
  2. Click Download and restart Home Assistant
  3. Go to Settings > Devices & Services > Add Integration and search for “Dynamic Energy Cost”

Or use direct links:


16 Likes

Great work on this one! Works like a charm.
Is it possible to manually reset all values? A good thing to do when experimenting. :slight_smile: I tried to remove the device and add it, but it’s too smart and reminds the value.

In the latest 0.3.0 release (Release 0.3.0 · martinarva/dynamic_energy_cost · GitHub) I made a reset service you can use.

To reset the energy cost and cumulative kWh for a specific sensor, you can use the following service call in Home Assistant:

service: dynamic_energy_cost.reset_cost
target:
  entity_id: sensor.your_sensor_entity_id
2 Likes

Thanks for the update.
I’ve created a simple script and Button on the homepage to trigger the reset.
Because I won’t make an “Oopsie”, I’ve created the script with an confirmation message.

Script

alias: Charger_Action_Reset_Montly_Costs
use_blueprint:
  path: homeassistant/confirmable_notification.yaml
  input:
    notify_device: <DEVICEID>
    title: Reset Sensor Montly PowerCharger
    confirm_action:
      - service: dynamic_energy_cost.reset_cost
        target:
          entity_id: sensor.car_charger_usage_monthly_energy_cost
        data: {}
    message: >-
      When confirming this action, the montly Charger status will be reset
      to 0.
icon: mdi:rewind

Dashboard button

type: tile
entity: script.action_reset_montlycharger
show_entity_picture: false
name: Reset Montly Charger Status
hide_state: true
vertical: true

When you click on the button on the homepage, it will send a message to your device (in my case, my mobile phone) and I can confirm with clicking on “Confirm”. Only then, the sensor will be reset.

Note: This is an easy and first script for this sensor. Built for testing.

1 Like

I wish you published this a few days earlier. :rofl: I spent a few hours last week creating a multitude of Utility Meter entities, tariff helpers, etc. just to track a couple of devices. :woozy_face:

I haven’t tried your code yet, but it sounds like it should make my job a lot easier next time! :slight_smile: Thank you.

1 Like

I feel you and the reason I made this was exactly this. I still hope, this will be a part of official HA energy dashboard in the future, but until then I hope I save people time a bit.

2 Likes

@arva It’s not a bug, but a request. Is it possible that you change the versions in the manifest.json file? On this moment I didn’t knew if I’ve 0.4.0 or 0.4.1 already. When the manifest.json file is updated, you can see the version in the gui or in the manifest.json file.

1 Like

is there a way to get multiple instances of the integration?

I would like to calculate cost using same kWh meter and different rates and later compare them, any tips how to get it?

EDIT: nevermind :slight_smile: there is ADD ENTRY on the integration…

EDIT 2: does not create any entities :frowning:
any clue?

Maybe there is something in the logs? Also try the new 0.4.2 version.

1 Like

My Tasmota plugs give three sensors for this that I could use. I’m presuming that I need the total sensor but can you clarify please?

I have

sensor.kettle_energy_power = w
sensor.kettle_energy_total = kWh
sensor.kettle_energy_today = kWh

yes, upgrading solved the problem, Thank you!

both of these work:
sensor.kettle_energy_total = kWh
sensor.kettle_energy_today = kWh

Thanks for this! awesome integration! is it possible to change the currency? My nordpool is in SEK not EUR.

1 Like

I just translated EUR in all documents in \config\custom_components\dynamic_energy_cost to NOK for this purpose. I used notepad++, opened all the files, and used the replace in all open documents for this. This is propably not a good way to do this, but it seemed to work for me :slight_smile:

Also I changed the divisor value in the file “power_based_sensors.py” on line 85 from “/ 1000” to “/ 1000000” as Nordpool provides prices in øre and not kroner/NOK.

It probably is not the smartest workaround, as some/all of it would be overwritten by the next update.

The change from EUR to NOK/SEK etc. could maybe be implemented in the translations in “\config\custom_components\dynamic_energy_cost\translations” ?

1 Like

I’ve been using this for a while now, and it makes it much easier to calculate running costs for individual devices such as an EV.

What is the simplest way to display the cost for the previous calendar month and the cost over the previous 30 days?

I’m also interested in displaying the average and maximum monthly cost.

Weekly would also be useful.

A use case would be calculating actual cost of running an EV during a period of time for tax returns or expense claims.

Great integration! Would it be possible to get a weekly energy cost entity? Thanks!

Great work. Was looking for something similiar for ages.
One request: Would it be possible to get a entity without reset?

Fantastic integration. Saves a ton of work. Thank you!!

1 Like

Great work! Working perfect with my 16A Puck Relay. Crossing fingers for user selectable currency, as I use NOK and not EUR

2 Likes

Excellent work Arva! This is terrific!
Thank you very much!!

A few neat additions if possible:

  • User selectable Currency
  • Reset schedule… for example, regularly resetting the monthly sensors at the end of the billing period i.e the 27th day of each month (I am aware this can be done with automation - its just a “nice to have” feature request)

Thank you again! :slight_smile: