M-Punkt
(Michael Rösgen)
August 4, 2021, 9:19am
1
Hi all,
could do with some help in creating a sensor from a switch attribute.
setup:
Fritz!DECT 210 socket connected to a Fritzbox 7490
Fritzbox 7490 integration in HA configured + running
lovelace entity card shows the correct value for attribute Current Power W
Up to this point everything works as designed
Now I would like to access the “Current Power W” attribute via a sensor object.
To achieve this, I built a template sensor:
template:
sensor:
- name: fritz_dect_210_1_watt
unique_id: fritz_dect_210_1_watt
state: "{{ state_attr('switch.fritz.dect_210_1', 'current_power_w') | float }}"
icon: mdi:chart-bell-curve
unit_of_measurement: "W"
This sensor will stubbornly report 0W, regardless of the real value of the attribute.
Where did I go wrong?
Any help is very appreciated.
Thank you
Michael
tom_l
August 4, 2021, 9:24am
2
What does this return in the Developer Tools Template Editor,
{{ state_attr('switch.fritz.dect_210_1', 'current_power_w') }}
M-Punkt
(Michael Rösgen)
August 4, 2021, 12:02pm
3
Thanks for the pointer - I haven’t used this yet.
Template Editor returns an error message:
“Dieses Template überwacht keine Ereignisse und wird nicht automatisch aktualisiert”
basically translates to
“This template does not monitor any events + will not be updated automatically”
Unfortunately, I’m none the wiser yet…
tom_l
August 4, 2021, 12:21pm
4
Can you take a screenshot of the switch entity and the attribute column in Developer Tools States?
tom_l
August 4, 2021, 12:47pm
6
Yep. That one.
The template editor should return 0
according to that, when you enter this:
{{ state_attr('switch.fritz.dect_210_1', 'current_power_w') }}
Hello, can you try this?
template:
- sensor:
- name: "fritz_dect_210_1_watt"
unique_id: fritz_dect_210_1_watt
state: "{{ state_attr('switch.fritz_dect_210_1', 'current_power_w') | float }}"
icon: mdi:chart-bell-curve
unit_of_measurement: "W"
I think you misspelled switch.fritz_dect_210_1
by writing switch.fritz.dect_210_1
.
3 Likes
M-Punkt
(Michael Rösgen)
August 4, 2021, 1:57pm
9
OMG!
Thanks @ardysusilo for spotting this f…<<<ine typo.
Honestly, I rerererechecked that and didn’t see it.
Now it works like a charm.
Again, thank you (and @tom_l as well) for saving my soul.
Michael