Getting daily and monthly energy usage from a total kWh sensor - utility_meter not working

Hi!

First of all, a huge thank you to the developers and everybody involved in the forums, it has been a breeze to set everything up so far. Although there is one minor thing that doesn’t quote work yet or that I rather don’t really understand.

I have two Zigbee power outlets that report the total amount of energy used. It’s a simple numeric sensor that just counts “lifetime” kWh usage should be no issue here.

I am adding values of two outlets together with this template:

sensor:
  # Sensor templates
  - platform: template
    sensors:
      # Tuya plugs total energy
      total_kwh:
        unit_of_measurement: "kWh"
        value_template: "{{ ( states('sensor.tuya_smart_plug_01_energy') | float + states('sensor.tuya_smart_plug_02_energy') | float ) | round(2) }}"

I want to get the mothly and daily energy usage out of this value, but the utility_meter integration, which I thought was fitting here, provides wrong values.

This configuration:

# Utility Meter integration
utility_meter:
  energy_daily:
    source: sensor.total_kwh
    cycle: daily
  energy_monthly:
    source: sensor.total_kwh
    cycle: monthly

results in this output:

2021-03-19 09.33.26

Which does not make sense, as the sensor.total_kwh is only reporting about 5 kWh. It seems like on a restart of HASS to reload the config, the current value is added to the daily meter. I think the utility_meter is probably rather used for meters, that to emit a daily kWh value, from what I understand.

So is there an easy way to create a sensor that creates daily and monthly values from a cumulative, total meter?

Thanks in advance!

Solved! Somehow the utility_meter sensor did not like the sensor template that added both sensors together.

So basically, I created utility meters for each smart outlet sensor:

utility_meter:
  pc_energy_daily:
    source: sensor.tuya_smart_plug_01_energy
    cycle: daily
  pc_energy_monthly:
    source: sensor.tuya_smart_plug_01_energy
    cycle: monthly
  livingroom_energy_daily:
    source: sensor.tuya_smart_plug_02_energy
    cycle: daily
  livingroom_energy_monthly:
    source: sensor.tuya_smart_plug_02_energy
    cycle: monthly

And then combined those via a sensor template into the total value:

# Sensor platform
sensor:
  - platform: template
    sensors:
      # Tuya plugs total energy
      total_kwh_daily:
        value_template: "{{ ( states('sensor.pc_energy_daily') | float + states('sensor.livingroom_energy_daily') | float ) | round(2) }}"
      total_kwh_monthly:
        value_template: "{{ ( states('sensor.pc_energy_monthly') | float + states('sensor.livingroom_energy_monthly') | float ) | round(2) }}"
1 Like