Edit esp-officelights.yaml

This commit is contained in:
ESPHome Device Builder
2026-07-25 13:08:53 +12:00
parent 474a911ba9
commit e74ac70ef0
+45 -2
View File
@@ -34,17 +34,19 @@
# MQTT COMMANDS:
# Bunker Lights (Button 1):
# - Command topic: ${mqtt_this_device_command_topic_bunker}
# Payloads: ${mqtt_command_on}, ${mqtt_command_off}
# Payloads: ${mqtt_command_on}, ${mqtt_command_off}, or 1 to 3600 (timer seconds)
# - Status topic: ${mqtt_this_device_status_topic_bunker}
# Payloads mirror the actual bunker relay state and are published retained.
#
# Overhead Lights (Button 2):
# - Command topic: ${mqtt_this_device_command_topic_overhead}
# Payloads: ${mqtt_command_on}, ${mqtt_command_off}
# Payloads: ${mqtt_command_on}, ${mqtt_command_off}, or 1 to 3600 (timer seconds)
# - Status topic: ${mqtt_this_device_status_topic_overhead}
# Payloads mirror the overhead virtual relay state and are published retained.
#
# This device subscribes to status topics from esp-officeduallights to mirror remote state.
# Timer values from esp-occupancyoffice are handled locally (countdown runs on this device).
# Physical button presses cancel any active timer before toggling.
#:########################################################################################:#
# OFFLINE NOTES:
# - a) Home Assistant offline (network and MQTT online):
@@ -118,6 +120,12 @@ substitutions:
mqtt_command_on: "On"
mqtt_command_off: "Off"
# MQTT Overhead Status - shared topic for overhead state sync
# Both this device and esp-officeduallights publish and subscribe to this topic so
# whichever device's timer finishes first keeps the other in sync.
mqtt_shared_overhead_status_function: "office-overhead-status"
mqtt_shared_overhead_status_topic: "${mqtt_status_main_topic}/${mqtt_shared_overhead_status_function}"
# Switch/Relay/Button Naming
switch_1_name: "Bunker Lights" # Physical relay (GPIO13) connected to bunker light load
switch_2_name: "Overhead Lights" # Virtual mirror of esp-officeduallights overhead state
@@ -214,6 +222,11 @@ mqtt:
payload: !lambda |-
return id(Relay_2).state ? "${mqtt_command_on}" : "${mqtt_command_off}";
retain: true
- mqtt.publish:
topic: "${mqtt_shared_overhead_status_topic}"
payload: !lambda |-
return id(Relay_2).state ? "${mqtt_command_on}" : "${mqtt_command_off}";
retain: true
on_message:
# Mirror remote overhead command onto virtual Relay_2, but only if a real state change
@@ -265,6 +278,28 @@ mqtt:
id(overhead_timer_script)->execute(timer_seconds * 1000);
# Mirror shared overhead status from esp-officeduallights onto virtual Relay_2.
# This handles the case where the dual lights' overhead timer finishes and turns off
# the overhead — the main lightswitch mirrors the state so its virtual relay stays
# in sync. State guards prevent ping-pong with the command topic handlers above.
- topic: "${mqtt_shared_overhead_status_topic}"
payload: "${mqtt_command_on}"
then:
- if:
condition:
lambda: "return !id(Relay_2).state;"
then:
- switch.turn_on: Relay_2
- topic: "${mqtt_shared_overhead_status_topic}"
payload: "${mqtt_command_off}"
then:
- if:
condition:
lambda: "return id(Relay_2).state;"
then:
- switch.turn_off: Relay_2
# Mirror remote bunker command onto Relay_1, but only if a real state change is needed.
# This handles commands from esp-officeduallights when its local button toggles the
# physical bunker light and publishes status.
@@ -544,11 +579,19 @@ switch:
topic: "${mqtt_this_device_status_topic_overhead}"
payload: "${mqtt_command_on}"
retain: true
- mqtt.publish:
topic: "${mqtt_shared_overhead_status_topic}"
payload: "${mqtt_command_on}"
retain: true
on_turn_off:
- mqtt.publish:
topic: "${mqtt_this_device_status_topic_overhead}"
payload: "${mqtt_command_off}"
retain: true
- mqtt.publish:
topic: "${mqtt_shared_overhead_status_topic}"
payload: "${mqtt_command_off}"
retain: true
# Relay 3 (Spare) - no function assigned
- platform: gpio