From 25e73750dc60fb48a9755bce40bf61296ad2c87c Mon Sep 17 00:00:00 2001 From: ESPHome Device Builder Date: Sun, 13 Sep 2026 11:18:12 +1200 Subject: [PATCH] Edit esp-officelights.yaml --- esphome/esp-officelights.yaml | 101 +++++++++++++++++++++++++--------- 1 file changed, 75 insertions(+), 26 deletions(-) diff --git a/esphome/esp-officelights.yaml b/esphome/esp-officelights.yaml index 78701f1..210f5ab 100644 --- a/esphome/esp-officelights.yaml +++ b/esphome/esp-officelights.yaml @@ -6,6 +6,8 @@ # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-officelights.yaml #:########################################################################################:# # VERSIONS: +# v3.2 2026-09-12 Makes HA the primary Office synchronizer. Direct MQTT peer synchronization +# runs only while HA's native API state subscription is disconnected. # v3.1 2026-08-16 Makes the Sonoff Dual the sole overhead status authority. Removes the # bidirectional shared retained-status topic that could chatter during reconnects. # v3.0 2026-07-25 Refactored MQTT sync to use template HA switch actions; physical button and @@ -81,7 +83,7 @@ substitutions: # Project Naming project_name: "Zemismart Technologies.KS-811 Triple" - project_version: "v3.1" + project_version: "v3.2" # Passwords & Secrets api_key: !secret esp-api_key @@ -215,15 +217,18 @@ mqtt: retain: true on_message: - # Mirror remote overhead command onto virtual Relay_2, but only if a real state change - # is needed. Do not republish the command from here. Relay status is published by the - # relay callback below. + # MQTT peer synchronization is the HA-down fallback. When HA is connected it is the + # sole synchronizer, so remote MQTT state must not change this mirror. - topic: "${mqtt_this_device_command_topic_overhead}" payload: "${mqtt_command_on}" then: - if: condition: - lambda: "return !id(Relay_2).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return !id(Relay_2).state;" then: - switch.turn_on: Relay_2 @@ -232,7 +237,11 @@ mqtt: then: - if: condition: - lambda: "return id(Relay_2).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return id(Relay_2).state;" then: - switch.turn_off: Relay_2 @@ -244,7 +253,11 @@ mqtt: then: - if: condition: - lambda: "return !id(Relay_2).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return !id(Relay_2).state;" then: - switch.turn_on: Relay_2 @@ -253,7 +266,11 @@ mqtt: then: - if: condition: - lambda: "return id(Relay_2).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return id(Relay_2).state;" then: - switch.turn_off: Relay_2 @@ -265,7 +282,11 @@ mqtt: then: - if: condition: - lambda: "return !id(Relay_1).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return !id(Relay_1).state;" then: - switch.turn_on: Relay_1 @@ -274,7 +295,11 @@ mqtt: then: - if: condition: - lambda: "return id(Relay_1).state;" + and: + - not: + api.connected: + state_subscription_only: true + - lambda: "return id(Relay_1).state;" then: - switch.turn_off: Relay_1 @@ -341,10 +366,16 @@ script: lambda: "return !id(Relay_1).state;" then: - switch.turn_on: Relay_1 - - mqtt.publish: - topic: "${mqtt_this_device_command_topic_bunker}" - payload: "${mqtt_command_on}" - retain: false + - if: + condition: + not: + api.connected: + state_subscription_only: true + then: + - mqtt.publish: + topic: "${mqtt_this_device_command_topic_bunker}" + payload: "${mqtt_command_on}" + retain: false # Local/HA requested OFF for Bunker Lights. - id: office_bunker_off @@ -355,10 +386,16 @@ script: lambda: "return id(Relay_1).state;" then: - switch.turn_off: Relay_1 - - mqtt.publish: - topic: "${mqtt_this_device_command_topic_bunker}" - payload: "${mqtt_command_off}" - retain: false + - if: + condition: + not: + api.connected: + state_subscription_only: true + then: + - mqtt.publish: + topic: "${mqtt_this_device_command_topic_bunker}" + payload: "${mqtt_command_off}" + retain: false # Physical Button 1 toggle logic for Bunker Lights. This is the only place that decides # ON vs OFF for the bunker. @@ -383,10 +420,16 @@ script: lambda: "return !id(Relay_2).state;" then: - switch.turn_on: Relay_2 - - mqtt.publish: - topic: "${mqtt_this_device_command_topic_overhead}" - payload: "${mqtt_command_on}" - retain: false + - if: + condition: + not: + api.connected: + state_subscription_only: true + then: + - mqtt.publish: + topic: "${mqtt_this_device_command_topic_overhead}" + payload: "${mqtt_command_on}" + retain: false # Local/HA requested OFF for Overhead Lights. - id: office_overhead_off @@ -397,10 +440,16 @@ script: lambda: "return id(Relay_2).state;" then: - switch.turn_off: Relay_2 - - mqtt.publish: - topic: "${mqtt_this_device_command_topic_overhead}" - payload: "${mqtt_command_off}" - retain: false + - if: + condition: + not: + api.connected: + state_subscription_only: true + then: + - mqtt.publish: + topic: "${mqtt_this_device_command_topic_overhead}" + payload: "${mqtt_command_off}" + retain: false # Physical Button 2 toggle logic for Overhead Lights. - id: office_overhead_toggle