BO1
December 19, 2022, 5:41pm
1
Hi,
I am trying to add a template based energy sensor to energy dashboard, but it does not show in the pick list
What am I doing wrong in my sensor definition?
- name: lights_total_consumption
state: >
{% set ns = namespace(states=[]) %}
{% for s in states.sensor |
selectattr('attributes.device_class', 'defined') |
selectattr('attributes.device_class', '==', 'energy') |
selectattr('attributes.source_domain', 'defined') |
selectattr('attributes.source_domain', '==', 'light')%}
{% set ns.states = ns.states + [ s.state | float ] %}
{% endfor %}
{{ns.states | sum | round(2)}}
device_class: energy
state_class: measurement
unit_of_measurement: KWh
Thanks.
BO1
December 20, 2022, 1:13am
3
@ tom_I
Actually I already thought that capitalization can matter, but despite changing KWh to kWh, still not able to find it in the drop down list.
I also played with the state_class, adding state_class: total as attribute
Restarted HA, still unable to find it in that dropdown list
thanks
tom_l
December 20, 2022, 1:15am
4
Oh I messed that. Yeah, state_class has to be total or total_increasing as well as the unit change.
You will probably also need an availability template to prevent odd results if a device goes offline.
BO1
December 20, 2022, 1:18am
5
Well,
still with both these changes inmplemented (state_class: total and unit_of _measure: kWh) still no luck
I see in the that dropdown a lot of other energy sensors, but this one… driving me crazy
tom_l
December 20, 2022, 1:21am
6
Try the state class total_increasing
also, are you restarting HA after making the changes?
BO1
December 20, 2022, 1:30am
7
Tom,
Thanks but no luck.
Tried also restarting HA, that stubborn entity does not want to come up.
I am on 2022.11.4 FWIW
–B