changes to esphome devices and packages to start removing node red dependencies

This commit is contained in:
root
2026-04-25 21:05:32 +12:00
parent 51bff34d2e
commit 15f348570f
71 changed files with 1322 additions and 202 deletions
+146 -42
View File
@@ -6,6 +6,8 @@
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-officeduallights.yaml
#:########################################################################################:#
# VERSIONS:
# V2.7 2026-04-24 Updated MQTT local topics, retain false, and timed control using seconds
# V2.6 2026-04-23 Added independent MQTT timed ON control for relay1 and relay2
# V2.5 2026-03-11 Updated yaml to zorruno layout V1.1
# V2.4 2025-06-30 Tidied up MQTT direct relay control (esps can control each other via MQTT)
# V2.3 2025-06-18 Added MQTT direct relay control
@@ -22,21 +24,27 @@
# - Controls 2 office light circuits:
# - Overhead cool white lights
# - Right hand warm bunker light
# - Local button 1 toggles relay/light 1
# - Local button 2 toggles relay/light 2
# - Relay state changes are sent out via MQTT status topics
# - Local button 1 toggles relay/light 1 and cancels any active timer for relay 1
# - Local button 2 toggles relay/light 2 and cancels any active timer for relay 2
# - Relay state changes are sent out via MQTT status topics with retain false
# - MQTT can command each relay with:
# - On = turn on with no timer and cancel any active timer
# - Off = turn off immediately and cancel any active timer
# - 1 to 3600 = turn on for that many seconds, then turn off
# - If a new valid timed value is received while a timer is already active, the timer restarts from zero
# - Invalid MQTT timer values are ignored
# - Template binary lights drive the template relay switches
# - Sonoff Dual R1 requires UART serial packets to operate the physical relays
#
# MQTT COMMANDS:
# - Command relay 1:
# - ${mqtt_local_command_topic}/relay1/set ON or OFF
# - ${mqtt_local_command1_topic} On, Off, or 1 to 3600 seconds
# - Command relay 2:
# - ${mqtt_local_command_topic}/relay2/set ON or OFF
# - ${mqtt_local_command2_topic} On, Off, or 1 to 3600 seconds
# - Relay 1 status publishes to:
# - ${mqtt_local_status_topic}/relay1/state
# - ${mqtt_local_status1_topic} On or Off
# - Relay 2 status publishes to:
# - ${mqtt_local_status_topic}/relay2/state
# - ${mqtt_local_status2_topic} On or Off
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant offline (network and MQTT still online):
@@ -68,25 +76,34 @@ substitutions:
# Project Naming
project_name: "Sonoff Technologies.Sonoff Dual R1"
project_version: "v2.5"
project_version: "v2.7"
# Passwords and Secrets
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-officeduallights_ip
current_ip_address: ${static_ip_address}
mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic
mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic
# Device Settings
relay_icon: "mdi:lightbulb-group"
log_level: "NONE"
update_interval: "60s"
# MQTT Controls
mqtt_device_name: "office-dual-lights"
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}"
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}"
# MQTT LOCAL Controls
mqtt_local_device1_name: "office-dual-lights-right"
mqtt_local_command1_topic: "${mqtt_command_main_topic}/${mqtt_local_device1_name}"
mqtt_local_status1_topic: "${mqtt_status_main_topic}/${mqtt_local_device1_name}"
mqtt_local_device2_name: "office-dual-lights-left"
mqtt_local_command2_topic: "${mqtt_command_main_topic}/${mqtt_local_device2_name}"
mqtt_local_status2_topic: "${mqtt_status_main_topic}/${mqtt_local_device2_name}"
# MQTT REMOTE Controls
# mqtt_remote_device1_name: "masterbath-towelrail"
# mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/operation"
# mqtt_remote_device1_command1: "BOOST"
# Switch Naming
switch_1_name: "Dual L1 Relay"
@@ -173,37 +190,115 @@ uart:
baud_rate: 19200
#:########################################################################################:#
# MQTT:
# MQTT COMPONENT:
# Device-specific MQTT command triggers
# https://esphome.io/components/mqtt.html
#:########################################################################################:#
mqtt:
on_message:
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "ON"
- topic: "${mqtt_local_command1_topic}"
payload: "On"
then:
- switch.turn_on: relay_1
- script.stop: relay_1_timer_script
- light.turn_on: light_1
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "OFF"
- topic: "${mqtt_local_command1_topic}"
payload: "Off"
then:
- switch.turn_off: relay_1
- script.stop: relay_1_timer_script
- light.turn_off: light_1
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "ON"
- topic: "${mqtt_local_command1_topic}"
then:
- switch.turn_on: relay_2
- 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(relay_1_timer_script)->execute(timer_seconds * 1000);
- topic: "${mqtt_local_command2_topic}"
payload: "On"
then:
- script.stop: relay_2_timer_script
- light.turn_on: light_2
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "OFF"
- topic: "${mqtt_local_command2_topic}"
payload: "Off"
then:
- switch.turn_off: relay_2
- script.stop: relay_2_timer_script
- light.turn_off: light_2
- topic: "${mqtt_local_command2_topic}"
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(relay_2_timer_script)->execute(timer_seconds * 1000);
#:########################################################################################:#
# STATUS LED:
# SCRIPT COMPONENT:
# Independent per-relay timer scripts
# mode: restart means a new valid timer value restarts the timer from zero
# https://esphome.io/components/script.html
#:########################################################################################:#
script:
- id: relay_1_timer_script
mode: restart
parameters:
timer_duration_ms: int
then:
- light.turn_on: light_1
- delay: !lambda "return timer_duration_ms;"
- light.turn_off: light_1
- id: relay_2_timer_script
mode: restart
parameters:
timer_duration_ms: int
then:
- light.turn_on: light_2
- delay: !lambda "return timer_duration_ms;"
- light.turn_off: light_2
#:########################################################################################:#
# STATUS LED COMPONENT:
# Sonoff Dual LED is on GPIO13
# https://esphome.io/components/status_led.html
#:########################################################################################:#
@@ -213,8 +308,9 @@ status_led:
inverted: true
#:########################################################################################:#
# BINARY SENSORS:
# BINARY SENSOR COMPONENT:
# Sonoff Dual R1 buttons are GPIO04 and GPIO14
# Local button presses cancel any active timer for that relay before toggling
# https://esphome.io/components/binary_sensor/
#:########################################################################################:#
binary_sensor:
@@ -225,7 +321,8 @@ binary_sensor:
inverted: true
id: button_1
on_press:
- switch.toggle: relay_1
- script.stop: relay_1_timer_script
- light.toggle: light_1
- platform: gpio
pin:
@@ -234,11 +331,13 @@ binary_sensor:
inverted: true
id: button_2
on_press:
- switch.toggle: relay_2
- script.stop: relay_2_timer_script
- light.toggle: light_2
#:########################################################################################:#
# SWITCH:
# SWITCH COMPONENT:
# Sonoff Dual R1 requires serial data packets to switch the relays
# Relay state changes publish MQTT status updates with retain false
# https://esphome.io/components/switch/
#:########################################################################################:#
switch:
@@ -250,8 +349,9 @@ switch:
internal: true
turn_on_action:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/relay1/state"
payload: "ON"
topic: "${mqtt_local_status1_topic}"
payload: "On"
retain: false
- if:
condition:
switch.is_off: relay_2
@@ -261,8 +361,9 @@ switch:
- uart.write: [0xA0, 0x04, 0x03, 0xA1]
turn_off_action:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/relay1/state"
payload: "OFF"
topic: "${mqtt_local_status1_topic}"
payload: "Off"
retain: false
- if:
condition:
switch.is_off: relay_2
@@ -279,8 +380,9 @@ switch:
internal: true
turn_on_action:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/relay2/state"
payload: "ON"
topic: "${mqtt_local_status2_topic}"
payload: "On"
retain: false
- if:
condition:
switch.is_off: relay_1
@@ -290,8 +392,9 @@ switch:
- uart.write: [0xA0, 0x04, 0x03, 0xA1]
turn_off_action:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/relay2/state"
payload: "OFF"
topic: "${mqtt_local_status2_topic}"
payload: "Off"
retain: false
- if:
condition:
switch.is_off: relay_1
@@ -301,7 +404,7 @@ switch:
- uart.write: [0xA0, 0x04, 0x01, 0xA1]
#:########################################################################################:#
# OUTPUTS:
# OUTPUT COMPONENT:
# Template outputs drive the relay template switches when the light state changes
# https://esphome.io/components/output/
#:########################################################################################:#
@@ -329,7 +432,8 @@ output:
}
#:########################################################################################:#
# LIGHT:
# LIGHT COMPONENT:
# Main control entities for both local and MQTT control paths
# https://esphome.io/components/light/
#:########################################################################################:#
light: