Edit esp-downstloungemain.yaml
This commit is contained in:
@@ -164,14 +164,31 @@ logger:
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
# Republish current relay states whenever MQTT reconnects so retained status stays accurate
|
||||
# for subscribers that reconnect later.
|
||||
on_connect:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: !lambda |-
|
||||
return id(relay_1).state ? "On" : "Off";
|
||||
retain: true
|
||||
|
||||
on_message:
|
||||
# Main Lights control (Relay 1)
|
||||
# Main Lights control (Relay 1) — state guard prevents ping-pong
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "On"
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: "return !id(relay_1).state;"
|
||||
then:
|
||||
- switch.turn_on: relay_1
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "Off"
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: "return id(relay_1).state;"
|
||||
then:
|
||||
- switch.turn_off: relay_1
|
||||
|
||||
|
||||
Reference in New Issue
Block a user