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):
# - Command topic: ${mqtt_this_device_command_topic_overhead}
# 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.
# - Status topic: ${mqtt_dual_status_overhead_topic}
# 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.
# 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.
#:########################################################################################:#
# OFFLINE NOTES:
@@ -213,16 +213,6 @@ mqtt:
payload: !lambda |-
return id(Relay_1).state ? "${mqtt_command_on}" : "${mqtt_command_off}";
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:
# 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}"
payload: "${mqtt_command_on}"
then:
- script.stop: overhead_timer_script
- if:
condition:
lambda: "return !id(Relay_2).state;"
@@ -241,44 +230,16 @@ mqtt:
- topic: "${mqtt_this_device_command_topic_overhead}"
payload: "${mqtt_command_off}"
then:
- script.stop: overhead_timer_script
- if:
condition:
lambda: "return id(Relay_2).state;"
then:
- switch.turn_off: Relay_2
- topic: "${mqtt_this_device_command_topic_overhead}"
then:
- lambda: |-
if (x.empty()) {
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}"
# Mirror the Sonoff Dual's physical overhead relay status onto virtual Relay_2.
# The main lightswitch never publishes this status, so a reconnect cannot create
# a feedback loop.
- topic: "${mqtt_dual_status_overhead_topic}"
payload: "${mqtt_command_on}"
then:
- if:
@@ -287,7 +248,7 @@ mqtt:
then:
- switch.turn_on: Relay_2
- topic: "${mqtt_shared_overhead_status_topic}"
- topic: "${mqtt_dual_status_overhead_topic}"
payload: "${mqtt_command_off}"
then:
- if:
@@ -464,16 +425,6 @@ script:
- delay: !lambda "return timer_duration_ms;"
- 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
# https://esphome.io/components/binary_sensor/
@@ -562,32 +513,14 @@ switch:
payload: "${mqtt_command_off}"
retain: true
# Virtual Relay 2 (Overhead Lights mirror). No physical load connected. Mirrors the state
# of esp-officeduallights overhead light via MQTT status subscription.
# Virtual Relay 2 (Overhead Lights mirror). No physical load connected. Mirrors the
# Sonoff Dual's physical overhead relay via its one-way MQTT status topic.
- platform: gpio
name: "Internal Relay 2: ${switch_2_name}"
internal: true
pin: GPIO12
id: Relay_2
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
- platform: gpio