When you specify for
in a State Condition (or Device Condition) you are indicating the state value must be unchanged for the specified time. That means at the moment the condition is evaluated, the state of the relay must be on
for at least 10 seconds. It’s not going to wait 10 seconds for the relay’s state to be on
, it must be on
for at least the past 10 seconds.
What I see is that the payload published to stat/GarageDoor/status
is a simple string value and is either open
or closed
. In addition, the payload is published as a retained message (meaning the value is stored by the MQTT broker).
The payload published to stat/GarageDoor/SWITCH2
is a JSON string value and is either {"STATE":"ON"}
or {"STATE":"OFF"}
(and is not published as a retained message). If you choose to use this topic, you can interpret its payload (in a Template Condition) using trigger.payload_json
(see documentation).
FWIW, what I would do is create an MQTT Binary Sensor that represents the garage door.
- platform: mqtt
name: 'Garage Door'
state_topic: stat/GarageDoor/status
payload_on: 'open'
payload_off: 'closed'
device_class: garage_door
Then the automation’s trigger can use a simple State Trigger. For example, this triggers when the door is closed:
- alias: Example
trigger:
- platform: state
entity_id: binary_sensor.garage_door
to: 'off'
... etc ...