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

1 Like

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