I know that this light uses 13 W of power when it’s on, and 0 W when it is off, so I created a template sensor to reflect its power usage:
template:
sensor:
- name: Hallway Light Power
unit_of_measurement: W
device_class: power
state: "{% if is_state('light.hallway_light', 'on') %} {{ 13.0 }} {% else %} {{ 0.0 }} {% endif %}"
I also wanted to track its total energy usage in kWh, so I created an “integration” sensor:
sensor:
- platform: integration
source: sensor.hallway_light_power
name: Hallway Light Energy
unit_prefix: k
method: left
This works well, except for one issue: the value of the integration sensor only updates when the value of the source (power) sensor changes. If I turn on my light for 12 hours, the energy usage of the light is not gradually added to the total kWh value during those 12 hours like I would expect. Instead, it is all added to the total immediately when I turn the light off. I have daily and monthly utility_meter sensors and this issue causes the energy usage to be added to the wrong day or month. Is there a way to make the integration sensor update in real time (or even on an interval, say, every 5 minutes), so that it will always accurately reflect the amount of energy that my light has used?
@tom_l Wow. I spent several days creating power sensors, energy sensors, and utility meters for all of my lights, and now I found out there is a custom component that can do all of that for me.
Thanks for letting me know about this! This is going to make my configuration so much simpler. I can see there is even a scan_interval setting which addresses my original question about updating the state when there is no change.
Are you sure this should be working?
I had the same idea, but since the state doesn’t change (even if triggered in regular intervals) the “integration sensor” never seems to update either.
There might be something wrong with my trigger, as the attribute “last _update” does not change: