Hi guys, could somebody help me with writing automation for MQTT trigger.
I want to turn ON or OFF switch depending on received payload. I did that for each payload, but would like to use only one automation for one switch and use IF, ELSE, END IF. Tried a lot, but without success…
This is what I have tried for Action when deleted payload from trigger (using yaml) and below is two working automations:
service: switch.turn_on
data:
value: |
{% if is_state ('trigger.payload', 'ON') %}
turn_on:
service: switch.turn_on
target:
entity_id: switch.doser_active
{% else %}
turn_off:
service: switch.turn_off
target:
entity_id: switch.doser_active
{% endif %}
working automations (copied from automations.yaml)
- id: '1622358858743'
alias: Aquaponics Doser Active ON MQTT
description: ''
trigger:
- platform: mqtt
topic: aquaponics/turnOn
payload: 'ON'
condition: []
action:
- service: switch.turn_on
target:
entity_id: switch.doser_active
mode: single
- id: '1622405410615'
alias: Aquaponics Doser Active OFF MQTT
description: ''
trigger:
- platform: mqtt
topic: aquaponics/turnOn
payload: 'OFF'
condition: []
action:
- service: switch.turn_off
target:
entity_id: switch.doser_active
mode: single
and this did not help also
service: |
{% if ('{{ trigger.payload }}'), "ON" %}
switch.turn_on
{% else %}
switch.turn_off
{% endif %}
entity_id: switch.doser_active