From e74ac70ef0338fc3629998cc90ef2ccbe49556e6 Mon Sep 17 00:00:00 2001 From: ESPHome Device Builder Date: Sat, 25 Jul 2026 13:08:53 +1200 Subject: [PATCH] Edit esp-officelights.yaml --- esphome/esp-officelights.yaml | 47 +++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) diff --git a/esphome/esp-officelights.yaml b/esphome/esp-officelights.yaml index aae26f0..320771d 100644 --- a/esphome/esp-officelights.yaml +++ b/esphome/esp-officelights.yaml @@ -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