Error with an Template Sensor

Hi

im trying to get an Atribute Sensor from my Dyson.

  - platform: template
    sensors:
      dysonair10_manu:
        friendly_name: "Pollen"
        unit_of_measurement: "µg/m³"
        value_template: "{{ state_attr('air_quality.schlafzimmer_air_quality', 'particulate_matter_10' }}"

but get this error message:

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected '}', expected ')') for dictionary value @ data['sensors']['dysonair10_manu']['value_template']. Got "{{ state_attr('air_quality.schlafzimmer_air_quality', 'particulate_matter_10' }}". (See ?, line ?).

You are missing ‘)’ after ‘particulate_matter_10’.

  - platform: template
    sensors:
      dysonair10_manu:
        friendly_name: "Pollen"
        unit_of_measurement: "µg/m³"
        value_template: >-
          {{ state_attr('air_quality.schlafzimmer_air_quality', 'particulate_matter_10') }
1 Like

omg - ty <3

Good tip before putting it in your configuration.yaml file is to test it on Developer Tools → Template.

See if the result is as what you have expected and no error shows up.

1 Like

You do not quote multi-line templates. Use this:

        value_template: >
          {{ state_attr('air_quality.schlafzimmer_air_quality', 'particulate_matter_10') }}

Or this:

        value_template: "{{ state_attr('air_quality.schlafzimmer_air_quality', 'particulate_matter_10') }}"
1 Like

Fixed. Thank you

Thanks for the heads up. Forget to erase the " after making it a multi-line.