Edit esp-officelights.yaml

This commit is contained in:
ESPHome Device Builder
2026-08-16 17:24:31 +12:00
parent 6f6054ad7b
commit a37e414299
+10 -77
View File
@@ -43,11 +43,11 @@
# Overhead Lights (Button 2): # Overhead Lights (Button 2):
# - Command topic: ${mqtt_this_device_command_topic_overhead} # - Command topic: ${mqtt_this_device_command_topic_overhead}
# Payloads: ${mqtt_command_on}, ${mqtt_command_off}, or 1 to 3600 (timer seconds) # Payloads: ${mqtt_command_on}, ${mqtt_command_off}, or 1 to 3600 (timer seconds)
# - Status topic: ${mqtt_this_device_status_topic_overhead} # - Status topic: ${mqtt_dual_status_overhead_topic}
# Payloads mirror the overhead virtual relay state and are published retained. # Payloads are published by the Sonoff Dual physical relay and mirrored locally.
# #
# This device subscribes to status topics from esp-officeduallights to mirror remote state. # 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). # Timer values from esp-occupancyoffice are handled by the Sonoff Dual physical relay.
# Physical button presses cancel any active timer before toggling. # Physical button presses cancel any active timer before toggling.
#:########################################################################################:# #:########################################################################################:#
# OFFLINE NOTES: # OFFLINE NOTES:
@@ -213,16 +213,6 @@ mqtt:
payload: !lambda |- payload: !lambda |-
return id(Relay_1).state ? "${mqtt_command_on}" : "${mqtt_command_off}"; return id(Relay_1).state ? "${mqtt_command_on}" : "${mqtt_command_off}";
retain: true retain: true
- mqtt.publish:
topic: "${mqtt_this_device_status_topic_overhead}"
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: on_message:
# Mirror remote overhead command onto virtual Relay_2, but only if a real state change # Mirror remote overhead command onto virtual Relay_2, but only if a real state change
@@ -231,7 +221,6 @@ mqtt:
- topic: "${mqtt_this_device_command_topic_overhead}" - topic: "${mqtt_this_device_command_topic_overhead}"
payload: "${mqtt_command_on}" payload: "${mqtt_command_on}"
then: then:
- script.stop: overhead_timer_script
- if: - if:
condition: condition:
lambda: "return !id(Relay_2).state;" lambda: "return !id(Relay_2).state;"
@@ -241,44 +230,16 @@ mqtt:
- topic: "${mqtt_this_device_command_topic_overhead}" - topic: "${mqtt_this_device_command_topic_overhead}"
payload: "${mqtt_command_off}" payload: "${mqtt_command_off}"
then: then:
- script.stop: overhead_timer_script
- if: - if:
condition: condition:
lambda: "return id(Relay_2).state;" lambda: "return id(Relay_2).state;"
then: then:
- switch.turn_off: Relay_2 - switch.turn_off: Relay_2
- topic: "${mqtt_this_device_command_topic_overhead}" # Mirror the Sonoff Dual's physical overhead relay status onto virtual Relay_2.
then: # The main lightswitch never publishes this status, so a reconnect cannot create
- lambda: |- # a feedback loop.
if (x.empty()) { - topic: "${mqtt_dual_status_overhead_topic}"
return;
}
bool numeric_payload = true;
for (char c : x) {
if (c < '0' || c > '9') {
numeric_payload = false;
break;
}
}
if (!numeric_payload) {
return;
}
const int timer_seconds = atoi(x.c_str());
if (timer_seconds < 1 || timer_seconds > 3600) {
return;
}
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}" payload: "${mqtt_command_on}"
then: then:
- if: - if:
@@ -287,7 +248,7 @@ mqtt:
then: then:
- switch.turn_on: Relay_2 - switch.turn_on: Relay_2
- topic: "${mqtt_shared_overhead_status_topic}" - topic: "${mqtt_dual_status_overhead_topic}"
payload: "${mqtt_command_off}" payload: "${mqtt_command_off}"
then: then:
- if: - if:
@@ -464,16 +425,6 @@ script:
- delay: !lambda "return timer_duration_ms;" - delay: !lambda "return timer_duration_ms;"
- switch.turn_off: Relay_1 - switch.turn_off: Relay_1
# Overhead timer script. Turns on immediately, waits for the duration, then turns off.
- id: overhead_timer_script
mode: restart
parameters:
timer_duration_ms: int
then:
- switch.turn_on: Relay_2
- delay: !lambda "return timer_duration_ms;"
- switch.turn_off: Relay_2
#:########################################################################################:# #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
@@ -562,32 +513,14 @@ switch:
payload: "${mqtt_command_off}" payload: "${mqtt_command_off}"
retain: true retain: true
# Virtual Relay 2 (Overhead Lights mirror). No physical load connected. Mirrors the state # Virtual Relay 2 (Overhead Lights mirror). No physical load connected. Mirrors the
# of esp-officeduallights overhead light via MQTT status subscription. # Sonoff Dual's physical overhead relay via its one-way MQTT status topic.
- platform: gpio - platform: gpio
name: "Internal Relay 2: ${switch_2_name}" name: "Internal Relay 2: ${switch_2_name}"
internal: true internal: true
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
restore_mode: ${relay_restore_mode} restore_mode: ${relay_restore_mode}
on_turn_on:
- mqtt.publish:
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 # Relay 3 (Spare) - no function assigned
- platform: gpio - platform: gpio