Power consumption template

Hi.
I have a d-link switch that monitors consumption.

The template

'{{ state_attr('switch.asciugatrice', 'current_power_w' ) | float }}'

works in the sandbox.

Instead, this, to hava a sensor to display and use in an automation,

- platform: template
    sensors:
      consumo_asciugatrice:
        value_template: '{{ state_attr('switch.asciugatrice', 'current_power_w' ) | float }}'
        friendly_name: "Consumo"
        unit_of_measurement: "W"

results in a configuration error.

I can’t understand where I am wrong.

Thanks in advance.

you can’t use single quote to enclose your value_template AND to define the strings inside the value_template.
Try:

- platform: template
    sensors:
      consumo_asciugatrice:
        value_template: '{{ state_attr("switch.asciugatrice", "current_power_w" ) | float }}'
        friendly_name: "Consumo"
        unit_of_measurement: "W"

or

- platform: template
    sensors:
      consumo_asciugatrice:
        value_template: "{{ state_attr('switch.asciugatrice', 'current_power_w' ) | float }}"
        friendly_name: "Consumo"
        unit_of_measurement: "W"
4 Likes

I think I had tried both, but I’ll give that a new try.
Thank you :slight_smile:

My fault :smiley:
Thank you again.

1 Like