Create sensor with estimated power usage that updates regularly

I’m in the process of measuring all the energy usage of my house’s devices by use of smart plugs throughout. Some devices use pretty much constant power such as fridges and freezers. Now that I know their energy usage, I would like to create a sensor that uses this known wattage (say 90w) and have that being updated throughout the day so that my daily accumulated energy usage is included and I can use the smart plug elsewhere.

I’ve tried in this way but for some reason it doesnt show up:

- name: "Freezer Energy Usage"
  unit_of_measurement: "kWh"
  state_class: "total_increasing"
  device_class: "energy"
  state: >
    {% set watts = 90 %}
    {% set kwh_per_day = (watts / 1000) * 24 %}
    {% set start_time = as_timestamp(now().replace(hour=0, minute=0, second=0)) %}
    {% set hours_today = (as_timestamp(now()) - start_time) / 3600 %}
    {% set kwh_today = (kwh_per_day / 24) * hours_today %}
    {{ kwh_today }}
  update_interval: 
    minutes: 1

1 Like

Thanks, that worked for what I need.

Although I’m having issues using it for the discovery of existing connected items.