Energy: Cost for the individual devices

UPDATE:

Version 0.2.0 (still very early stage) is up.

Now you can input energy (kwh) sensor and electricity price sensot to the integration like you do with energy dashboard, and get daily, monthly, and yearly cost sensors.

I left the possibility to calculate cost from power sensor, but it’s not that precise as fom energy sensor. Only if you don’t have energy sensor for the device you want to calculate cost, use power sensor.

As said, it’s a early beta and its my first custom integration, first python development and probably my first ever proper development project.

3 Likes

@arva This looks great. I am trying to calculate how much it costs to charge my car each day. I am on a variable rate which changes every 30 minutes (Octopus’s Agile tariff in the UK). My car charger (Myenergi Zappi) has an integration which has a sensor for the power delivered to my car. It seems I need to learn and understand Reimann integrations, how to get these to calculate every 30 minutes and some other things before I can even get started. I’ve just lost most of Sunday and feel no closer to do this pretty basic thing. Looks like you are on the way to solving that. I’d be happy to help you test.

Hi!

Actually price change frequency does not matter.

Cost calculation is made every time the energy entity changes. It then calculates the difference between new reading and last reading multiples it with energy price and adds the value to cost.

So it will check the current price on every update. Caveat is that energy sensor must update frequently. Usually it does and if it does not then it would be impossible to calculate cost anyway.

Edge case can be when last known energy reading from the end of hour, let’s say 00:59:30 and next time energy sensor updates one minute interval at 01:00:30. Then the cost will be calculated with the 01:00 price, but some of the energy was actually consumed with last hour price. But for let’s say 10kw power, the half minute energy will be 0.08kwh, and cost with 0.2€/kwh (again edge case where hours difference is 0.2€/keh) is 0.016€, so not so much.

I went with this logic to mitigate the risk of losing data or doing wrong calculations when restart or what ever happens.

If the new value is lower (for example energy sensor resets) it will not do the calculation and just stores the energy value for the next energy sensor update.

This prevents cost decrease. Kind of similar logic as total_increase in HA.

As of calculating cost from Power entity it’s the same. Calculations being made every time power entity changes, but i strongly recommend to use energy sensor instead of power senor tho, couse it’s more precise that from power sensor.

In your case use the Energy consumed today sensor (kWh) in your Myenergi Zappi integration.

As for now the integration is using EUR as hardcoded currency, but you can feed in your GBP/h as price entity. Result cost sensors unit_of_measurement is EUR, but the value is correct. It’s in my to do to make logic that will take the unit of measurement from the inserted energy cost sensor. Meanwhile, you can change the unit of measurement manually in UI.

Great.

I now have two “devices” set up using the integration.

One uses “Zappi power ct internal load” (W) as the Power Usage sensor.

The other uses “Zappi Energy used today” (kWh) as the Energy usage sensor. This sensor resets to 0 at midnight.

They both use the tariff sensor which changes every 30 mins.

Let’s see how they compare after a few days of charging.

1 Like

Probably the kwh one is more precise.

@arva I have a static cost kWh rate here in the US. How am I just setting a default rate using the new dynamic energy costs or is this not what this was designed for?
I have a bunch of devices that keep track of watts consumed and I would just like to turn these into costs associated with the individual devices on the energy monitor tab.

Hi! Make a input number helper and use this as an energy price and you are good to go.

@arva Unfortunately I am not sure what that exactly means. I am still very new to adding any beyond a switch I can turn on/off from my phone. I already read the Input Number and I am lost just like all of the other articles around this. Do you have an example you could provide so I can wrap my head around this?

The tracking energy devices are Shelly EM devices.

How have you found this? I’ve just started to play around and can’t quite get it to match what I think it should… Any help would be awesome!

Assuming it works the way I think, then it is a great option.

The main cost I am trying to track is charging my car. I am on a highly variable rate (Agile Octopus in the UK) and I could not find another option as simple as this for calculating that.

The daily figures look about right. I dont have another way to get any figures for comparison.

I didn’t have to become well acquainted with Reimann Integrations so that was a big plus!

Amazing, I’ll give it a go. In the exact same boat, octopus agile, zappi charger. I can roughly work out from the octopus app how much I’m spending more (charging overnight and can see the higher peaks). I’m not bothered about an exact figure but in the region of is good enough to see how much I’m spending on my EV vs my old petrol Jeep.

I settled on using the Zappi Energy Used Today sensor which is in kWh, and the Octopus Energy integration to get the current rate.

Still trying to figure out which works out cheaper for all my energy use - Intelligent Octopus Go or Agile.

Hello Arva and thanks for your integration ! Little question for your integration : when i create my new integration do i provide the total of consommation of my device (in kWh) or the total of the day of the consommation ? (This sensor return to zero each day)
Thanks a lot, and sorry for my english, i’m french.

I’m now using @arva 's integration for this. Works really well.
I have dynamic energy pricing and solar production.
To calculate electricity cost for the house:
cost : the sensor that measures consuption from net (kwh) linked with a sensor that holds the current energy consumption price €/kwh
rewards : the sensor that measures injection into the net (kwh) linked with a sensor that holds the current energy reward price €/kwh
The net cost is then cost-rewards and is calculated with a template sensor.

For real cost of individual consumers this there is an extra step to take to take into account the percentage drawn from the net vs consumed from own solar panels. For this I use the formule below (in a template sensor):

Real-time cost per kWh=(Ptotal​/Pnet​​⋅Cdc​)+(Ptotal​/Psolar​​⋅Cif​)

Where:

  • Pnet _​ is the power drawn from the net (kWh).
  • Psolar is the power produced by the solar panels (kWh).
  • Ptotal​ is the total power consumed by the household (kWh), calculated as Ptotal=Pnet+Psolar
  • Cdc_ is the cost per kWh from the net (delivery cost).
  • Cif is the injection fee per kWh for power injected into the net (which can be negative).

I can now show the daily/monthly/yearly sensors for all my individual consumers (with an energy meter) in my Lovelace dashboard. Integration in the energy dashboard would be nice to have easy access to the historic data and csv export (would be a nice way to have the real cost of EV charging for accounting for example)
So +1 for this feature request

1 Like

Thanks @arva going to give yours a go. +1 for this feature request in general and voted. Fingers crossed

@arva my plug socket only reports in Watts. I also have an integral helper to calculate the kwh.

Is there any difference to be using your integration with the power in watts, or via my integral helper, or will then essentially be doing the same thing?

1 Like

when i try to use the input helper this comes up

Entity input_number.co_charger_gbp_kwh belongs to domain input_number, expected [‘sensor’]
What should I do?

Solved, created a sensor that gets information from the Input number just created

>   - sensor:
>       - name: Energy Cost
>         state: "{{ states('input_number.energy_cost') }}"
>         unit_of_measurement: "GBP/kWh"