I have two sensors that measure power draw for two different loads—in this case, both cat beds. Both sensors offer up a consumption for today. I’m using a group helper to combine the two consumptions by summing them. The result looks correct, as do the charts when I view the values in the History tab of HA. However, when I look at the energy tab in HA I see a very large spike from 12am-1am for the grouped cat bed consumptions. What am I doing wrong? I’ll not that this isn’t an anomaly, as it’s occurred every day since I setup the grouped sensor.
Here’s what I did to fix the issue:
{% set midnight = now().replace(hour=0, minute=0, second=0, microsecond=0) %}
{% set sensor1_value = states('sensor.cat_bed_today_s_consumption') | float %}
{% set sensor2_value = states('sensor.living_room_cat_bed_today_s_consumption') | float %}
{% set sensor3_value = states('sensor.bedroom_cat_bed_today_s_consumption') | float %}
{% set sensor1_last_changed = states['sensor.cat_bed_today_s_consumption'].last_changed %}
{% set sensor2_last_changed = states['sensor.living_room_cat_bed_today_s_consumption'].last_changed %}
{% set sensor3_last_changed = states['sensor.bedroom_cat_bed_today_s_consumption'].last_changed %}
{% set sensor1_is_reset = sensor1_last_changed >= midnight %}
{% set sensor2_is_reset = sensor2_last_changed >= midnight %}
{% set sensor3_is_reset = sensor3_last_changed >= midnight %}
{% set sensor1_value = sensor1_value if sensor1_is_reset else 0 %}
{% set sensor2_value = sensor2_value if sensor2_is_reset else 0 %}
{% set sensor3_value = sensor3_value if sensor3_is_reset else 0 %}
{{ sensor1_value + sensor2_value + sensor3_value }}