Templating a sensor from a switch - no luck so far

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

grafik

Up to this point everything works as designed :slight_smile:

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

What does this return in the Developer Tools Template Editor, Open your Home Assistant instance and show your template developer tools.

{{ state_attr('switch.fritz.dect_210_1', 'current_power_w') }}

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…

Can you take a screenshot of the switch entity and the attribute column in Developer Tools States?

Open your Home Assistant instance and show your state developer tools.

This one?

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

And I copied it. :roll_eyes:

Well spotted.

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