Dynamic Energy Cost

There is still no Individual devices cost functionality in Energy Dashboard which has a feature request here: Energy: Cost for the individual devices

So there is workaround using Gas part of the Energy Dashboard, but if you have gas as well, there is no good way how to do it.

If you have fixed electricity price, its pretty easy to with an template sensor, but if you have changing electricity price like Nordpool for example, it gets pretty complex.

I had a method how to do it from a device power sensor described here: Calculate device energy costs using dynamic electricity price like Nordpool

This approach is working nicely, but there are two issues:

  1. Quite a lot of code to write in configuration.yaml
  2. From power sensor using integration left method the result is not not that precise

So i took a leap and wrote my first custom integration Dynamic Energy Cost. It’s in early beta stage but main functionality is working already.

There are two ways of calculating the cost:

  1. From energy (kwh) sensor - this is a preferred way as it’s more precise. Calculations are made every time energy sensor changes. Difference between last reading and current reading are multiplied by current electricity price and added to the daily, monthly, yearly cost sensors which will reset accordingly.
  2. From power (kw) sensor - if your device don’t have energy sensor, you can use this. It has same integration left method logic to calculate cost. daily, monthly, yearly cost sensors which will reset accordingly.

Roadmap:

  • Hacs. At the moment only manual install
  • Integration configuration ui to have filtered list where you can search entities. At the moment manual entry only.
13 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: