I have done quite a lot in Home Assistant, but now I am facing a wall …
In my configuration I am converting switches with attribute with a template sensor to extract the power consumption and using sensor.integration to convert from W to kWh.
But my problem is that for some sensors this works without problem, but for others it ends up in kWatth instead of kWh (which the energy dashboard doesn’t like…)
One example where it works:
Original sensor data:
Then I use the following to extract the power:
template:
- sensor:
- name: elforbrukning_ateljen_luftvarmepump
unit_of_measurement: W
device_class: power
state_class: measurement
state: "{{ float(state_attr('switch.ateljen_luftvarmepump_21', 'current_power_w')|float(0)) }}"
So I get this sensor:
Then using integration to convert from W to kWh:
sensor:
- platform: integration
source: sensor.elforbrukning_ateljen_luftvarmepump
name: elforbrukning_ateljen_luftvarmepump_int
unit_prefix: k
unit_time: h
round: 2
and I get this resulting sensor
Which is exactly what I expect.
Then I have one example where it doesn’t work:
Original sensor data:
Then I use the following to extract the power:
template:
...
- sensor:
- name: elforbrukning_teknik_ateljen
unit_of_measurement: W
device_class: power
state_class: measurement
state: "{{float(state_attr('switch.ateljen_teknik_ateljen_23', 'current_power_w')|float(0))}}"
So I get this sensor:
Then using integration to convert from W to kWh:
sensor:
...
- platform: integration
source: sensor.elforbrukning_teknik_ateljen
name: elforbrukning_teknik_ateljen_int
unit_prefix: k
unit_time: h
round: 2
and I get this resulting sensor
And now I got unit_of_measurement
kWatth
instead of kWh
The original switches both comes from the same fibaro Home Center integration and looks exactly the same as seen above, so I don’t think it is related to this.
It feels like it is related to the sensor.integration
I have searched online but can not find anyone else mentioning this problem and I can’t see the difference between the cases where it work and where it doesn’t.
I hope it is a simple mistake…
Running Home Assistant core-2021.12.10