more esphome devices and fixes
This commit is contained in:
+156
-130
@@ -1,204 +1,222 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# OFFICE DUAL LIGHT CONTROL
|
||||
# - Overhead cool white lights
|
||||
# - Right hand warm bunker light
|
||||
#:########################################################################################:#
|
||||
# TITLE: OFFICE DUAL LIGHT CONTROL
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-officeduallights.yaml
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# 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
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# - Sonoff Dual R1
|
||||
# - ESP8266 based
|
||||
# - 2 x relay outputs
|
||||
# - 2 x local push buttons
|
||||
# - Relay control via UART serial commands
|
||||
# - Status LED on GPIO13
|
||||
#:########################################################################################:#
|
||||
# OPERATION NOTES:
|
||||
# - 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
|
||||
# - Template binary lights drive the template relay switches
|
||||
# - Sonoff Dual R1 requires UART serial packets to operate the physical relays
|
||||
#
|
||||
# Controlled by a Sonoff Dual R1
|
||||
# A sonoff dual uses serial data to turn the relays on/off
|
||||
# MQTT COMMANDS:
|
||||
# - Command relay 1:
|
||||
# - ${mqtt_local_command_topic}/relay1/set ON or OFF
|
||||
# - Command relay 2:
|
||||
# - ${mqtt_local_command_topic}/relay2/set ON or OFF
|
||||
# - Relay 1 status publishes to:
|
||||
# - ${mqtt_local_status_topic}/relay1/state
|
||||
# - Relay 2 status publishes to:
|
||||
# - ${mqtt_local_status_topic}/relay2/state
|
||||
#:########################################################################################:#
|
||||
# OFFLINE NOTES:
|
||||
# a) Home Assistant offline (network and MQTT still online):
|
||||
# - Device continues to operate from local buttons
|
||||
# - Device can still be controlled directly by MQTT
|
||||
# - Relay status still publishes by MQTT if broker is available
|
||||
#
|
||||
# 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
|
||||
# b) MQTT offline (or HA and MQTT both offline):
|
||||
# - Device continues to operate from local buttons only
|
||||
# - No direct inter-ESP MQTT control available
|
||||
# - No MQTT state feedback available
|
||||
#
|
||||
# NOTES:
|
||||
# Command the lights on with MQTT
|
||||
# ${mqtt_local_command_full_topic}/relay1/set ON or OFF
|
||||
# ${mqtt_local_command_full_topic}/relay2/set ON or OFF
|
||||
# ${mqtt_local_status_full_topic}/relay1/set ON or OFF
|
||||
# ${mqtt_local_status_full_topic}/relay2/set ON or OFF
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# c) Entire WiFi / Network offline:
|
||||
# - Device continues to operate from local buttons only
|
||||
# - No HA control or MQTT control/status available
|
||||
# - Accurate time is not needed; SNTP is not required for operation
|
||||
#:########################################################################################:#
|
||||
|
||||
##########################################################################################
|
||||
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
||||
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SUBSTITUTIONS:
|
||||
# Specific device variable substitutions
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-officeduallights"
|
||||
friendly_name: "Office Dual Lights"
|
||||
description_comment: "Dual Office Lights (Overhead and right hand Bunker) :: Sonoff Dual R1"
|
||||
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
description_comment: "Dual Office Lights (Overhead and right hand Bunker) :: Sonoff Dual R1 (Layout V1.1)"
|
||||
device_area: "Office"
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff Dual R1" # Project Details
|
||||
project_version: "v2.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords & Secrets
|
||||
project_name: "Sonoff Technologies.Sonoff Dual R1"
|
||||
project_version: "v2.5"
|
||||
|
||||
# Passwords and Secrets
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-officeduallights_ip # unfortunately you can't use substitutions inside secrets names
|
||||
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
|
||||
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:lightbulb-group"
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
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}" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}"
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}"
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Dual L1 Relay"
|
||||
relay_1_icon: "mdi:lightbulb"
|
||||
light_1_name: "Light 1 (Right Hand Bunker Light)"
|
||||
switch_2_name: "Dual L2 Relay"
|
||||
relay_2_icon: "mdi:lightbulb"
|
||||
light_2_name: "Light 2 (Cool White Overhead Lights)"
|
||||
switch_1_name: "Dual L1 Relay"
|
||||
relay_1_icon: "mdi:lightbulb"
|
||||
light_1_name: "Light 1 (Right Hand Bunker Light)"
|
||||
|
||||
##########################################################################################
|
||||
# PACKAGES: Included Common Packages
|
||||
switch_2_name: "Dual L2 Relay"
|
||||
relay_2_icon: "mdi:lightbulb"
|
||||
light_2_name: "Light 2 (Cool White Overhead Lights)"
|
||||
|
||||
#:########################################################################################:#
|
||||
# PACKAGES:
|
||||
# Included common packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
file: common/network_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
local_static_ip_address: "${static_ip_address}"
|
||||
local_current_ip_address: "${current_ip_address}"
|
||||
local_ota_pass: "${ota_pass}"
|
||||
|
||||
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
|
||||
common_api: !include
|
||||
file: common/api_common.yaml
|
||||
#file: common/api_common_noencryption.yaml
|
||||
# file: common/api_common_noencryption.yaml
|
||||
vars:
|
||||
local_api_key: "${api_key}"
|
||||
|
||||
#### MQTT ####
|
||||
common_mqtt: !include
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
#common_sntp: !include common/sntp_common.yaml
|
||||
|
||||
#### DIAGNOSTICS Sensors ####
|
||||
diag_basic: !include common/include_basic_diag_sensors.yaml
|
||||
diag_more: !include common/include_more_diag_sensors.yaml
|
||||
#diag_debug: !include common/include_debug_diag_sensors.yaml
|
||||
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
# common_webportal: !include common/webportal_common.yaml
|
||||
# common_sntp: !include common/sntp_common.yaml
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
diag_basic: !include common/include_basic_diag_sensors.yaml
|
||||
diag_more: !include common/include_more_diag_sensors.yaml
|
||||
# diag_debug: !include common/include_debug_diag_sensors.yaml
|
||||
# diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
|
||||
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
comment: "${description_comment}"
|
||||
area: "${device_area}"
|
||||
# platformio_options:
|
||||
# build_flags:
|
||||
# - "-Os" # optimize for size
|
||||
# - "-Wl,--gc-sections" # drop unused code/data
|
||||
# - "-fno-exceptions" # strip C++ exceptaions
|
||||
# - "-fno-rtti" # strip C++ RTTI
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266.html
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m # The original sonoff basic
|
||||
restore_from_flash: False # restore some values on reboot
|
||||
board: esp01_1m
|
||||
restore_from_flash: false
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min
|
||||
|
||||
mdns:
|
||||
disabled: True
|
||||
disabled: true
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGER:
|
||||
# Sonoff Dual cannot use UART logging because UART is required for relay control
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
# NOTE: Sonoff Dual CANNOT send serial data to log
|
||||
###############################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
level: "${log_level}"
|
||||
baud_rate: 0
|
||||
|
||||
##########################################################################################
|
||||
# UART Bus
|
||||
#:########################################################################################:#
|
||||
# UART BUS:
|
||||
# https://esphome.io/components/uart.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
uart:
|
||||
tx_pin: GPIO01
|
||||
rx_pin: GPIO03
|
||||
baud_rate: 19200
|
||||
#data_bits: 8
|
||||
#stop_bits: 1
|
||||
#parity: EVEN
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# Device-specific MQTT command triggers
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
# Direct MQTT control for relays via serial commands
|
||||
on_message:
|
||||
# Relay 1 control
|
||||
- topic: "${mqtt_local_command_topic}/relay1/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay_1
|
||||
- light.turn_on: light_1
|
||||
|
||||
- topic: "${mqtt_local_command_topic}/relay1/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay_1
|
||||
- light.turn_off: light_1
|
||||
- light.turn_off: light_1
|
||||
|
||||
# Relay 2 control
|
||||
- topic: "${mqtt_local_command_topic}/relay2/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay_2
|
||||
- light.turn_on: light_2
|
||||
|
||||
- topic: "${mqtt_local_command_topic}/relay2/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay_2
|
||||
- light.turn_off: light_2
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# Sonoff Dual LED is on GPIO13
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Sonoff Dual LED is GPIO13
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# Sonoff Dual R1 buttons are GPIO04 and GPIO14
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Sonoff Dual R1 buttons are GPIO04, GPIO14
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
@@ -218,12 +236,11 @@ binary_sensor:
|
||||
on_press:
|
||||
- switch.toggle: relay_2
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH:
|
||||
# Sonoff Dual R1 requires serial data packets to switch the relays
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff Dual R1 requires serial data to switch
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: template
|
||||
name: "${switch_1_name}"
|
||||
@@ -234,7 +251,7 @@ switch:
|
||||
turn_on_action:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/relay1/state"
|
||||
payload: "ON"
|
||||
payload: "ON"
|
||||
- if:
|
||||
condition:
|
||||
switch.is_off: relay_2
|
||||
@@ -245,7 +262,7 @@ switch:
|
||||
turn_off_action:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/relay1/state"
|
||||
payload: "OFF"
|
||||
payload: "OFF"
|
||||
- if:
|
||||
condition:
|
||||
switch.is_off: relay_2
|
||||
@@ -253,6 +270,7 @@ switch:
|
||||
- uart.write: [0xA0, 0x04, 0x00, 0xA1]
|
||||
else:
|
||||
- uart.write: [0xA0, 0x04, 0x02, 0xA1]
|
||||
|
||||
- platform: template
|
||||
name: "${switch_2_name}"
|
||||
id: relay_2
|
||||
@@ -262,7 +280,7 @@ switch:
|
||||
turn_on_action:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/relay2/state"
|
||||
payload: "ON"
|
||||
payload: "ON"
|
||||
- if:
|
||||
condition:
|
||||
switch.is_off: relay_1
|
||||
@@ -273,7 +291,7 @@ switch:
|
||||
turn_off_action:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/relay2/state"
|
||||
payload: "OFF"
|
||||
payload: "OFF"
|
||||
- if:
|
||||
condition:
|
||||
switch.is_off: relay_1
|
||||
@@ -282,30 +300,38 @@ switch:
|
||||
else:
|
||||
- uart.write: [0xA0, 0x04, 0x01, 0xA1]
|
||||
|
||||
################################################################################
|
||||
# TEMPLATE OUTPUTS: drive the real relays when the light state changes
|
||||
################################################################################
|
||||
#:########################################################################################:#
|
||||
# OUTPUTS:
|
||||
# Template outputs drive the relay template switches when the light state changes
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: template
|
||||
id: light_output_1
|
||||
type: binary
|
||||
write_action:
|
||||
- lambda: |-
|
||||
if (state) id(relay_1).turn_on();
|
||||
else id(relay_1).turn_off();
|
||||
if (state) {
|
||||
id(relay_1).turn_on();
|
||||
} else {
|
||||
id(relay_1).turn_off();
|
||||
}
|
||||
|
||||
- platform: template
|
||||
id: light_output_2
|
||||
type: binary
|
||||
write_action:
|
||||
- lambda: |-
|
||||
if (state) id(relay_2).turn_on();
|
||||
else id(relay_2).turn_off();
|
||||
if (state) {
|
||||
id(relay_2).turn_on();
|
||||
} else {
|
||||
id(relay_2).turn_off();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LIGHT:
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: binary
|
||||
name: "${light_1_name}"
|
||||
@@ -313,6 +339,6 @@ light:
|
||||
output: light_output_1
|
||||
|
||||
- platform: binary
|
||||
name: "Light 2 (Cool White Overhead Lights)"
|
||||
name: "${light_2_name}"
|
||||
id: light_2
|
||||
output: light_output_2
|
||||
output: light_output_2
|
||||
Reference in New Issue
Block a user