Hi
i made a service template but i think there is a bigger problem. it is not working. config check and template check says OK.
could somebody give me a direction where to search for the probleme?
- service_template: >
{% if (states('sensor.openweathermap_forecast_wind_speed') | float > 3 and
states('sensor.openweathermap_forecast_temperature') | float > 26) %}
homeassistant.turn_on
entity_id: group.teichpumpen_wind_hitze
{% elif (states('sensor.openweathermap_forecast_wind_speed') | float > 3 and
states('sensor.openweathermap_forecast_temperature') | float < 26) %}
homeassistant.turn_on
entity_id: group.teichpumpen_wind
{% elif (states('sensor.openweathermap_forecast_wind_speed') | float < 3 and
states('sensor.openweathermap_forecast_temperature') | float > 26) %}
homeassistant.turn_on
entity_id: group.teichpumpen_hitze
{% else %}
homeassistant.turn_on
entity_id: group.teichpumpen
{% endif %}
tom_l
August 14, 2022, 1:45pm
2
- service: homeassistant.turn_on
target:
entity_id: >
{% if (states('sensor.openweathermap_forecast_wind_speed') | float > 3 and
states('sensor.openweathermap_forecast_temperature') | float > 26) %}
group.teichpumpen_wind_hitze
{% elif (states('sensor.openweathermap_forecast_wind_speed') | float > 3 and
states('sensor.openweathermap_forecast_temperature') | float < 26) %}
group.teichpumpen_wind
{% elif (states('sensor.openweathermap_forecast_wind_speed') | float < 3 and
states('sensor.openweathermap_forecast_temperature') | float > 26) %}
group.teichpumpen_hitze
{% else %}
group.teichpumpen
{% endif %}
This is a key value pair:
key: value
You can only template the value, not the key and definitely not both.
1 Like
How can I handle the problem?
tom_l
August 14, 2022, 1:51pm
4
Exactly the way I just showed you in the template I wrote above. Or you could make it more readable like this:
- service: homeassistant.turn_on
target:
entity_id: >
{% set wind_speed = states('sensor.openweathermap_forecast_wind_speed') | float(0) %}
{% set temperature = states('sensor.openweathermap_forecast_temperature') | float(0) %}
{% if wind_speed > 3 and temperature > 26 %}
group.teichpumpen_wind_hitze
{% elif wind_speed | float > 3 and temperature < 26 %}
group.teichpumpen_wind
{% elif wind_speed | float < 3 and temperature > 26 %}
group.teichpumpen_hitze
{% else %}
group.teichpumpen
{% endif %}
1 Like
thank you.
it runs like a charme
1 Like
123
(Taras)
August 14, 2022, 4:15pm
6
If you’re interested, the template can be reduced to this:
- service: homeassistant.turn_on
target:
entity_id: >
{% set x = iif(states('sensor.openweathermap_forecast_temperature') | float(0) > 26, '_hitze', '') %}
{% if states('sensor.openweathermap_forecast_wind_speed') | float(0) > 3 %}
group.teichpumpen_wind{{ x }}
{% else %}
group.teichpumpen{{ x }}
{% endif %}
1 Like
Juanpermon
(Juanpermon)
September 14, 2024, 11:09am
7
I have a similar issue. I want to show the number of lights that are on but it shows nothing. If I remove the elif and the else, it works (just the if and the endif)
I can’t see what’s wrong
{% set estado = states(‘sensor.luces_encendidas_conteo’)|int %}
{% if estado > 1 %}
{{estado}} encendidas
{% elif estado = 1 %}
{{estado}} encendida
{% else %}
Todas apagadas
{% endif %}
Thank you.
123
(Taras)
September 14, 2024, 11:52am
8
Two =
symbols are used to perform an equivalence test.
{% elif estado == 1 %}
1 Like