Syntax sensor template - Configuration Error

Hi, I’m just struggling with a sensor template… :woozy_face:

I’ve read the documentation , several posts ( 190105, 83469 and 236421) but I don’t get the clue why I geht “Configuration invalid” error.

This is my code:

  - platform: template
    sensors:
      rain_sensor:
        friendly_name: "Regensensor"
        value_template: >-
          {% if states('sensor.esp_regensensor_analog')|float > 3.0 }
            trocken
          {% else %}
            nass
          {% endif %}

integrated in by this in confiugartion.yaml

sensor: !include_dir_merge_list sensors/

and this is the error:

Invalid config for [sensor.template]: invalid template (TemplateSyntaxError: unexpected ‘}’) for dictionary value @ data[‘sensors’][‘rain_sensor’][‘value_template’]. Got “{% if states(‘sensor.esp_regensensor_analog’)|float > 3.0 }\n trocken\n{% else %}\n nass\n{% endif %}”. (See ?, line ?).

Any idea or hint?

PS. I know only for two values I could use a binary sensor, but I want to add more states when it works with this two.

Should be

...float > 3.0 %}

1 Like

Great, thanks…
sometimes I think I’m blind :crazy_face:

Since the sensors’s state has only two options, consider turning it into a binary_sensor like binary_sensor.raining and a value template of

{{ states('sensor.esp_regensensor.analog') | float > 3.0 }}

Es sei denn, es soll noch die Option “Sinflut” dazukommen :slight_smile:

:wink:

yes, there will be more states:

  - platform: template
    sensors:
      rain_sensor:
        friendly_name: "Niederschlag"
        value_template: >-
          {% if states('sensor.esp_regensensor_analog')|float < 1.5 %}
            sehr stark
          {% elif states('sensor.esp_regensensor_analog')|float < 2.0 %}
            stark
          {% elif states('sensor.esp_regensensor_analog')|float < 2.5 %}
            mässig
          {% elif states('sensor.esp_regensensor_analog')|float < 3.0 %}
            leicht
          {% else %}
            trocken
          {% endif %}
        icon_template: >-
          {% if states('sensor.esp_regensensor_analog')|float < 1.5 %}
            mdi:water-alert
          {% elif states('sensor.esp_regensensor_analog')|float < 2.0 %}
            mdi:water-plus
          {% elif states('sensor.esp_regensensor_analog')|float < 2.5 %}
            mdi:water
          {% elif states('sensor.esp_regensensor_analog')|float < 3.0 %}
            mdi:water-minus
          {% else %}
            mdi:water-off
          {% endif %}

aber keine Sintflut dabei :rofl: