I’ve got a very simple automation that turns a light on or off when a switch in Smartthings is on or off.
I know my MQTT setup is working. I can see the switch position in Smartthings matches the switch position in the web UI. This works intermittently, only sometimes turning the light on. I’ve stared at this so long, I’m sure I’m missing something.
My code is:
- id: '13'
alias: Hallway Switch
trigger:
- entity_id: switch.hallway_switch
platform: state
to: 'on'
- entity_id: switch.hallway_switch
platform: state
to: 'off'
- platform: mqtt
payload: 'on'
topic: "smartthings/Hallway Switch/switch"
action:
entity_id: light.hallway
service_template: >
{% if trigger.payload == 'on' %}
light.turn_on
{%- else -%}
light.turn_off
{% endif %}