Calculating Cost using a Utility Meter Sensor


I finally managed to get my Utility sensors working as they should, but what is the best way to get the cost of the persistent data sorted from a utility sensor please?


  - platform: integration
    source: sensor.tv_power
    name: tv energy
    unit_prefix: k
    round: 2

utility meter

    source: sensor.tv_energy
    cycle: monthly
    source: sensor.tv_energy
    cycle: daily
    source: sensor.tv_energy
    cycle: hourly   

I thought it would be like this but it appears to just add it up and not sure how I should be going about it? as when I reboot HA the sensor shows 0 (see the graph drop)

  - platform: template
        friendly_name: TV Cost Hourly
        unit_of_measurement: '£'
        value_template: "{{ (states('sensor.tv_hourly') | float * 0.16653) | round(4) }}"
  - platform: template
        friendly_name: TV Cost Daily
        unit_of_measurement: '£'
        value_template: "{{ (states('sensor.tv_daily') | float * 0.16653) | round(4) }}"   

I have a simple standard tariff, so any ideas please?


Sensors aren’t persistent across reboots. You could create an input_number to store the value. If you don’t set an initial value, it will be persistent.

Then you need to store the values. A easy way would be to store the current sensor value on home Assistant restart or shutdown event.

Now add this input_number as an offset in your sensor.

I’ve read this a few times and I think I finally get it, thanks!

How do people keep their utility meter readings after database purges? or do you just keep long term values in influxdb?

I use input_number to store values.

Easiest thing would be to update the input number when home Assistant reboots. Home Assistant sends an event on reboot that you can use as an automation trigger.

A different DB is the solution, as you’ve found out. InfluxDB is certainly one possible solution.

I’m using emonCMS:
That is an energy monitoring tool designed for everything electricity related. I’ve got CT sensors feeding data into a different Pi running emonCMS and then sends data to HA.
You seem to have HA already set up with sensors, you can send data from HA to emonCMS. Then set up the feeds in emonCMS, it will save all data permanently until you go to delete stuff. There’s also a handy data trim tool, for example to delete years old data.

1 Like

thanks, I had never seen this before… What are you using with CT sensors please? are they connected to a RPi or arduino board? or something else?

You can use their emonPi, which is their solution that works straight out of the box:
Nice bit of kit, though a bit expensive at £200.
(okay, just had another look, no enclosure unassembled is more reasonable at £105, 1 less CT sensor but otherwise comparable to my setup)

For me, after upgrading to Pi 4 for Home Assistant, I’ve got a 3B to spare. So I bought this CT sensor hat with their matching CT *3 and voltage sensors, £51, put it on my old Pi 3 running emonPi image.

nice one… thanks so much for this. I did see they did their own but as you say, a tad expensive.

can you calculate the cost of electricity use in emonCMS? so it displays in HA via

Yes. In emonCMS, any input is listed in the “Input” table, this includes stuff from HA. In the Input table, you can do loads of things with it. There is a kwh converter, a kwhd (kwh day) converter, you can do calculations on your data, even with another input (eg. grid + solar = house consumption). The last bit means you can create a cost of electricity use by multiply with your per unit cost.

All the results can be fed into a “Feeds” table. From that table, you can get the data into HA or into their other tools, such as “apps” or graphs.

If you are in UK, I’ve just discovered there is an “app” that can match your usage against Octopus Agile smart tarrif that changes every 30min. Looks like my average unit rate would only cost 6.2p per kWh if I were on Agile.

1 Like

thanks for this… looks like I have a new project over yet another wet weekend :slight_smile:

one more question sorry :smiley:

Did you get these sensors?

AC Voltage sensor:

  • UK: 77DB-06-09

Yes. I purchased the matching voltage sensor as specified by their website to go with the RPICT3V1 CT sensor hat.

Depend on your meter location, it might be difficult getting somewhere to plug in. I was fortunate enough to have the meter my study (formerly garage), next to some power sockets.

Let me know if you need any help setting everything up. The emonCMS interface takes some getting use to. My initial mistake is making too many feeds for calculations, whereas everything should be done on the input page. Each step that does calculation will output into the next row.

nice one thanks again… I have power near my fusebox, not sure on the space behind it for the clamps, but will have a look tonight hopefully.

and I installed emonCMS docker earlier and I was confused as hell…

I can vouch for the EmonCMS, I got the RPICT3V1 last week and have spent today calibrating it and integrating in to HA. Works really well I just need to create a dashboard display now.

1 Like

what did you need to do to calibrate it?

I found the voltage was reading 220v so recalibrated it.

as I was saying to papasierra, I think I cocked up big time. I spent all day today doing this but I did’t buy the voltage sensor, as I thought it wasn’t needed or I could use any AC.DC adapter I have lying around… WRONG

Oh dear, I hope you haven’t damaged the board, It should be a AC to AC power supply not AC to DC.
I had a mains transformer around that gave out 10v so used that and recalibrated the VCAL as in the link earlier.

Yeah it is fine but another stupid mistake by me :smile: