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.
4 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.

1 Like

@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.