Hi all,
I’m trying to create an automation that push an Mqtt topic based on the state of various sensors.
After several attempt, this is how my code looks right now
- service: mqtt.publish
data_template:
topic: >
{%- set sensors = ["binary_sensor.soil_1", "binary_sensor.soil_2", "binary_sensor.soil_3", "binary_sensor.soil_4", "binary_sensor.soil_5"] -%}
{%- for sensor in sensors if is_state(sensor, 'on') -%}
{% if loop.length < 1-%}
{% if loop.first-%}
wemosgarden/soilsensorled/green
{% endif %}
{% elif loop.length >= 3-%}
{% if loop.first-%}
wemosgarden/soilsensorled/red
{% endif %}
{% else %}
wemosgarden/soilsensorled/yellow
{% endif %}
{%- endfor -%}
If I try this setup in the template editor it works, and the automation load without error.
But when I trigger the automation the topic isn’t published.
What am I doing wrong?
thanks in advance for any hint