I have a lamp that, according to the specs, uses 25.6 watts when turned on. I have a Zigbee switch actuator connected to it, so my Home Assistant instance knows when it’s turned on or off, so I should be able to measure its energy consumption without an additional metering device.
I have a template sensor configured as follows:
template:
sensor:
- name: kitchen_island_lamp_power
unique_id: d7a22810-9a60-4a83-880f-7e79c8431e86
unit_of_measurement: 'W'
device_class: power
state: >
{% if is_state('light.kitchen_island', 'on') %} {{ 25.6 | float }} {% else %} {{ 0 | float }} {% endif %}
To test it, I turned on the light for about 1 minute, and the template sensor yields the correct values:
Next, I’m using the Riemann sum integral (I copied the configuration of the “Energy” section of the docs) to compute the lamp’s energy consumption in kWh.
sensor:
- platform: integration
unique_id: b3bb2e79-f9e0-4d6d-8201-302e61ccfa62
source: sensor.kitchen_island_lamp_power
name: kitchen_island_lamp_energy
unit_prefix: k
unit_time: h
round: 2
First, let’s calculate how much we expect the kWh value to rise when the lamp is turned on for 1 minute:
- Duration: 1 minute = 60 seconds ~= 0.01666667 hours
- Power: 25.6 watts = 0.0256 kilowatts
- Energy: 0.0256 kW * 0.01666667 h = 0.00042666 kWh
Now the problem is that the Riemann sum integral computes 0.29 kWh in the same time (which cannot be correct from my point of view):
Does anyone see what I’m doing wrong? Any hint is very much appreciated.
I’m using the following version of Home Assistant:
- Home Assistant 2022.8.7
- Supervisor 2022.08.5
- Operating System 8.5
- Frontend 20220802.0 - latest