Calculating Cost using a Utility Meter Sensor

Hello

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?

sensor

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

utility meter

utility_meter:
  tv_monthly:
    source: sensor.tv_energy
    cycle: monthly
  tv_daily:
    source: sensor.tv_energy
    cycle: daily
  tv_hourly:
    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)
image

    
  - platform: template
    sensors:
      tv_cost_hourly:
        friendly_name: TV Cost Hourly
        unit_of_measurement: '£'
        value_template: "{{ (states('sensor.tv_hourly') | float * 0.16653) | round(4) }}"
  - platform: template
    sensors:
      tv_cost_daily:
        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?

Cheers
Mark

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.