yaml layout updates to v1.x

This commit is contained in:
root
2026-02-25 21:05:21 +13:00
parent 61b0c64a1e
commit a8d2927274
44 changed files with 6521 additions and 4689 deletions
+118 -84
View File
@@ -1,35 +1,67 @@
############################################# #:########################################################################################:#
############################################# # TITLE: 3D PRINTER POWER AND SWITCH
# 3D PRINTER POWER AND SWITCH # zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-3dprinterpow.yaml
#:########################################################################################:#
# VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 2025-06-29 Initial Version # V1.0 2025-06-29 Initial Version
############################################# #:########################################################################################:#
# Sonoff POW R1 # HARDWARE:
# Sonoff POW R1 (ESP8266)
# https://devices.esphome.io/devices/Sonoff-POW-R1 # https://devices.esphome.io/devices/Sonoff-POW-R1
#:########################################################################################:#
# OPERATION NOTES:
# - Inline power monitor (HLW8012) plus relay control for the 3D printer power feed
# - Local MQTT control (ON/OFF) without needing Home Assistant
# - Publishes current relay state on boot (burst) and on relay changes
# - "Running" binary sensor is derived from measured power > 4 W (with delayed_off)
#:########################################################################################:#
# MQTT COMMANDS:
# - Command topic (local):
# ${mqtt_local_command_topic}
# Payload "ON" -> relay ON + status LED ON
# Payload "OFF" -> relay OFF + status LED OFF
# #
# NOTES # - Status topic (local):
# - # ${mqtt_local_status_topic}
# # Payload "ON"/"OFF" published on relay state changes, plus a short burst on boot
############################################# #:########################################################################################:#
############################################# # OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device remains controllable via MQTT local command topic
# - Status publishes to MQTT still occur (relay state burst + changes)
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable from Home Assistant via API (if enabled)
# - Local MQTT commands will not work and status publishes will fail while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - Local button still toggles the relay (and status LED follows)
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-3dprinterpow" device_name: "esp-3dprinterpow"
friendly_name: "3D Printer Power" friendly_name: "3D Printer Power"
description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1." description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1. (Layout V1.1)"
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sonoff Technologies.POW R1" # Project Details project_name: "Sonoff Technologies.POW R1" # Project Details
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-3dprinterpow_ip # unfortunately you can't use substitutions inside secrets names static_ip_address: !secret esp-3dprinterpow_ip # unfortunately you can't use substitutions inside secrets names
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
@@ -42,16 +74,16 @@ substitutions:
mqtt_local_device_name: "3dprinter-power" mqtt_local_device_name: "3dprinter-power"
mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}" # Topic we will use to command this locally without HA mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}" # Topic we will use to command this locally without HA
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}" # Topic we will use to view status locally without HA mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}" # Topic we will use to view status locally without HA
# Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
entity_prefix: "Load" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
########################################################################################## # Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
entity_prefix: "Load" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -74,23 +106,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -104,80 +136,74 @@ esphome:
then: then:
- script.execute: publish_state_burst - script.execute: publish_state_burst
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
############################################# #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
############################################# #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT: Device-specific MQTT command triggers
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Switch control from MQTT # Switch control from MQTT
- topic: "${mqtt_local_command_topic}" - topic: "${mqtt_local_command_topic}"
payload: "ON" payload: "ON"
then: then:
- switch.turn_on: relay - switch.turn_on: relay
- light.turn_on: led - light.turn_on: led
- topic: "${mqtt_local_command_topic}" - topic: "${mqtt_local_command_topic}"
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay - switch.turn_off: relay
- light.turn_off: led - light.turn_off: led
############################################# #:########################################################################################:#
# STATUS LED # BINARY SENSORS:
# https://esphome.io/components/status_led.html
#############################################
#status_led:
# pin:
# number: GPIO2
# inverted: yes
#############################################
# SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
############################################# #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO00 number: GPIO0
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
name: Button name: "Button"
on_press: on_press:
- switch.toggle: virtual_button - switch.toggle: virtual_button
- platform: template - platform: template
name: ${entity_prefix} Running name: "${entity_prefix} Running"
filters: filters:
- delayed_off: 15s - delayed_off: 15s
lambda: |- lambda: |-
if (isnan(id(power).state)) { if (isnan(id(power).state)) {
return {}; return {};
} else if (id(power).state > 4) { } else if (id(power).state > 4) {
// Running
return true; return true;
} else { } else {
// Not running
return false; return false;
} }
#:########################################################################################:#
# SENSORS COMPONENT:
# https://esphome.io/components/sensor/
#:########################################################################################:#
sensor: sensor:
- platform: hlw8012 - platform: hlw8012
sel_pin: 5 sel_pin: 5
@@ -185,20 +211,17 @@ sensor:
cf1_pin: 13 cf1_pin: 13
update_interval: 2s update_interval: 2s
current: current:
name: ${entity_prefix} Current name: "${entity_prefix} Current"
voltage: voltage:
name: ${entity_prefix} Voltage name: "${entity_prefix} Voltage"
power: power:
name: ${entity_prefix} Power name: "${entity_prefix} Power"
id: power id: power
#on_value_range:
# - above: 4.0
# then:
# - light.turn_on: led
# - below: 3.0
# then:
# - light.turn_off: led
#:########################################################################################:#
# SWITCH COMPONENT:
# https://esphome.io/components/switch/
#:########################################################################################:#
switch: switch:
- platform: template - platform: template
name: "Relay" name: "Relay"
@@ -215,7 +238,6 @@ switch:
id: relay id: relay
pin: GPIO12 pin: GPIO12
restore_mode: RESTORE_DEFAULT_ON restore_mode: RESTORE_DEFAULT_ON
# restore_mode: ALWAYS_ON # Or RESTORE_DEFAULT_ON/RESTORE_DEFAULT_OFF
on_turn_on: on_turn_on:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}" topic: "${mqtt_local_status_topic}"
@@ -227,19 +249,31 @@ switch:
payload: "OFF" payload: "OFF"
retain: false retain: false
#:########################################################################################:#
# OUTPUT COMPONENT:
# https://esphome.io/components/output/
#:########################################################################################:#
output: output:
- platform: esp8266_pwm - platform: esp8266_pwm
id: pow_blue_led id: pow_blue_led
pin: pin:
number: GPIO15 number: GPIO15
inverted: True inverted: true
#:########################################################################################:#
# LIGHT COMPONENT:
# https://esphome.io/components/light/
#:########################################################################################:#
light: light:
- platform: monochromatic - platform: monochromatic
name: Status LED name: "Status LED"
output: pow_blue_led output: pow_blue_led
id: led id: led
#:########################################################################################:#
# SCRIPT COMPONENT:
# https://esphome.io/components/script.html
#:########################################################################################:#
script: script:
- id: publish_state_burst - id: publish_state_burst
mode: restart mode: restart
+81 -50
View File
@@ -1,23 +1,40 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: ARCADE CABINET 1 POWER (ATHOM SMART PLUG V1)
# zorruno.com layout v1.0 2026
#:########################################################################################:#
# VERSIONS:
# V1.0 Unknown date - Initial Version (date not present in source header)
#:########################################################################################:#
# HARDWARE:
# - Athom Smart Plug Power V1 (ESP8285 / ESP8266 family)
# - Load: MAME Arcade Cabinet 1 (Defender)
#:########################################################################################:#
# OPERATION NOTES:
# - Controls arcade cabinet mains power via Athom Smart Plug relay
# - Provides power monitoring via included Athom PowerMon V1 common package
# - Local power button toggles relay state
#:########################################################################################:#
# MQTT COMMANDS:
# #
########################################################################################## #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
#
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-arcademachine1" device_name: "esp-arcademachine1"
friendly_name: "Arcade Cabinet 1" friendly_name: "Arcade Cabinet 1"
description_comment: "MAME Arcade 1 (Defender) machine power :: Athom Smart Plug Power V1" description_comment: "MAME Arcade 1 (Defender) machine power :: Athom Smart Plug Power V1 (Layout V1.0)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Athom Technology.Smart Plug V1" # Project Details project_name: "Athom Technology.Smart Plug V1" # Project Details
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Passwords
@@ -34,13 +51,14 @@ substitutions:
update_interval: "10s" # update time for for general sensors etc update_interval: "10s" # update time for for general sensors etc
# Device Settings # Device Settings
relay_icon: "mdi:power-socket-au" relay_icon: "mdi:power-socket-au"
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
##########################################################################################
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
################################################## ##################################################
# MANDATORY packages (won't compile without them!) # MANDATORY packages (won't compile without them!)
@@ -57,7 +75,7 @@ packages:
################################################## ##################################################
# OPTIONAL packages (comment if you don't want them) # OPTIONAL packages (comment if you don't want them)
################################################## ##################################################
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -65,7 +83,7 @@ packages:
#file: common/api_common_noencryption.yaml #file: common/api_common_noencryption.yaml
vars: vars:
local_api_key: "${api_key}" local_api_key: "${api_key}"
#### WEB PORTAL #### #### WEB PORTAL ####
common_webportal: !include common_webportal: !include
file: common/webportal_common.yaml file: common/webportal_common.yaml
@@ -75,7 +93,7 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common_sntp: !include
file: common/sntp_common.yaml file: common/sntp_common.yaml
@@ -100,56 +118,69 @@ packages:
local_friendly_name: "${friendly_name}" local_friendly_name: "${friendly_name}"
local_current_limit: "${current_limit}" local_current_limit: "${current_limit}"
##########################################################################################
# ESPHome #:########################################################################################:#
# ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
name_add_mac_suffix: False name_add_mac_suffix: false
min_version: 2024.6.0 min_version: 2024.6.0
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
#framework: #framework:
# version: 2.7.4 # version: 2.7.4
#:########################################################################################:#
# PREFERENCES:
# https://esphome.io/components/preferences.html
#:########################################################################################:#
preferences: preferences:
flash_write_interval: 10min flash_write_interval: 10min
mdns:
disabled: False # binary size saving
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # MDNS:
# https://esphome.io/components/mdns.html
#:########################################################################################:#
mdns:
disabled: false # binary size saving
#:########################################################################################:#
# LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing 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) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
##########################################################################################
# BINARY SENSORS #:########################################################################################:#
# BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO03 number: GPIO3
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: true inverted: true
name: "Power Button" name: "Power Button"
@@ -162,28 +193,28 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay).state) { if (id(relay).state) {
// Relay is ON: turn it OFF and set mode to 2 (TIMER) // Relay is ON: turn it OFF
id(relay).turn_off(); id(relay).turn_off();
} else { } else {
// Relay is OFF: turn it ON and set mode to 3 (BOOST) // Relay is OFF: turn it ON
id(relay).turn_on(); id(relay).turn_on();
} }
- platform: template - platform: template
name: "Relay Status" name: "Relay Status"
lambda: |- lambda: |-
return id(relay).state; return id(relay).state;
#################################################################################################
# SWITCH COMPONENT #:########################################################################################:#
# SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
################################################################################################# #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Power Output" name: "Power Output"
pin: GPIO14 pin: GPIO14
id: relay id: relay
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
#internal: true # Hides the switch from Home Assistant #internal: true # Hides the switch from Home Assistant
icon: "${relay_icon}" icon: "${relay_icon}"
+108 -80
View File
@@ -1,39 +1,62 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: MASTER BEDROOM BEDSIDE LAMP BULB
# MASTER BEDROOM BEDSIDE LAMP BULB # zorruno.com layout v1.1 2026
# File: esp-bedrm1arlecbulb.yaml #:########################################################################################:#
# # REPO:
# v1.1 - 2026-02-21 Add "Jump Fade Up/Down" switch + configurable Jump Fade (%) # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-bedrm1arlecbulb.yaml
# v1.0 - 2026-02-21 Initial version (ported from Athom bulb YAML to Arlec GLD120HA) #:########################################################################################:#
# # VERSIONS:
# Hardware: Arlec Grid Connect Smart LED Globe RGB (GLD120HA) - B22 # v1.2 2026-02-25 Updated yaml to zorruno layout V1.1
# RGB + Warm White + Cold White (RGBWW, 5x PWM channels) # v1.1 2026-02-21 Add "Jump Fade Up/Down" switch + configurable Jump Fade (%)
# # v1.0 2026-02-21 Initial version (ported from Athom bulb YAML to Arlec GLD120HA)
# NOTES #:########################################################################################:#
# - This keeps the "preferred control" ramping / min-max / watchdog / restore logic. # HARDWARE:
# - Arlec Grid Connect Smart LED Globe RGB (GLD120HA) - B22
# - ESP8266 (PWM, 5x channels) RGB + Warm White + Cold White (RGBWW)
# - PWM channels:
# - Red GPIO4
# - Green GPIO12
# - Blue GPIO14
# - Warm White GPIO13
# - Cold White GPIO5
#:########################################################################################:#
# OPERATION NOTES:
# - Keeps the "preferred control" ramping / min-max / watchdog / restore logic.
# - All ramping and "Output Set (0-100)" controls FORCE the bulb into Warm White endpoint # - All ramping and "Output Set (0-100)" controls FORCE the bulb into Warm White endpoint
# (so everyday dimming uses the Warm White channel only, not mixed CT). # (everyday dimming uses Warm White channel only, not mixed CT).
# - You can still control full RGB and CT from HA using the normal light entity. # - Full RGB and CT control is still available from HA using the normal light entity.
# - Max On watchdog turns the whole bulb OFF at the time limit (all channels). # - Max On watchdog turns the whole bulb OFF at the time limit (all channels).
# - Jump Fade switch behavior: # - Jump Fade switch behavior:
# - ON: jump to (jump% of max cap), then fade up to full (normal fade-up). # - ON: jump to (jump% of max cap), then fade up to full (normal fade-up).
# - OFF: jump down to (current - current*jump%), then fade down to OFF (normal fade-down). # - OFF: jump down to (current - current*jump%), then fade down to OFF (normal fade-down).
########################################################################################## #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Bulb continues local operation and restores per configured restart action.
# - MQTT state publishing may not be visible in HA until HA returns.
# b) MQTT OFFLINE (or broker unreachable)
# - Bulb still operates via HA API (if available) and local logic.
# - MQTT local command topics will not work while MQTT is down.
# c) Entire WiFi/Network OFFLINE
# - Bulb still operates locally (last state/restore behavior as configured).
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
########################################################################################## # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm1arlecbulb" # yaml file should be device_name.yaml device_name: "esp-bedrm1arlecbulb" # yaml file should be device_name.yaml
friendly_name: "Master Bedroom Bedside Lamp Arlec Bulb" friendly_name: "Master Bedroom Bedside Lamp Arlec Bulb"
description_comment: "Bedside lightbulb using gridconnect Arlec RGB bulb" description_comment: "Bedside lightbulb using gridconnect Arlec RGB bulb (Layout V1.1)"
device_area: "Master Bedroom" device_area: "Master Bedroom"
# Project Naming # Project Naming
project_name: "Grid Connect GLD120HA RGBWW.Arlec" project_name: "Grid Connect GLD120HA RGBWW.Arlec"
project_version: "v1.1" project_version: "v1.2"
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names) # Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
# Re-using your existing bulb flasher secrets (adjust if you prefer per-device secrets) # Re-using your existing bulb flasher secrets (adjust if you prefer per-device secrets)
@@ -55,28 +78,29 @@ substitutions:
mqtt_local_device_command_OFF: "OFF" mqtt_local_device_command_OFF: "OFF"
# Device Specific Settings # Device Specific Settings
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
update_interval: "20s" update_interval: "20s"
led_gamma: "2.8" led_gamma: "2.8"
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
maximum_led_output: "80" # % Hard cap maximum_led_output: "80" # % Hard cap
max_on_default_hours: "24" # 0 = no automatic turn-off max_on_default_hours: "24" # 0 = no automatic turn-off
pwm_frequency: "1000" # Hz pwm_frequency: "1000" # Hz
# Warm/cold endpoints (reported range around 3000K-5700K) # Warm/cold endpoints (reported range around 3000K-5700K)
bulb_warm_kelvin: "3000 K" bulb_warm_kelvin: "3000 K"
bulb_cold_kelvin: "5700 K" bulb_cold_kelvin: "5700 K"
# Arlec GLD120HA GPIO mapping (PWM) # Arlec GLD120HA GPIO mapping (PWM)
bulb_red_pin: GPIO4 bulb_red_pin: GPIO4
bulb_green_pin: GPIO12 bulb_green_pin: GPIO12
bulb_blue_pin: GPIO14 bulb_blue_pin: GPIO14
bulb_warm_white_pin: GPIO13 bulb_warm_white_pin: GPIO13
bulb_cold_white_pin: GPIO5 bulb_cold_white_pin: GPIO5
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
########################################################################################## # https://esphome.io/components/packages.html
#:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -100,13 +124,14 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome CORE CONFIGURATION # ESPHOME CORE CONFIGURATION
########################################################################################## # https://esphome.io/components/esphome.html
#:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -158,9 +183,10 @@ esphome:
# Boot complete: allow OFF handlers again # Boot complete: allow OFF handlers again
- lambda: 'id(booting) = false;' - lambda: 'id(booting) = false;'
########################################################################################## #:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK # ESP PLATFORM AND FRAMEWORK
########################################################################################## # https://esphome.io/components/esp8266.html
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
restore_from_flash: true restore_from_flash: true
@@ -171,9 +197,10 @@ mdns:
preferences: preferences:
flash_write_interval: 1min flash_write_interval: 1min
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES
########################################################################################## # https://esphome.io/components/globals.html
#:########################################################################################:#
globals: globals:
- id: min_brightness_pct - id: min_brightness_pct
type: int type: int
@@ -255,22 +282,23 @@ globals:
restore_value: false restore_value: false
initial_value: "false" initial_value: "false"
# Jump Fade percentage (default 25%) # Jump Fade percentage
- id: jump_fade_pct - id: jump_fade_pct
type: int type: int
restore_value: true restore_value: true
initial_value: "15" initial_value: "15"
########################################################################################## #:########################################################################################:#
# LOGGER # LOGGING
########################################################################################## # https://esphome.io/components/logger.html
#:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 baud_rate: 0
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS (adds device-specific triggers to common MQTT) # MQTT COMMANDS (adds device-specific triggers to common MQTT)
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
- topic: "${mqtt_local_command_topic}/light/set" - topic: "${mqtt_local_command_topic}/light/set"
@@ -283,9 +311,10 @@ mqtt:
then: then:
- switch.turn_off: bulb_ramp_switch - switch.turn_off: bulb_ramp_switch
########################################################################################## #:########################################################################################:#
# SWITCH # SWITCH
########################################################################################## # https://esphome.io/components/switch/
#:########################################################################################:#
switch: switch:
- platform: template - platform: template
id: bulb_ramp_switch id: bulb_ramp_switch
@@ -319,9 +348,10 @@ switch:
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
- script.execute: jump_ramp_off_script - script.execute: jump_ramp_off_script
########################################################################################## #:########################################################################################:#
# BUTTON # BUTTON
########################################################################################## # https://esphome.io/components/button/index.html
#:########################################################################################:#
button: button:
- platform: template - platform: template
id: fade_up_button id: fade_up_button
@@ -370,9 +400,10 @@ button:
id(last_brightness_pct) = pct; id(last_brightness_pct) = pct;
} }
########################################################################################## #:########################################################################################:#
# SELECT # SELECT
########################################################################################## # https://esphome.io/components/select/index.html
#:########################################################################################:#
select: select:
- platform: template - platform: template
id: restart_action id: restart_action
@@ -394,9 +425,10 @@ select:
id(restart_mode) = 2; id(restart_mode) = 2;
} }
########################################################################################## #:########################################################################################:#
# SENSORS # SENSORS
########################################################################################## # https://esphome.io/components/sensor/
#:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
id: bulb_output_pct id: bulb_output_pct
@@ -445,9 +477,10 @@ sensor:
if (pwm > 1.0f) pwm = 1.0f; if (pwm > 1.0f) pwm = 1.0f;
return pwm * 100.0f; return pwm * 100.0f;
########################################################################################## #:########################################################################################:#
# OUTPUTS: 5 x PWM channels for the Arlec GLD120HA RGBWW bulb # OUTPUTS: 5 x PWM channels for the Arlec GLD120HA RGBWW bulb
########################################################################################## # https://esphome.io/components/output/
#:########################################################################################:#
output: output:
- platform: esp8266_pwm - platform: esp8266_pwm
id: output_red id: output_red
@@ -474,9 +507,10 @@ output:
pin: ${bulb_cold_white_pin} pin: ${bulb_cold_white_pin}
frequency: ${pwm_frequency} frequency: ${pwm_frequency}
########################################################################################## #:########################################################################################:#
# LIGHT: RGBWW (correct for this bulb) # LIGHT: RGBWW (correct for this bulb)
########################################################################################## # https://esphome.io/components/light/
#:########################################################################################:#
light: light:
- platform: rgbww - platform: rgbww
id: bulb_light id: bulb_light
@@ -492,10 +526,9 @@ light:
warm_white_color_temperature: ${bulb_warm_kelvin} warm_white_color_temperature: ${bulb_warm_kelvin}
cold_white_color_temperature: ${bulb_cold_kelvin} cold_white_color_temperature: ${bulb_cold_kelvin}
# Safety: do not allow RGB and whites simultaneously
color_interlock: true color_interlock: true
# Important: keep OFF at boot to avoid instant restore flashes; boot script handles behavior. # Keep OFF at boot to avoid instant restore flashes; boot script handles behavior.
restore_mode: ALWAYS_OFF restore_mode: ALWAYS_OFF
default_transition_length: 2s default_transition_length: 2s
@@ -533,7 +566,6 @@ light:
id(last_set_pos) = 0; id(last_set_pos) = 0;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
# Cap brightness to max_brightness_pct without a visible step
on_state: on_state:
- lambda: |- - lambda: |-
const float cap = id(max_brightness_pct) / 100.0f; const float cap = id(max_brightness_pct) / 100.0f;
@@ -548,9 +580,10 @@ light:
call.set_transition_length(0); call.set_transition_length(0);
call.perform(); call.perform();
########################################################################################## #:########################################################################################:#
# NUMBER # NUMBER
########################################################################################## # https://esphome.io/components/number/
#:########################################################################################:#
number: number:
- platform: template - platform: template
id: cfg_ramp_up_s id: cfg_ramp_up_s
@@ -612,7 +645,6 @@ number:
id(jump_fade_pct) = v; id(jump_fade_pct) = v;
id(cfg_jump_fade_pct).publish_state((float) v); id(cfg_jump_fade_pct).publish_state((float) v);
# This is the preferred everyday dimmer slider (FORCES Warm endpoint)
- platform: template - platform: template
id: led_output_set_pct id: led_output_set_pct
name: "${friendly_name} Output Set (0-100)" name: "${friendly_name} Output Set (0-100)"
@@ -713,9 +745,10 @@ number:
then: then:
- script.execute: max_on_watchdog - script.execute: max_on_watchdog
########################################################################################## #:########################################################################################:#
# SCRIPTS # SCRIPTS
########################################################################################## # https://esphome.io/components/script.html
#:########################################################################################:#
script: script:
- id: ramp_on_script - id: ramp_on_script
mode: restart mode: restart
@@ -930,7 +963,6 @@ script:
then: then:
- script.stop: ramp_off_script - script.stop: ramp_off_script
# Jump UP to (jump_pct% of max cap), only if we are below it.
- if: - if:
condition: condition:
lambda: |- lambda: |-
@@ -971,7 +1003,6 @@ script:
return target_pct / 100.0f; return target_pct / 100.0f;
transition_length: 0s transition_length: 0s
# Then fade up to full using your normal fade logic
- script.execute: ramp_on_script - script.execute: ramp_on_script
# Jump Fade: OFF = jump down to (current - current*jump%) then normal fade down to OFF # Jump Fade: OFF = jump down to (current - current*jump%) then normal fade down to OFF
@@ -980,12 +1011,10 @@ script:
then: then:
- script.stop: ramp_on_script - script.stop: ramp_on_script
# If the light is off already, do nothing fancy (avoids a flash from ramp_off_script).
- if: - if:
condition: condition:
lambda: 'return id(bulb_light).current_values.is_on();' lambda: 'return id(bulb_light).current_values.is_on();'
then: then:
# Jump DOWN to (100 - jump)% of current brightness (25 -> 75%), clamp to min.
- light.turn_on: - light.turn_on:
id: bulb_light id: bulb_light
color_temperature: "${bulb_warm_kelvin}" color_temperature: "${bulb_warm_kelvin}"
@@ -997,7 +1026,7 @@ script:
if (jp < 0.0f) jp = 0.0f; if (jp < 0.0f) jp = 0.0f;
if (jp > 100.0f) jp = 100.0f; if (jp > 100.0f) jp = 100.0f;
float factor = (100.0f - jp) / 100.0f; // 25 -> 0.75 float factor = (100.0f - jp) / 100.0f;
float target_pct = curr_pct * factor; float target_pct = curr_pct * factor;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
@@ -1010,7 +1039,6 @@ script:
return target_pct / 100.0f; return target_pct / 100.0f;
transition_length: 0s transition_length: 0s
# Then fade down to off using your normal fade logic
- script.execute: ramp_off_script - script.execute: ramp_off_script
else: else:
- light.turn_off: - light.turn_off:
+162 -133
View File
@@ -1,70 +1,88 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: CEILING FAN - BEDROOM 2
# CEILING FAN - BEDROOM 2 # zorruno.com layout v1.0 2026
# - 3 speed fan using Sonoff IFan02 #:########################################################################################:#
# - Also, single Light Output # VERSIONS:
# V1.0 2025-07-21 First Setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# Controlled by a Sonoff iFan02 (3-speed fan + 1x light relay)
#:########################################################################################:#
# OPERATION NOTES:
# - Fan and light can be controlled via MQTT (local topics below) and via Home Assistant API
# - Fan speed state is tracked in a restored global (speed_value)
# - UART0 is used to sniff fan MCU frames (useful for RF remote debug)
#:########################################################################################:#
# MQTT COMMANDS:
# Fan speed command:
# ${mqtt_local_command_topic}/speed/set -> 0,1,2,3,+,-
# Fan light command:
# ${mqtt_local_command_topic}/light/set -> ON,OFF
# #
# Controlled by a Sonoff IFan 02 # Fan speed status:
# # ${mqtt_local_status_topic}/speed/state -> 0,1,2,3
# V1.0 - 2025-07-21 First Setup (and replacement of Tasmota) # Fan light status:
# # ${mqtt_local_status_topic}/light/state -> ON,OFF
# NOTES: #:########################################################################################:#
# Command the fan with MQTT # OFFLINE NOTES:
# ${mqtt_local_command_full_topic}/speed/set 1,2,3,0,+,- # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# ${mqtt_local_command_full_topic}/light/set ON,OFF # - Device remains controllable via MQTT local command topics
# Status of the fan is in MQTT # - Status publishes to MQTT still occur (speed and light state)
# ${mqtt_local_command_full_topic}/speed/state 1,2,3,0 # - HA entities (fan/light/select) will be unavailable until HA returns
# ${mqtt_local_command_full_topic}/light/state ON,OFF # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# # - Device remains controllable from Home Assistant via API (fan/light/select)
########################################################################################## # - MQTT local commands will not work and status publishes will fail while MQTT is down
########################################################################################## # c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - If power remains on, the relays keep their last driven state (fan speed relays and light relay)
# - If the device reboots while offline, fan/light restore_mode defaults apply (RESTORE_DEFAULT_OFF)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm2ceilingfan" device_name: "esp-bedrm2ceilingfan"
friendly_name: "Bedroom 2 Ceiling Fan" friendly_name: "Bedroom 2 Ceiling Fan"
description_comment: "3 Speed Overhead Ceiling Fan Bedroom 2 :: Sonoff ifan02" description_comment: "3 Speed Overhead Ceiling Fan Bedroom 2 :: Sonoff iFan02 (Layout V1.0)"
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sonoff Technologies.Sonoff ifan02" # Project Details project_name: "Sonoff Technologies.Sonoff iFan02" # Project Details
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords and Secrets
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-bedrm2ceilingfan_ip # unfortunately you can't use substitutions inside secrets names static_ip_address: !secret esp-bedrm2ceilingfan_ip # unfortunately you can't use substitutions inside secrets names
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls # MQTT LOCAL Controls
mqtt_device_name: "bedroom2-ceilingfan" mqtt_device_name: "bedroom2-ceilingfan"
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic used 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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic used to view status locally without HA
# MQTT REMOTE Controls # Switch/Relay Naming and Icons
light_1_name: "Fan Light"
switch_2_name: "Fan 2 Relay"
switch_3_name: "Fan 3 Relay"
switch_4_name: "Fan 4 Relay"
# Button Naming & Icons #:########################################################################################:#
# Switch/Relay Naming & Icons
#relay_icon: "mdi:lightbulb-group"
light_1_name: "Fan Light"
switch_2_name: "Fan 2 Relay"
switch_3_name: "Fan 3 Relay"
switch_4_name: "Fan 4 Relay"
##########################################################################################
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -73,6 +91,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -86,102 +105,99 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
on_boot: # This weird toggle thing makes sure the states get restored on reboot on_boot: # Publish restored speed on boot so other systems can sync
priority : -100 priority: -100
then: then:
- delay: 200ms - delay: 200ms
#- fan.toggle: ifan02_fan
#- fan.toggle: ifan02_fan
#- delay: 200ms
#- light.toggle: ifan02_light
#- delay: 1ms
#- light.toggle: ifan02_light
#- delay: 1s
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
# platformio_options: # platformio_options:
# build_flags: # build_flags:
# - "-Os" # optimize for size # - "-Os" # optimize for size
# - "-Wl,--gc-sections" # drop unused code/data # - "-Wl,--gc-sections" # drop unused code/data
# - "-fno-exceptions" # strip C++ exceptaions # - "-fno-exceptions" # strip C++ exceptions
# - "-fno-rtti" # strip C++ RTTI # - "-fno-rtti" # strip C++ RTTI
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m # Sonoff iFan02
restore_from_flash: True # restore some values on reboot restore_from_flash: true # restore some values on reboot
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
mdns: mdns:
disabled: True # Disabling will make the build file smaller (and it is still available via static IP) disabled: true # Disabling will make the build file smaller (and it is still available via static IP)
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES:
########################################################################################## # https://esphome.io/guides/automations.html#global-variables
#:########################################################################################:#
globals: globals:
- id: speed_value - id: speed_value
type: int type: int
restore_value: yes restore_value: true
initial_value: '0' initial_value: "0"
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" # INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) baud_rate: 0 # set to 0 for no logging via UART (UART0 used for fan MCU sniffing)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# UART: Fan MCU / RF Remote Sniff (iFan02 -> ESP over UART0) # UART:
# Fan MCU / RF Remote Sniff (iFan02 -> ESP over UART0)
# - Uses GPIO3 (RX0) to listen to the fan microcontroller frames (433 MHz remote is decoded there) # - Uses GPIO3 (RX0) to listen to the fan microcontroller frames (433 MHz remote is decoded there)
# - 9600 8N1 is typical; if no frames appear, try 19200 (uncomment below) # - 9600 8N1 is typical; if no frames appear, try 19200 (uncomment below)
# - If still nothing, some revisions route MCU TX to another pin; try rx_pin: GPIO13 # - If still nothing, some revisions route MCU TX to another pin; try rx_pin: GPIO13
########################################################################################## #:########################################################################################:#
uart: uart:
id: ifan_uart id: ifan_uart
tx_pin: GPIO1 # ESP TX0 -> Fan MCU RX (not required for sniffing, but harmless) tx_pin: GPIO1 # ESP TX0 -> Fan MCU RX (not required for sniffing, but harmless)
rx_pin: GPIO3 # ESP RX0 <- Fan MCU TX (primary source for RF button frames) rx_pin: GPIO3 # ESP RX0 <- Fan MCU TX (primary source for RF button frames)
baud_rate: 9600 baud_rate: 9600
#baud_rate: 19200 # <-- try this if you see no frames in logs #baud_rate: 19200 # try this if you see no frames in logs
rx_buffer_size: 256 rx_buffer_size: 256
# NOTE: If no frames appear at either 9600 or 19200, try moving rx_pin to GPIO13 and reflash: # NOTE: If no frames appear at either 9600 or 19200, try moving rx_pin to GPIO13 and reflash:
# rx_pin: GPIO13 # rx_pin: GPIO13
########################################################################################## #:########################################################################################:#
# INTERVAL: Accumulate UART bytes and publish last frame to text sensor # INTERVAL COMPONENT:
# https://esphome.io/components/interval.html
#
# Accumulate UART bytes and publish last frame to text sensor
# - Publishes after ~60ms of silence to group a single button press into one frame # - Publishes after ~60ms of silence to group a single button press into one frame
########################################################################################## #:########################################################################################:#
interval: interval:
- interval: 50ms - interval: 50ms
then: then:
@@ -206,20 +222,20 @@ interval:
frame.clear(); frame.clear();
} }
########################################################################################## #:########################################################################################:#
# TEXT SENSORS: RF/MCU debug output (last frame seen) # TEXT SENSORS COMPONENT:
# - Shows the last raw hex bytes received from the fan MCU when you press the RF remote # https://esphome.io/components/text_sensor/index.html
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
- platform: template - platform: template
id: ifan_last_rf id: ifan_last_rf
name: "iFan02 Remote Last Frame" name: "iFan02 Remote Last Frame"
update_interval: never update_interval: never
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Light control # Light control
@@ -227,12 +243,13 @@ mqtt:
payload: "ON" payload: "ON"
then: then:
- light.turn_on: ifan02_light - light.turn_on: ifan02_light
- topic: "${mqtt_local_command_topic}/light/set" - topic: "${mqtt_local_command_topic}/light/set"
payload: "OFF" payload: "OFF"
then: then:
- light.turn_off: ifan02_light - light.turn_off: ifan02_light
# Fan speed control (03) + ramp up/down (+ / -) # Fan speed control (0-3) plus ramp up/down (+ / -)
- topic: "${mqtt_local_command_topic}/speed/set" - topic: "${mqtt_local_command_topic}/speed/set"
then: then:
# 1) Compute new speed_value based on payload # 1) Compute new speed_value based on payload
@@ -257,21 +274,21 @@ mqtt:
# 2) Drive the fan based on the new value # 2) Drive the fan based on the new value
- if: - if:
condition: condition:
lambda: 'return id(speed_value) == 0;' lambda: "return id(speed_value) == 0;"
then: then:
- fan.turn_off: ifan02_fan - fan.turn_off: ifan02_fan
else: else:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: !lambda 'return id(speed_value);' speed: !lambda "return id(speed_value);"
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #
# Sonoff ifan02 has relays, but they don't need to be shown in HA because # Sonoff iFan02 has relays, but they do not need to be shown in HA because
# the speed of the fan is the important part (and combinations of the relays give that) # the speed of the fan is the important part (and combinations of the relays give that)
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "${switch_3_name}" name: "${switch_3_name}"
@@ -279,12 +296,14 @@ switch:
id: fan3sw id: fan3sw
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
- platform: gpio - platform: gpio
name: "${switch_2_name}" name: "${switch_2_name}"
pin: GPIO5 pin: GPIO5
id: fan2sw id: fan2sw
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
- platform: gpio - platform: gpio
name: "${switch_4_name}" name: "${switch_4_name}"
pin: GPIO15 pin: GPIO15
@@ -292,10 +311,10 @@ switch:
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
########################################################################################## #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
########################################################################################## #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Bedroom 2 Fan Speed" name: "Bedroom 2 Fan Speed"
@@ -322,6 +341,7 @@ select:
- lambda: |- - lambda: |-
id(speed_value) = 0; id(speed_value) = 0;
- fan.turn_off: ifan02_fan - fan.turn_off: ifan02_fan
# LOW (1) # LOW (1)
- if: - if:
condition: condition:
@@ -332,6 +352,7 @@ select:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: 1 speed: 1
# MEDIUM (2) # MEDIUM (2)
- if: - if:
condition: condition:
@@ -342,6 +363,7 @@ select:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: 2 speed: 2
# HIGH (3) # HIGH (3)
- if: - if:
condition: condition:
@@ -353,13 +375,17 @@ select:
id: ifan02_fan id: ifan02_fan
speed: 3 speed: 3
################################################################################ #:########################################################################################:#
# TEMPLATE OUTPUTS: drive the real relays when the states change # OUTPUT COMPONENT:
################################################################################ # https://esphome.io/components/output/
#
# Template output drives the real relays when the fan output state changes
#:########################################################################################:#
output: output:
- platform: gpio - platform: gpio
pin: GPIO12 pin: GPIO12
id: lightrelay id: lightrelay
- platform: template - platform: template
type: float type: float
id: fan_decode id: fan_decode
@@ -386,17 +412,17 @@ output:
id(fan4sw).turn_on(); id(fan4sw).turn_on();
} }
########################################################################################## #:########################################################################################:#
# LIGHT COMPONENT # LIGHT COMPONENT:
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: binary - platform: binary
name: "${light_1_name}" name: "${light_1_name}"
output: lightrelay output: lightrelay
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
id: ifan02_light id: ifan02_light
# publish status updates when the light turns on/off: # Publish status updates when the light turns on/off
on_turn_on: on_turn_on:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state" topic: "${mqtt_local_status_topic}/light/state"
@@ -406,10 +432,10 @@ light:
topic: "${mqtt_local_status_topic}/light/state" topic: "${mqtt_local_status_topic}/light/state"
payload: "OFF" payload: "OFF"
########################################################################################## #:########################################################################################:#
# FAN COMPONENT # FAN COMPONENT:
# https://esphome.io/components/fan/index.html # https://esphome.io/components/fan/index.html
########################################################################################## #:########################################################################################:#
fan: fan:
- platform: speed - platform: speed
output: fan_decode output: fan_decode
@@ -417,28 +443,31 @@ fan:
id: ifan02_fan id: ifan02_fan
speed_count: 3 speed_count: 3
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
# whenever you explicitly set a speed (13):
# Whenever you explicitly set a speed (1-3)
on_speed_set: on_speed_set:
- lambda: |- - lambda: |-
id(speed_value) = x; id(speed_value) = x;
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
# whenever the fan goes fully off:
# Whenever the fan goes fully off
on_turn_off: on_turn_off:
- lambda: |- - lambda: |-
id(speed_value) = 0; id(speed_value) = 0;
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: "0" payload: "0"
# whenever the fan goes off→on (e.g. via HAs Fan switch):
# Whenever the fan goes off->on (eg via HA fan switch)
on_turn_on: on_turn_on:
- lambda: |- - lambda: |-
// bump 0->1 if we were off // Bump 0->1 if we were off
if (id(speed_value) == 0) id(speed_value) = 1; if (id(speed_value) == 0) id(speed_value) = 1;
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: !lambda 'return id(speed_value);' speed: !lambda "return id(speed_value);"
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
+118 -95
View File
@@ -1,36 +1,61 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: BEDROOM 2 FAN SWITCH (WALL SWITCH)
# BEDROOM 2 FAN SWITCH # zorruno.com layout v1.0 2026
#:########################################################################################:#
# VERSIONS:
# V1.0 2025-07-23 First Setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# Controlled by a Zemismart KS-811 Triple push button (KS-811-3)
# pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Wall switch for Bedroom 2 ceiling fan
# - 3 physical buttons: Speed Up (Button 1), Speed Down (Button 2), Fan Off (Button 3)
# - Buttons publish MQTT commands to the fan speed topic (remote control)
# - Device also subscribes to the fan speed state topic and drives the local KS-811 relays
# as a visual indicator of current speed (0-3)
#:########################################################################################:#
# MQTT COMMANDS:
# Remote fan speed command topic:
# ${mqtt_remote_device_command_topic}
# Payloads sent by buttons:
# Button 1 (Speed Up) -> "+"
# Button 2 (Speed Down) -> "-"
# Button 3 (Fan Off) -> "0"
# #
# Controlled by a Zemismart KS-811 Triple push button # Subscribed speed state topic (drives relay indicators):
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # ${mqtt_local_status_topic} -> 0,1,2,3
# #:########################################################################################:#
# V1.0 - 2025-07-23 First Setup (and replacement of Tasmota) # OFFLINE NOTES:
# # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# NOTES # - Buttons still publish MQTT commands directly to the fan
# - Switch for Ceiling Fan # - Relay indicator sync still works (subscribed MQTT state updates)
# - 3 Switches, Up, Down and Off # - HA entities for this switch device are unavailable until HA returns
# - Remote commands to the fan ${mqtt_remote_command_full_topic}/speed/set 1,2,3,0,+,- # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# # - Buttons cannot command the fan (no MQTT broker available)
########################################################################################## # - Relay indicator sync will not update from fan speed state
########################################################################################## # - HA can still see/control only this device entities, but the fan control path is MQTT
# c) Entire WiFi/Network OFFLINE
# - No MQTT publish/subscribe and no HA API connectivity
# - Buttons will do nothing to the fan (no transport)
# - Relay indicators will remain in their last state until connectivity returns (or reboot)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm2fanswitch" device_name: "esp-bedrm2fanswitch"
friendly_name: "Bedroom 2 Fan Wall Switch (3)" friendly_name: "Bedroom 2 Fan Wall Switch (3)"
description_comment: "Switch for Bedroom 2 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3)" description_comment: "Switch for Bedroom 2 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3) (Layout V1.0)"
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
entity_prefix: "Main Bathroom" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
# Passwords # Passwords
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
@@ -38,37 +63,34 @@ substitutions:
static_ip_address: !secret esp-bedrm2fanswitch_ip static_ip_address: !secret esp-bedrm2fanswitch_ip
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
# Device Settings
#relay_icon: "mdi:heating-coil"
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
# MQTT LOCAL Controls # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
#mqtt_device_name: "bedroom2-ceilingfan-switch" # Don't forget to switch it back when changed.
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA current_ip_address: ${static_ip_address}
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for general sensors etc
# MQTT REMOTE Controls # MQTT REMOTE Controls
mqtt_remote_device_name: "bedroom2-ceilingfan" mqtt_remote_device_name: "bedroom2-ceilingfan"
mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/speed/set" mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/speed/set"
mqtt_remote_device_command1: "+" mqtt_remote_device_command1: "+"
mqtt_remote_device_command2: "-" mqtt_remote_device_command2: "-"
mqtt_remote_device_command3: "0" mqtt_remote_device_command3: "0"
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
# Fan speed status topic (used to sync relay indicators)
# Button Naming & Icons mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/speed/state"
# Switch/Relay Naming & Icons # Switch/Relay Naming & Icons
#relay_icon: "mdi:heating-coil" switch_1_name: "Fan Speed Up" # Virtual intent only, no load connected to relay 1
switch_1_name: "Fan Speed Up" # This is virtual only, no power connected to 1st relay switch_2_name: "Fan Speed Down" # Virtual intent only, no load connected to relay 2
switch_2_name: "Fan Speed Down" # This is virtual only, no power connected to 2nd relay switch_3_name: "Fan Off" # Virtual intent only, no load connected to relay 3
switch_3_name: "Fan Off" # This is virtual only, no power connected to 3rd relay
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -77,6 +99,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -90,85 +113,80 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: ${device_name} name: "${device_name}"
friendly_name: ${friendly_name} friendly_name: "${friendly_name}"
comment: ${description_comment} #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: ${device_area} area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
# platformio_options: # platformio_options:
# build_flags: # build_flags:
# - "-Os" # optimize for size # - "-Os" # optimize for size
# - "-Wl,--gc-sections" # drop unused code/data # - "-Wl,--gc-sections" # drop unused code/data
# - "-fno-exceptions" # strip C++ exceptions # - "-fno-exceptions" # strip C++ exceptions
# - "-fno-rtti" # strip C++ RTTI # - "-fno-rtti" # strip C++ RTTI
# on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_3
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if using UART for other serial devices
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
########################################################################################## # Status LED for KS-811 is GPIO2
# Status LED for KS-811 is GPIO02 #:########################################################################################:#
##########################################################################################
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO02
inverted: yes inverted: true
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## # Buttons for KS-811-3 are GPIO16, GPIO5, GPIO4
# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04 #:########################################################################################:#
##########################################################################################
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # This pin does not support interrupts so use polling (suppresses warning).
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
@@ -179,7 +197,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
@@ -190,33 +208,38 @@ binary_sensor:
pin: pin:
number: GPIO4 number: GPIO4
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 3: ${switch_3_name}" name: "Button 3: ${switch_3_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_remote_device_command_topic}" topic: "${mqtt_remote_device_command_topic}"
payload: "${mqtt_remote_device_command3}" payload: "${mqtt_remote_device_command3}"
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
##########################################################################################
# Relays for KS-811-3 are GPIO13, GPIO12, GPIO14 # Relays for KS-811-3 are GPIO13, GPIO12, GPIO14
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: Relay_1
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: Relay_3
#:########################################################################################:#
# MQTT:
# Subscribe to fan speed state and mirror it to relay indicator pattern
#:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
- topic: "${mqtt_local_status_topic}" - topic: "${mqtt_local_status_topic}"
+88 -73
View File
@@ -1,60 +1,73 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: BEDROOM 2 LIGHTSWITCH
# BEDROOM 2 LIGHTSWITCH # zorruno.com layout v1.0 2026
#:########################################################################################:#
# VERSIONS:
# V3.5 2025-07-24 YAML tidyups # V3.5 2025-07-24 YAML tidyups
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Double push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Zemismart KS-811 Double push button (KS-811-2)
# # pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
# NOTES #:########################################################################################:#
# - # OPERATION NOTES:
# # - 2 button wall switch controlling 2 relays
########################################################################################## # - Button 1 toggles Relay 1 (Main Lights)
########################################################################################## # - Button 2 toggles Relay 2 (Desk Lights)
# - Status LED on GPIO2
#:########################################################################################:#
# MQTT COMMANDS:
# - None (local relay control only; MQTT package is included for diagnostics/standardization)
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network ONLINE
# - Physical buttons still toggle the relays locally
# - If MQTT is online, any standard MQTT diagnostics from your common package continue to publish
# - HA entities will be unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Physical buttons still toggle the relays locally
# - HA control via API remains available (switch entities still work)
# - MQTT diagnostics/publishes from common_mqtt will fail while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Physical buttons still toggle the relays locally (standalone operation)
# - No HA API access and no MQTT connectivity until network returns
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm2lights" device_name: "esp-bedrm2lights"
friendly_name: "Bedroom 2 Lightswitch (2)" friendly_name: "Bedroom 2 Lightswitch (2)"
description_comment: "Bedroom 2 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Desk Lights (2)" description_comment: "Bedroom 2 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Desk Lights (2) (Layout V1.0)"
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords and Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-bedrm2lights_ip static_ip_address: !secret esp-bedrm2lights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:lightbulb-group"
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls
#mqtt_device_name: "bedroom2-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
# Switch Naming # Switch Naming
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
switch_2_name: "Desk Lights" switch_2_name: "Desk Lights"
#switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -63,6 +76,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -76,23 +90,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -101,50 +115,52 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot: #on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_2 # - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
######################################################################################### # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if using UART for other serial devices
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### # Buttons for KS-811-2 are GPIO16, GPIO5
#:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
@@ -153,7 +169,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: Relay_2
@@ -163,15 +179,16 @@ binary_sensor:
# pin: # pin:
# number: GPIO4 # number: GPIO4
# mode: INPUT # mode: INPUT
# inverted: True # inverted: true
# name: "Button 3: ${switch_3_name}" # name: "Button 3: ${switch_3_name}"
# on_press: # on_press:
# - switch.toggle: Relay_3 # - switch.toggle: Relay_3
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### # Relays for KS-811-2 are GPIO13, GPIO12
#:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -187,6 +204,4 @@ switch:
# - platform: gpio # - platform: gpio
# name: "Relay 3: ${switch_3_name}" # name: "Relay 3: ${switch_3_name}"
# pin: GPIO14 # pin: GPIO14
# id: Relay_3 # id: Relay_3
+145 -119
View File
@@ -1,72 +1,88 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: CEILING FAN - BEDROOM 3
# CEILING FAN - BEDROOM 3 # zorruno.com layout v1.0 2026
# - 3 speed fan using Sonoff IFan02 #:########################################################################################:#
# - Also, single Light Output # VERSIONS:
# V1.0 2025-07-21 First Setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# Controlled by a Sonoff iFan02 (3-speed fan + 1x light relay)
#:########################################################################################:#
# OPERATION NOTES:
# - Fan and light can be controlled via MQTT (local topics below) and via Home Assistant API
# - Fan speed state is tracked in a restored global (speed_value)
# - On boot, the device publishes the restored speed_value to the MQTT speed/state topic for syncing
#:########################################################################################:#
# MQTT COMMANDS:
# Fan speed command:
# ${mqtt_local_command_topic}/speed/set -> 0,1,2,3,+,-
# Fan light command:
# ${mqtt_local_command_topic}/light/set -> ON,OFF
# #
# Controlled by a Sonoff IFan 02 # Fan speed status:
# # ${mqtt_local_status_topic}/speed/state -> 0,1,2,3
# V1.0 - 2025-07-21 First Setup (and replacement of Tasmota) # Fan light status:
# # ${mqtt_local_status_topic}/light/state -> ON,OFF
# NOTES: #:########################################################################################:#
# Command the fan with MQTT # OFFLINE NOTES:
# ${mqtt_local_command_full_topic}/speed/set 1,2,3,0,+,- # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# ${mqtt_local_command_full_topic}/light/set ON,OFF # - Fan and light remain controllable via MQTT local command topics
# Status of the fan is in MQTT # - Status publishes to MQTT still occur (speed and light state)
# ${mqtt_local_command_full_topic}/speed/state 1,2,3,0 # - HA entities are unavailable until HA returns
# ${mqtt_local_command_full_topic}/light/state ON,OFF # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# # - Fan and light remain controllable from Home Assistant via API (fan/light/select)
########################################################################################## # - MQTT local commands will not work and status publishes will fail while MQTT is down
########################################################################################## # c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - If power remains on, relays keep their last driven state
# - If the device reboots while offline, fan/light restore_mode defaults apply (RESTORE_DEFAULT_OFF)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm3ceilingfan" device_name: "esp-bedrm3ceilingfan"
friendly_name: "Bedroom 3 Ceiling Fan" friendly_name: "Bedroom 3 Ceiling Fan"
description_comment: "3 Speed Overhead Ceiling Fan Bedroom 3 :: Sonoff ifan02" description_comment: "3 Speed Overhead Ceiling Fan Bedroom 3 :: Sonoff iFan02 (Layout V1.0)"
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sonoff Technologies.Sonoff ifan02" # Project Details project_name: "Sonoff Technologies.Sonoff iFan02" # Project Details
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords and Secrets
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-bedrm3ceilingfan_ip # unfortunately you can't use substitutions inside secrets names static_ip_address: !secret esp-bedrm3ceilingfan_ip # unfortunately you can't use substitutions inside secrets names
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls # MQTT LOCAL Controls
mqtt_device_name: "bedroom3-ceilingfan" mqtt_device_name: "bedroom3-ceilingfan"
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic used 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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic used to view status locally without HA
# MQTT REMOTE Controls
# Button Naming & Icons
# Switch/Relay Naming & Icons # Switch/Relay Naming & Icons
#relay_icon: "mdi:lightbulb-group" light_1_name: "Fan Light"
light_1_name: "Fan Light" switch_2_name: "Fan 2 Relay"
switch_2_name: "Fan 2 Relay" switch_3_name: "Fan 3 Relay"
switch_3_name: "Fan 3 Relay" switch_4_name: "Fan 4 Relay"
switch_4_name: "Fan 4 Relay"
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -75,6 +91,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -88,80 +105,76 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
on_boot: # This weird toggle thing makes sure the states get restored on reboot project:
priority : -100 name: "${project_name}"
version: "${project_version}"
on_boot: # Publish restored speed on boot so other systems can sync
priority: -100
then: then:
- delay: 200ms - delay: 200ms
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
# 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 # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m # Sonoff iFan02
restore_from_flash: True # restore some values on reboot restore_from_flash: true # restore some values on reboot
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
mdns: mdns:
disabled: True # Disabling will make the build file smaller (and it is still available via static IP) disabled: true # Disabling will make the build file smaller (and it is still available via static IP)
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES:
########################################################################################## # https://esphome.io/guides/automations.html#global-variables
#:########################################################################################:#
globals: globals:
- id: speed_value - id: speed_value
type: int type: int
restore_value: yes restore_value: true
initial_value: '0' initial_value: "0"
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" # INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Light control # Light control
@@ -169,12 +182,13 @@ mqtt:
payload: "ON" payload: "ON"
then: then:
- light.turn_on: ifan02_light - light.turn_on: ifan02_light
- topic: "${mqtt_local_command_topic}/light/set" - topic: "${mqtt_local_command_topic}/light/set"
payload: "OFF" payload: "OFF"
then: then:
- light.turn_off: ifan02_light - light.turn_off: ifan02_light
# Fan speed control (03) + ramp up/down (+ / -) # Fan speed control (0-3) plus ramp up/down (+ / -)
- topic: "${mqtt_local_command_topic}/speed/set" - topic: "${mqtt_local_command_topic}/speed/set"
then: then:
# 1) Compute new speed_value based on payload # 1) Compute new speed_value based on payload
@@ -199,21 +213,21 @@ mqtt:
# 2) Drive the fan based on the new value # 2) Drive the fan based on the new value
- if: - if:
condition: condition:
lambda: 'return id(speed_value) == 0;' lambda: "return id(speed_value) == 0;"
then: then:
- fan.turn_off: ifan02_fan - fan.turn_off: ifan02_fan
else: else:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: !lambda 'return id(speed_value);' speed: !lambda "return id(speed_value);"
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #
# Sonoff ifan02 has relays, but they don't need to be shown in HA because # Sonoff iFan02 has relays, but they do not need to be shown in HA because
# the speed of the fan is the important part (and combinations of the relays give that) # the speed of the fan is the important part (and combinations of the relays give that)
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "${switch_3_name}" name: "${switch_3_name}"
@@ -221,12 +235,14 @@ switch:
id: fan3sw id: fan3sw
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
- platform: gpio - platform: gpio
name: "${switch_2_name}" name: "${switch_2_name}"
pin: GPIO5 pin: GPIO5
id: fan2sw id: fan2sw
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
- platform: gpio - platform: gpio
name: "${switch_4_name}" name: "${switch_4_name}"
pin: GPIO15 pin: GPIO15
@@ -234,14 +250,14 @@ switch:
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
internal: true internal: true
########################################################################################## #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
########################################################################################## #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Bedroom 2 Fan Speed" name: "Bedroom 3 Fan Speed"
id: bedroom2_fan_speed_select id: bedroom3_fan_speed_select
options: options:
- "Off" - "Off"
- "Low" - "Low"
@@ -264,6 +280,7 @@ select:
- lambda: |- - lambda: |-
id(speed_value) = 0; id(speed_value) = 0;
- fan.turn_off: ifan02_fan - fan.turn_off: ifan02_fan
# LOW (1) # LOW (1)
- if: - if:
condition: condition:
@@ -274,6 +291,7 @@ select:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: 1 speed: 1
# MEDIUM (2) # MEDIUM (2)
- if: - if:
condition: condition:
@@ -284,6 +302,7 @@ select:
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: 2 speed: 2
# HIGH (3) # HIGH (3)
- if: - if:
condition: condition:
@@ -295,13 +314,17 @@ select:
id: ifan02_fan id: ifan02_fan
speed: 3 speed: 3
################################################################################ #:########################################################################################:#
# TEMPLATE OUTPUTS: drive the real relays when the states change # OUTPUT COMPONENT:
################################################################################ # https://esphome.io/components/output/
#
# Template output drives the real relays when the fan output state changes
#:########################################################################################:#
output: output:
- platform: gpio - platform: gpio
pin: GPIO12 pin: GPIO12
id: lightrelay id: lightrelay
- platform: template - platform: template
type: float type: float
id: fan_decode id: fan_decode
@@ -328,17 +351,17 @@ output:
id(fan4sw).turn_on(); id(fan4sw).turn_on();
} }
########################################################################################## #:########################################################################################:#
# LIGHT COMPONENT # LIGHT COMPONENT:
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: binary - platform: binary
name: "${light_1_name}" name: "${light_1_name}"
output: lightrelay output: lightrelay
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
id: ifan02_light id: ifan02_light
# publish status updates when the light turns on/off: # Publish status updates when the light turns on/off
on_turn_on: on_turn_on:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state" topic: "${mqtt_local_status_topic}/light/state"
@@ -348,10 +371,10 @@ light:
topic: "${mqtt_local_status_topic}/light/state" topic: "${mqtt_local_status_topic}/light/state"
payload: "OFF" payload: "OFF"
########################################################################################## #:########################################################################################:#
# FAN COMPONENT # FAN COMPONENT:
# https://esphome.io/components/fan/index.html # https://esphome.io/components/fan/index.html
########################################################################################## #:########################################################################################:#
fan: fan:
- platform: speed - platform: speed
output: fan_decode output: fan_decode
@@ -359,28 +382,31 @@ fan:
id: ifan02_fan id: ifan02_fan
speed_count: 3 speed_count: 3
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
# whenever you explicitly set a speed (13):
# Whenever you explicitly set a speed (1-3)
on_speed_set: on_speed_set:
- lambda: |- - lambda: |-
id(speed_value) = x; id(speed_value) = x;
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
# whenever the fan goes fully off:
# Whenever the fan goes fully off
on_turn_off: on_turn_off:
- lambda: |- - lambda: |-
id(speed_value) = 0; id(speed_value) = 0;
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: "0" payload: "0"
# whenever the fan goes off→on (e.g. via HAs Fan switch):
# Whenever the fan goes off->on (eg via HA fan switch)
on_turn_on: on_turn_on:
- lambda: |- - lambda: |-
// bump 01 if we were off // bump 0->1 if we were off
if (id(speed_value) == 0) id(speed_value) = 1; if (id(speed_value) == 0) id(speed_value) = 1;
- fan.turn_on: - fan.turn_on:
id: ifan02_fan id: ifan02_fan
speed: !lambda 'return id(speed_value);' speed: !lambda "return id(speed_value);"
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state" topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));' payload: !lambda "return to_string(id(speed_value));"
+127 -95
View File
@@ -1,76 +1,103 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: BEDROOM 3 FAN SWITCH (WALL SWITCH)
# BEDROOM 3 FAN SWITCH # zorruno.com layout v1.0 2026
#:########################################################################################:#
# VERSIONS:
# V1.0 2025-07-23 First Setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# Zemismart KS-811 Triple push button (KS-811-3)
# pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Wall switch for Bedroom 3 ceiling fan
# - 3 physical buttons: Speed Up (Button 1), Speed Down (Button 2), Fan Off (Button 3)
# - Buttons publish MQTT commands to the fan speed topic (remote control)
# - Device also subscribes to the fan speed state topic and drives the local KS-811 relays
# as a visual indicator of current speed (0-3)
#:########################################################################################:#
# MQTT COMMANDS:
# Remote fan speed command topic:
# ${mqtt_remote_device_command_topic}
# Payloads sent by buttons:
# Button 1 (Speed Up) -> "+"
# Button 2 (Speed Down) -> "-"
# Button 3 (Fan Off) -> "0"
# #
# Controlled by a Zemismart KS-811 Triple push button # Subscribed speed state topic (drives relay indicators):
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # ${mqtt_local_status_topic} -> 0,1,2,3
# #:########################################################################################:#
# V1.0 - 2025-07-23 First Setup (and replacement of Tasmota) # OFFLINE NOTES:
# # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# NOTES # - Buttons still publish MQTT commands directly to the fan
# - Switch for Ceiling Fan # - Relay indicator sync still works (subscribed MQTT state updates)
# - 3 Switches, Up, Down and Off # - HA entities for this switch device are unavailable until HA returns
# - Remote commands to the fan ${mqtt_remote_command_full_topic}/speed/set 1,2,3,0,+,- # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# # - Buttons cannot command the fan (no MQTT broker available)
########################################################################################## # - Relay indicator sync will not update from fan speed state
########################################################################################## # - HA can still see/control only this device entities, but the fan control path is MQTT
# c) Entire WiFi/Network OFFLINE
# - No MQTT publish/subscribe and no HA API connectivity
# - Buttons will do nothing to the fan (no transport)
# - Relay indicators will remain in their last state until connectivity returns (or reboot)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm3fanswitch" device_name: "esp-bedrm3fanswitch"
friendly_name: "Bedroom 3 Fan Wall Switch (3)" friendly_name: "Bedroom 3 Fan Wall Switch (3)"
description_comment: "Switch for Bedroom 3 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3)" description_comment: "Switch for Bedroom 3 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3) (Layout V1.0)"
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
#entity_prefix: "Main Bathroom" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
# Passwords # Project Naming
project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
#entity_prefix: "Main Bathroom" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
# Passwords and Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-bedrm3fanswitch_ip static_ip_address: !secret esp-bedrm3fanswitch_ip
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:heating-coil"
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls # MQTT LOCAL Controls
#mqtt_device_name: "bedroom2-ceilingfan-switch" #mqtt_device_name: "bedroom3-ceilingfan-switch"
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA #mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic used 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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic used to view status locally without HA
# MQTT REMOTE Controls # MQTT REMOTE Controls
mqtt_remote_device_name: "bedroom3-ceilingfan" mqtt_remote_device_name: "bedroom3-ceilingfan"
mqtt_remote_device_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set" mqtt_remote_device_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set"
mqtt_remote_device_command1: "+" mqtt_remote_device_command1: "+"
mqtt_remote_device_command2: "-" mqtt_remote_device_command2: "-"
mqtt_remote_device_command3: "0" mqtt_remote_device_command3: "0"
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
# Button Naming & Icons
# Switch/Relay Naming & Icons # Fan speed status topic (used to sync relay indicators)
#relay_icon: "mdi:heating-coil" mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state"
switch_1_name: "Fan Speed Up" # This is virtual only, no power connected to 1st relay
switch_2_name: "Fan Speed Down" # This is virtual only, no power connected to 2nd relay
switch_3_name: "Fan Off" # This is virtual only, no power connected to 3rd relay
########################################################################################## # Switch/Relay Naming and Icons
switch_1_name: "Fan Speed Up" # Virtual intent only, no load connected to relay 1
switch_2_name: "Fan Speed Down" # Virtual intent only, no load connected to relay 2
switch_3_name: "Fan Off" # Virtual intent only, no load connected to relay 3
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -79,6 +106,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -92,85 +120,84 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: ${device_name} name: "${device_name}"
friendly_name: ${friendly_name} friendly_name: "${friendly_name}"
comment: ${description_comment} #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the ESPHome page in HA
area: ${device_area} area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
platformio_options: platformio_options:
build_flags: build_flags:
- "-Os" # optimize for size - "-Os" # optimize for size
- "-Wl,--gc-sections" # drop unused code/data - "-Wl,--gc-sections" # drop unused code/data
#- "-fno-exceptions" # strip C++ exceptions #- "-fno-exceptions" # strip C++ exceptions
#- "-fno-rtti" # strip C++ RTTI #- "-fno-rtti" # strip C++ RTTI
# on_boot: # on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_3 # - switch.turn_on: Relay_3
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if using UART for other serial devices
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
########################################################################################## # Status LED for KS-811 is GPIO2
# Status LED for KS-811 is GPIO02 #:########################################################################################:#
##########################################################################################
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO2
inverted: yes inverted: true
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## # Buttons for KS-811-3 are GPIO16, GPIO5, GPIO4
# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04 #:########################################################################################:#
##########################################################################################
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
@@ -181,7 +208,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
@@ -192,33 +219,38 @@ binary_sensor:
pin: pin:
number: GPIO4 number: GPIO4
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 3: ${switch_3_name}" name: "Button 3: ${switch_3_name}"
on_press: on_press:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_remote_device_command_topic}" topic: "${mqtt_remote_device_command_topic}"
payload: "${mqtt_remote_device_command3}" payload: "${mqtt_remote_device_command3}"
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
##########################################################################################
# Relays for KS-811-3 are GPIO13, GPIO12, GPIO14 # Relays for KS-811-3 are GPIO13, GPIO12, GPIO14
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: Relay_1
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: Relay_3
#:########################################################################################:#
# MQTT:
# Subscribe to fan speed state and mirror it to relay indicator pattern
#:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
- topic: "${mqtt_local_status_topic}" - topic: "${mqtt_local_status_topic}"
+124 -92
View File
@@ -1,73 +1,99 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: BEDROOM 3 LIGHTSWITCH
# BEDROOM 3 LIGHTSWITCH # zorruno.com layout v1.0 2026
#:########################################################################################:#
# VERSIONS:
# V3.5 2025-07-24 YAML tidyups # V3.5 2025-07-24 YAML tidyups
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Double push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Zemismart KS-811 Double push button (KS-811-2)
# pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Virtual 2-button wall switch used to control Bedroom 3 ceiling fan light and to force "all off"
# - Button 1 toggles the iFan02 light (sends MQTT ON/OFF), using Relay 1 as the local state mirror
# - Button 2 forces "All Lights Off" (turns iFan02 light OFF and sets fan speed to 0), and turns Relay 2 OFF
# - Relay 1 and Relay 2 are used as local state indicators (no load connected)
# - A short cooldown is used on Button 1 to prevent repeated MQTT publishes
#:########################################################################################:#
# MQTT COMMANDS:
# Remote fan light command:
# ${mqtt_remote_device_command_topic1} -> ON,OFF
# Remote fan speed command (used by All Off):
# ${mqtt_remote_device_command_topic2} -> 0
# #
# NOTES # Remote fan light status (subscribed to keep Relay 1 in sync):
# - # ${mqtt_remote_status_topic1} -> ON,OFF
# #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Buttons still publish MQTT commands directly to the remote iFan02 (light and all-off actions)
# - Relay 1 state mirror still updates from subscribed remote light status topic
# - HA entities for this switch device are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Buttons cannot control the remote iFan02 (control path is MQTT)
# - Relay 1 will not mirror the remote light status while MQTT is down
# - HA can still see/control the local indicator relays, but those do not affect the fan without MQTT
# c) Entire WiFi/Network OFFLINE
# - No MQTT publish/subscribe and no HA API connectivity
# - Buttons will not control the remote iFan02
# - Local indicator relays remain in their last state until connectivity returns (or reboot)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-bedrm3lights" device_name: "esp-bedrm3lights"
friendly_name: "Bedroom 3 Lightswitch (2)" friendly_name: "Bedroom 3 Lightswitch (2)"
description_comment: "Bedroom 3 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1-Virtual), All Lights Off (2-Virtual)" description_comment: "Bedroom 3 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1-Virtual), All Lights Off (2-Virtual) (Layout V1.0)"
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords and Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-bedrm3lights_ip static_ip_address: !secret esp-bedrm3lights_ip
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:lightbulb-group"
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls # MQTT LOCAL Controls
mqtt_device_name: "bedroom3-lightswitch" mqtt_device_name: "bedroom3-lightswitch"
#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 REMOTE Controls # MQTT REMOTE Controls (Bedroom 3 iFan02)
mqtt_remote_device_name: "bedroom3-ceilingfan" mqtt_remote_device_name: "bedroom3-ceilingfan"
# Remote Light
mqtt_remote_device_command_topic1: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/light/set" mqtt_remote_device_command_topic1: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/light/set"
mqtt_remote_status_topic1: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/light/state" # Topic we will use to view status of remote without HA mqtt_remote_status_topic1: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/light/state"
mqtt_remote_device_command_ON: "ON" mqtt_remote_device_command_ON: "ON"
mqtt_remote_device_command_OFF: "OFF" mqtt_remote_device_command_OFF: "OFF"
mqtt_remote_device_command_topic2: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set"
#mqtt_remote_device_command1: "+"
#mqtt_remote_device_command2: "-"
mqtt_remote_device_command_0: "0"
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
# Button Naming & Icons # Remote Fan Speed (used for All Off)
mqtt_remote_device_command_topic2: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set"
mqtt_remote_device_command_0: "0"
# Switch Naming # Switch Naming
switch_1_name: "Main Lights" # Nothing physically connected to this output. Lights are physically on IFan02 light output switch_1_name: "Main Lights" # Nothing physically connected to this output (ifan02 light is the real load)
switch_2_name: "All Lights Off" # Nothing physically connected to this output switch_2_name: "All Lights Off" # Nothing physically connected to this output
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -76,6 +102,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -89,76 +116,80 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the ESPHome page in HA
area: "${device_area}" area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot: #on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_2 # - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
######################################################################################### # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}" # INFO 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if using UART for other serial devices
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
#GLobals #:########################################################################################:#
# GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html#global-variables
#:########################################################################################:#
globals: globals:
- id: btn1_last_ms - id: btn1_last_ms
type: uint32_t type: uint32_t
restore_value: no restore_value: false
initial_value: '0' initial_value: "0"
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### # Buttons for KS-811-2 are GPIO16, GPIO5
#:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
id: button_1 id: button_1
@@ -166,15 +197,15 @@ binary_sensor:
number: GPIO16 number: GPIO16
mode: mode:
input: true input: true
pullup: false # set to true if you need an internal pull-up pullup: false # set to true if you need an internal pull-up
inverted: true inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
filters: filters:
- delayed_on: 30ms - delayed_on: 30ms
- delayed_off: 30ms - delayed_off: 30ms
on_press: on_press:
# cooldown: 250 ms between publishes # Cooldown: 250ms between publishes
- if: - if:
condition: condition:
lambda: |- lambda: |-
@@ -202,25 +233,26 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.turn_off: Relay_2 - switch.turn_off: Relay_2
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_remote_device_command_topic1}" topic: "${mqtt_remote_device_command_topic1}"
payload: "${mqtt_remote_device_command_OFF}" payload: "${mqtt_remote_device_command_OFF}"
qos: 0 qos: 0
retain: false retain: false
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_remote_device_command_topic2}" topic: "${mqtt_remote_device_command_topic2}"
payload: "${mqtt_remote_device_command_0}" payload: "${mqtt_remote_device_command_0}"
qos: 0 qos: 0
retain: false retain: false
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### # Relays for KS-811-2 are GPIO13, GPIO12 (no load connected; used as indicators)
#:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -232,19 +264,19 @@ switch:
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
#:########################################################################################:#
########################################################################################## # MQTT:
# MQTT COMMANDS
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Switch control. Turn on/off relay if remote device switched on/off # Mirror remote light state onto Relay 1 indicator
- topic: "${mqtt_remote_status_topic1}" - topic: "${mqtt_remote_status_topic1}"
payload: "${mqtt_remote_device_command_ON}" payload: "${mqtt_remote_device_command_ON}"
then: then:
- switch.turn_on: Relay_1 - switch.turn_on: Relay_1
- topic: "${mqtt_remote_status_topic1}" - topic: "${mqtt_remote_status_topic1}"
payload: "${mqtt_remote_device_command_OFF}" payload: "${mqtt_remote_device_command_OFF}"
then: then:
- switch.turn_off: Relay_1 - switch.turn_off: Relay_1
+206 -188
View File
@@ -1,19 +1,28 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: BREAKFAST BAR LEDS (LOUNGE)
# Title: BREAKFAST BAR LEDS (Lounge) # zorruno.com layout v1.1 2026
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-loungebookshelfleds.yaml #:########################################################################################:#
# # REPO:
# v2.0 - 2025-09-15 A bunch of fixes and made it more standard across my devices # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-breakfastbarleds.yaml
# v1.0 - 2025-08-17 First setup (and replacement of Tasmota) #:########################################################################################:#
# VERSIONS:
# V2.0 2025-09-15 A bunch of fixes and made it more standard across my devices
# V1.0 2025-08-17 First setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# Magishome LED controller single channel (ESP8266, NOT the later ones with BL602)
# https://devices.esphome.io/devices/MagicHome-ZJ-WFMN-C-Single-Color
# #
# ------------------------------------------ # DEVICE GPIO (Magichome ESP8266)
# OPERATION (as of v2.0) # - GPIO02 Blue LED (used for ESPHome status) - I think... can't see the board
# ------------------------------------------ # - GPIO12 MOSFET output (0 V when switched)
# 1. General-purpose LED controller. #:########################################################################################:#
# OPERATION NOTES:
# 1. General-purpose LED controller.
# 2. Designed for the Sinilink XY-WFMS board with a MOSFET output (claimed 5A, 5-36 V DC), but will suit similar mosfet boards. # 2. Designed for the Sinilink XY-WFMS board with a MOSFET output (claimed 5A, 5-36 V DC), but will suit similar mosfet boards.
# 3. (In SUBSTITUTIONS) setting for MAX % output to extend LED life (ie can ensure it is only ever 95%) # 3. (SUBSTITUTIONS) setting for MAX % output to extend LED life (e.g. ensure it is only ever 95%)
# 4. (In SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker. # 4. (SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
# 5. (In SUBSTITUTIONS) PWM frequency is set to 1kHz by default. You can increase it, but higher values caused # 5. (SUBSTITUTIONS) PWM frequency is set to 1kHz by default. You can increase it, but higher values caused
# resets on Sinilink device. On ESP32 you can run much higher (~40 kHz). # resets on Sinilink device. On ESP32 you can run much higher (~40 kHz).
# 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but could be. # 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but could be.
# With a 1 MB flash, space is tight and only minimal optimisation has been done so far. # With a 1 MB flash, space is tight and only minimal optimisation has been done so far.
@@ -32,42 +41,57 @@
# - Normal On/Off switch (quick ramp up/down, up to the level of previous brightness) # - Normal On/Off switch (quick ramp up/down, up to the level of previous brightness)
# - Fade up/down times (0-60s) # - Fade up/down times (0-60s)
# - Output % (pre-gamma) and PWM % (post-gamma) # - Output % (pre-gamma) and PWM % (post-gamma)
# - Output Set (1-100, respects min/max). This also changes with other output so reflects value. # - Output Set (1-100, respects min/max). This also changes with other output so reflects value.
# - Many device diagnostics (from the included 'diagnostics' package) # - Many device diagnostics (from the included 'diagnostics' package)
# - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit) # - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit)
########################################################################################## #:########################################################################################:#
########################################################################################## # MQTT COMMANDS:
# Hardware: Magishome LED controller single channel (ESP8266, NOT the later ones with BL602) # Local MQTT light control:
# https://devices.esphome.io/devices/MagicHome-ZJ-WFMN-C-Single-Color # - ${mqtt_local_command_topic}/light/set -> ON,OFF
# ------------------------------------------ #
# DEVICE GPIO (Magichome ESP8266) # Local MQTT light status:
# ------------------------------------------ # - ${mqtt_local_status_topic}/light/state -> ON,OFF
# GPIO02 Blue LED (used for ESPHome status) - I think... can't see the board #:########################################################################################:#
# GPIO12 MOSFET output (0 V when switched) # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
########################################################################################## # - Device remains controllable via MQTT local command topics
# - Status publishes to MQTT still occur (light state)
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable from Home Assistant via API (light/switch/buttons/select/numbers)
# - MQTT local commands will not work and status publishes will fail while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - SNTP not needed (no timeclocks; loss of network does not affect timing)
# - If power remains on, the controller continues running at the last state (including any running scripts)
# - If the device reboots while offline, restart behavior depends on the stored restart_mode and restore globals
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-breakfastbarleds" # yaml file should be device_name.yaml device_name: "esp-breakfastbarleds" # yaml file should be device_name.yaml
friendly_name: "Breakfast Bar LEDs" friendly_name: "Breakfast Bar LEDs"
description_comment: "LED Strip under the breakfast bar, upstairs lounge :: Magichome ESP8266" description_comment: "LED Strip under the breakfast bar, upstairs lounge :: Magichome ESP8266 (Layout V1.1)"
device_area: "Lounge" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Lounge" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Magichome Single Colour V1.1 LED Controller.Generic ESP8266" # Project details. Manufacturer before the dot, device after the dot. project_name: "Magichome Single Colour V1.1 LED Controller.Generic ESP8266" # Manufacturer before the dot, device after the dot.
project_version: "v2.0" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version project_version: "v2.0" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names) # Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-breakfastbarleds_ip # CHANGE THIS static_ip_address: !secret esp-breakfastbarleds_ip
# MQTT LOCAL Controls (This is just my local method of controlling via MQTT, I also use the built in method) # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT LOCAL Controls (This is just my local method of controlling via MQTT, I also use the built in method)
mqtt_local_device_name: "lounge-breakfastbarleds" mqtt_local_device_name: "lounge-breakfastbarleds"
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
@@ -77,24 +101,24 @@ substitutions:
mqtt_local_device_command_OFF: "OFF" mqtt_local_device_command_OFF: "OFF"
# Device Specific Settings # Device Specific Settings
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
update_interval: "20s" # Update time for general sensors, etc. update_interval: "20s" # Update time for general sensors, etc.
led_gamma: "1.2" # Gamma from 1.2-3 is sensible to normalise the LED fading vs PWM led_gamma: "1.2" # Gamma from 1.2-3 is sensible to normalise the LED fading vs PWM
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics
max_on_default_hours: "24" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off max_on_default_hours: "24" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off
pwm_frequency: "1000" # PWM output Frequency in Hz. High enough to avoid audible/visible artifacts pwm_frequency: "1000" # PWM output Frequency in Hz. High enough to avoid audible/visible artifacts
# Device Specific GPIO (so we can easily update for other devices) # Device Specific GPIO (so we can easily update for other devices)
device_status_led: GPIO02 device_status_led: GPIO02
device_mosfet_out: GPIO12 device_mosfet_out: GPIO12
device_usr_button: GPIO04 # if no button, this is just a fake/safeish choice so it compiles with the generic yaml device_usr_button: GPIO04 # if no button, this is just a fake/safeish choice so it compiles with the generic yaml
device_fading_led: GPIO13 # if no LED, this is just a fake/safeish choice so it compiles with the generic yaml device_fading_led: GPIO13 # if no LED, this is just a fake/safeish choice so it compiles with the generic yaml
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -103,6 +127,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -116,22 +141,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome CORE CONFIGURATION # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -179,25 +205,11 @@ esphome:
# Boot complete: allow OFF handlers again # Boot complete: allow OFF handlers again
- lambda: 'id(booting) = false;' - lambda: 'id(booting) = false;'
# NEW: force indicator OFF after boot logic #:########################################################################################:#
# (Removed: output.turn_off: green_led_out) # ESP PLATFORM AND FRAMEWORK:
# Only if you want to play with build flags...
# platformio_options:
# build_unflags:
# - -flto
# build_flags:
# - -fno-lto
# - -Wl,--gc-sections
# - -ffunction-sections
# - -fdata-sections
# - -DNDEBUG
##########################################################################################
# ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp8266.html # https://esphome.io/components/esp8266.html
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
restore_from_flash: true # restore some values on reboot restore_from_flash: true # restore some values on reboot
@@ -208,118 +220,128 @@ mdns:
preferences: preferences:
flash_write_interval: 2min # enough time to update values for reboots, but not enough to wear flash flash_write_interval: 2min # enough time to update values for reboots, but not enough to wear flash
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES:
# https://esphome.io/components/globals.html # https://esphome.io/components/globals.html
########################################################################################## #:########################################################################################:#
globals: globals:
# Minimum Brightness % for LEDs (will switch off if <=) # Minimum Brightness % for LEDs (will switch off if <=)
- id: min_brightness_pct - id: min_brightness_pct
type: int type: int
restore_value: true restore_value: true
initial_value: "${minimum_led_output}" # start/finish at X% initial_value: "${minimum_led_output}"
# Maximum Brightness % for LEDs (should never go beyond this) # Maximum Brightness % for LEDs (should never go beyond this)
- id: max_brightness_pct - id: max_brightness_pct
type: int type: int
restore_value: false restore_value: false
initial_value: "${maximum_led_output}" # hard cap; never exceed this initial_value: "${maximum_led_output}"
# The maximum time the lights will stay on, in hours. Just in case they are left on. 0 = forever
# The maximum time the lights will stay on, in hours. 0 = forever
- id: max_on_hours - id: max_on_hours
type: int type: int
restore_value: true restore_value: true
initial_value: "${max_on_default_hours}" initial_value: "${max_on_default_hours}"
# Compile time Gamma # Compile time Gamma
- id: led_gamma_f - id: led_gamma_f
type: float type: float
restore_value: false restore_value: false
initial_value: ${led_gamma} # <-- numeric at compile time initial_value: ${led_gamma} # numeric at compile time
# Default Fading Up Time (Selectable and will be retained) # Default Fading Up Time (Selectable and will be retained)
- id: ramp_up_ms # fade-in when turned ON - id: ramp_up_ms
type: int type: int
restore_value: true restore_value: true
initial_value: '5000' # 5 s initial_value: "5000" # 5 s
# Default Fading Down Time (Selectable and will be retained) # Default Fading Down Time (Selectable and will be retained)
- id: ramp_down_ms # fade-out when turned OFF - id: ramp_down_ms
type: int type: int
restore_value: true restore_value: true
initial_value: '10000' # 10 s initial_value: "10000" # 10 s
# Action on Restart. (0=Fade full, 1=Restore brightness, 2=Remain off) # Action on Restart. (0=Fade full, 1=Restore brightness, 2=Remain off)
- id: restart_mode - id: restart_mode
type: int type: int
restore_value: true restore_value: true
initial_value: '0' # default = Fade Up to Full (so can be deployed with no other setup) initial_value: "0" # default = Fade Up to Full
# Determine last fade direction. # Determine last fade direction.
# true when you asked the light to end up ON (Ramp Up)
# false when you asked the light to end up OFF (Ramp Down)
- id: ramp_switch_target_on - id: ramp_switch_target_on
type: bool type: bool
restore_value: true restore_value: true
initial_value: 'false' initial_value: "false"
# Prevent jitter when adjusting the slider # Prevent jitter when adjusting the slider
- id: suppress_slider_sync - id: suppress_slider_sync
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
# actual 0..100 seen last time, for restart
- id: last_brightness_pct # Actual 0..100 seen last time, for restart
- id: last_brightness_pct
type: float type: float
restore_value: true restore_value: true
initial_value: '0.0' initial_value: "0.0"
# last published "Output Set (0-100)" integer
# Last published "Output Set (0-100)" integer
- id: last_set_pos - id: last_set_pos
type: int type: int
restore_value: false restore_value: false
initial_value: '-1' initial_value: "-1"
# helper to keep blink time == transition time
# Helper to keep blink time == transition time
- id: last_ramp_ms - id: last_ramp_ms
type: int type: int
restore_value: false restore_value: false
initial_value: '0' initial_value: "0"
# target for "Restore Brightness" scripted ramp
# Target for "Restore Brightness" scripted ramp
- id: restore_target_pct - id: restore_target_pct
type: float type: float
restore_value: false restore_value: false
initial_value: '0.0' initial_value: "0.0"
# true while a scripted ramp is in progress (to limit flash writes)
# True while a scripted ramp is in progress (to limit flash writes)
- id: is_ramping - id: is_ramping
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
# guards OFF persistence during startup caused by restore_mode: ALWAYS_OFF
# Guards OFF persistence during startup caused by restore_mode: RESTORE_DEFAULT_OFF
- id: booting - id: booting
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'true' initial_value: "true"
# true only while we are performing a ramp-down that briefly turns the light ON to hit the floor
# True only while we are performing a ramp-down that briefly turns the light ON to hit the floor
- id: ramping_for_off - id: ramping_for_off
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
########################################################################################## #:########################################################################################:#
# LOGGER COMPONENT # LOGGER COMPONENT:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
# Logs all log messages through the serial port and through MQTT topics. #:########################################################################################:#
##########################################################################################
logger: logger:
level: "${log_level}" # INFO Level suggested, or DEBUG for testing level: "${log_level}"
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) baud_rate: 0 # set to 0 for no logging via UART
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: ${device_status_led} number: ${device_status_led}
inverted: true inverted: true
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Light control to ramp up # Light control to ramp up
@@ -327,16 +349,17 @@ mqtt:
payload: "${mqtt_local_device_command_ON}" payload: "${mqtt_local_device_command_ON}"
then: then:
- switch.turn_on: mosfet_ramp_switch - switch.turn_on: mosfet_ramp_switch
# Light control to ramp down # Light control to ramp down
- topic: "${mqtt_local_command_topic}/light/set" - topic: "${mqtt_local_command_topic}/light/set"
payload: "${mqtt_local_device_command_OFF}" payload: "${mqtt_local_device_command_OFF}"
then: then:
- switch.turn_off: mosfet_ramp_switch - switch.turn_off: mosfet_ramp_switch
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
switch: switch:
# Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce) # Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce)
- platform: template - platform: template
@@ -356,10 +379,10 @@ switch:
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
button: button:
# Start ramping UP (from current level) # Start ramping UP (from current level)
- platform: template - platform: template
@@ -369,7 +392,7 @@ button:
on_press: on_press:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
- script.stop: ramp_off_script - script.stop: ramp_off_script
- script.execute: ramp_on_script - script.execute: ramp_on_script
@@ -381,7 +404,7 @@ button:
on_press: on_press:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
@@ -391,7 +414,6 @@ button:
name: "${friendly_name} Fade Stop" name: "${friendly_name} Fade Stop"
icon: mdi:pause icon: mdi:pause
on_press: on_press:
# Stop any pending scripts (and their delayed actions)
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.stop: ramp_off_script - script.stop: ramp_off_script
- lambda: |- - lambda: |-
@@ -399,7 +421,7 @@ button:
id(ramping_for_off) = false; id(ramping_for_off) = false;
id(is_ramping) = false; id(is_ramping) = false;
// Freeze the light at its *current* level by overwriting the transition // Freeze the light at its current level by overwriting the transition
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
auto call = id(mosfet_leds).make_call(); auto call = id(mosfet_leds).make_call();
@@ -415,12 +437,10 @@ button:
id(last_brightness_pct) = pct; id(last_brightness_pct) = pct;
} }
#:########################################################################################:#
# SELECT COMPONENT:
#########################################################################################
# SELECT COMPONENT
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
######################################################################################### #:########################################################################################:#
select: select:
- platform: template - platform: template
id: restart_action id: restart_action
@@ -442,10 +462,10 @@ select:
id(restart_mode) = 2; id(restart_mode) = 2;
} }
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
id: btn_gpio12 id: btn_gpio12
@@ -467,21 +487,21 @@ binary_sensor:
# Target is currently ON -> press should go OFF (start ramp-down) # Target is currently ON -> press should go OFF (start ramp-down)
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
else: else:
# Target is currently OFF -> press should go ON (start ramp-up) # Target is currently OFF -> press should go ON (start ramp-up)
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
- script.stop: ramp_off_script - script.stop: ramp_off_script
- script.execute: ramp_on_script - script.execute: ramp_on_script
########################################################################################## #:########################################################################################:#
# SENSOR COMPONENT # SENSOR COMPONENT:
# https://esphome.io/components/sensor/ # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
id: mosfet_output_pct id: mosfet_output_pct
@@ -489,7 +509,7 @@ sensor:
unit_of_measurement: "%" unit_of_measurement: "%"
icon: mdi:percent icon: mdi:percent
accuracy_decimals: 0 accuracy_decimals: 0
update_interval: 2s # consider 200ms if you want fewer updates update_interval: 2s
lambda: |- lambda: |-
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f; return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f;
@@ -530,28 +550,26 @@ sensor:
if (pwm > 1.0f) pwm = 1.0f; if (pwm > 1.0f) pwm = 1.0f;
return pwm * 100.0f; return pwm * 100.0f;
########################################################################################## #:########################################################################################:#
# OUTPUT COMPONENT # OUTPUT COMPONENT:
# https://esphome.io/components/light/index.html # https://esphome.io/components/output/
########################################################################################## #:########################################################################################:#
# An OUTPUT can be binary (0,1) or float, which is any value between 0 and 1.
# PWM Outputs such as "ledc" are float. https://esphome.io/components/output/ledc.html
##########################################################################################
output: output:
- platform: esp8266_pwm - platform: esp8266_pwm
id: mosfet_pwm id: mosfet_pwm
pin: ${device_mosfet_out} pin: ${device_mosfet_out}
frequency: ${pwm_frequency} frequency: ${pwm_frequency}
- platform: gpio - platform: gpio
id: green_led_out # Green LED id: green_led_out # Green LED
pin: pin:
number: ${device_fading_led} number: ${device_fading_led}
inverted: false inverted: false
########################################################################################## #:########################################################################################:#
# LIGHT COMPONENT # LIGHT COMPONENT:
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: monochromatic - platform: monochromatic
id: mosfet_leds id: mosfet_leds
@@ -582,7 +600,7 @@ light:
- script.execute: max_on_watchdog - script.execute: max_on_watchdog
# OFF: publish state, track intent, clear watchdog, and persist OFF so Mode 1 will not restore # OFF: publish state, track intent, clear watchdog, and persist OFF so Mode 1 will not restore
# Guarded by booting flag so the automatic OFF at boot from ALWAYS_OFF does not zero persistence. # Guarded by booting flag so the automatic OFF at boot from RESTORE_DEFAULT_OFF does not zero persistence.
on_turn_off: on_turn_off:
- output.turn_off: green_led_out - output.turn_off: green_led_out
- if: - if:
@@ -607,18 +625,17 @@ light:
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (!cv.is_on()) return; if (!cv.is_on()) return;
const float b = cv.get_brightness(); const float b = cv.get_brightness();
if (b <= cap + 0.001f) return; // no call if already at/under cap if (b <= cap + 0.001f) return;
auto call = id(mosfet_leds).make_call(); auto call = id(mosfet_leds).make_call();
call.set_state(true); call.set_state(true);
call.set_brightness(cap); call.set_brightness(cap);
call.set_transition_length(0); call.set_transition_length(0);
call.perform(); call.perform();
#:########################################################################################:#
########################################################################################## # NUMBER COMPONENT:
# NUMBER COMPONENT
# https://esphome.io/components/number/ # https://esphome.io/components/number/
########################################################################################## #:########################################################################################:#
number: number:
- platform: template - platform: template
id: cfg_ramp_up_s id: cfg_ramp_up_s
@@ -668,24 +685,22 @@ number:
min_value: 0 min_value: 0
max_value: 100 max_value: 100
step: 1 step: 1
# Show current position mapped into 0..100 across [min..max]
lambda: |- lambda: |-
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f; // 0..100 actual float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0 if (maxp <= minp) maxp = minp + 1.0f;
if (actual <= 0.0f) return 0.0f; // when OFF, show 0 if (actual <= 0.0f) return 0.0f;
float pos = (actual - minp) * 100.0f / (maxp - minp); float pos = (actual - minp) * 100.0f / (maxp - minp);
if (pos < 0.0f) pos = 0.0f; if (pos < 0.0f) pos = 0.0f;
if (pos > 100.0f) pos = 100.0f; if (pos > 100.0f) pos = 100.0f;
return floorf(pos + 0.5f); // integer return floorf(pos + 0.5f);
set_action: set_action:
- if: - if:
condition: condition:
lambda: 'return x <= 0.0f;' lambda: 'return x <= 0.0f;'
then: then:
# 0 means OFF
- lambda: 'id(suppress_slider_sync) = true;' - lambda: 'id(suppress_slider_sync) = true;'
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.stop: ramp_off_script - script.stop: ramp_off_script
@@ -695,16 +710,15 @@ number:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
id(last_brightness_pct) = 0.0f; // persist OFF immediately id(last_brightness_pct) = 0.0f;
id(last_set_pos) = 0; id(last_set_pos) = 0;
- delay: 400ms - delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;' - lambda: 'id(suppress_slider_sync) = false;'
else: else:
# Map 1..100 - [min..max] and set ON
- lambda: |- - lambda: |-
id(suppress_slider_sync) = true; id(suppress_slider_sync) = true;
float pos = x; // 0..100 float pos = x;
if (pos < 1.0f) pos = 1.0f; // 0 is OFF if (pos < 1.0f) pos = 1.0f;
if (pos > 100.0f) pos = 100.0f; if (pos > 100.0f) pos = 100.0f;
id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f)); id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f));
- script.stop: ramp_off_script - script.stop: ramp_off_script
@@ -712,7 +726,7 @@ number:
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
brightness: !lambda |- brightness: !lambda |-
float pos = id(led_output_set_pct).state; // 1..100 float pos = id(led_output_set_pct).state;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; if (maxp <= minp) maxp = minp + 1.0f;
@@ -722,13 +736,13 @@ number:
transition_length: 250ms transition_length: 250ms
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
float pos = id(led_output_set_pct).state; // 1..100 float pos = id(led_output_set_pct).state;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; if (maxp <= minp) maxp = minp + 1.0f;
float out_pct = minp + (pos * (maxp - minp) / 100.0f); float out_pct = minp + (pos * (maxp - minp) / 100.0f);
if (out_pct > maxp) out_pct = maxp; if (out_pct > maxp) out_pct = maxp;
id(last_brightness_pct) = out_pct; // persist exact target now id(last_brightness_pct) = out_pct;
- delay: 400ms - delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;' - lambda: 'id(suppress_slider_sync) = false;'
@@ -762,19 +776,18 @@ number:
then: then:
- script.execute: max_on_watchdog - script.execute: max_on_watchdog
########################################################################################## #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call. #:########################################################################################:#
##########################################################################################
script: script:
# Script: ramp up from current level. Obey global max.
# Script: ramp up from current level. Obey global max. (LED ON while ramping)
- id: ramp_on_script - id: ramp_on_script
mode: restart mode: restart
then: then:
- lambda: 'id(is_ramping) = true;' - lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script - script.stop: ramp_off_script
# Ensure we start at at least the floor without a visible "pop". # Ensure we start at at least the floor without a visible "pop".
- if: - if:
condition: condition:
@@ -787,6 +800,7 @@ script:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;' brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
transition_length: 80ms transition_length: 80ms
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms. # Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
@@ -810,21 +824,23 @@ script:
if (frac > 1.0f) frac = 1.0f; if (frac > 1.0f) frac = 1.0f;
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac); id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
return (uint32_t) id(last_ramp_ms); return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);' - delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- lambda: |- - lambda: |-
id(is_ramping) = false; id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
float pct = cv.get_brightness() * 100.0f; float pct = cv.get_brightness() * 100.0f;
id(last_brightness_pct) = pct; // persist final level id(last_brightness_pct) = pct;
} }
# Script: ramp to a specific target (Restore Brightness path). (LED ON while ramping) # Script: ramp to a specific target (Restore Brightness path).
- id: ramp_to_target_script - id: ramp_to_target_script
mode: restart mode: restart
then: then:
- lambda: 'id(is_ramping) = true;' - lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script - script.stop: ramp_off_script
# Ensure we start at the floor cleanly. # Ensure we start at the floor cleanly.
- if: - if:
condition: condition:
@@ -837,6 +853,7 @@ script:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;' brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
transition_length: 80ms transition_length: 80ms
# Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms. # Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms.
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
@@ -866,17 +883,17 @@ script:
if (frac > 1.0f) frac = 1.0f; if (frac > 1.0f) frac = 1.0f;
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac); id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
return (uint32_t) id(last_ramp_ms); return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);' - delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- lambda: |- - lambda: |-
id(is_ramping) = false; id(is_ramping) = false;
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
float pct = cv.get_brightness() * 100.0f; float pct = cv.get_brightness() * 100.0f;
id(last_brightness_pct) = pct; // persist final level id(last_brightness_pct) = pct;
} }
# Script: ramp down from current level to floor, then cleanly cut to OFF.
# Script: ramp down from current level to floor, then cleanly cut to OFF. (LED ON while ramping)
- id: ramp_off_script - id: ramp_off_script
mode: restart mode: restart
then: then:
@@ -884,6 +901,7 @@ script:
id(is_ramping) = true; id(is_ramping) = true;
id(ramping_for_off) = true; id(ramping_for_off) = true;
- script.stop: ramp_on_script - script.stop: ramp_on_script
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;' brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
@@ -899,6 +917,7 @@ script:
if (frac > 1.0f) frac = 1.0f; if (frac > 1.0f) frac = 1.0f;
id(last_ramp_ms) = (int) (id(ramp_down_ms) * frac); id(last_ramp_ms) = (int) (id(ramp_down_ms) * frac);
return (uint32_t) id(last_ramp_ms); return (uint32_t) id(last_ramp_ms);
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);' - delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- light.turn_off: - light.turn_off:
id: mosfet_leds id: mosfet_leds
@@ -907,7 +926,7 @@ script:
- lambda: |- - lambda: |-
id(is_ramping) = false; id(is_ramping) = false;
id(ramping_for_off) = false; id(ramping_for_off) = false;
id(last_brightness_pct) = 0.0f; // persist OFF for restore path id(last_brightness_pct) = 0.0f;
id(last_set_pos) = 0; id(last_set_pos) = 0;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
@@ -933,7 +952,7 @@ script:
- id: deferred_restore_brightness - id: deferred_restore_brightness
mode: restart mode: restart
then: then:
- delay: 5s # let preferences/globals load and light settle - delay: 5s # let preferences/globals load and light settle
- lambda: |- - lambda: |-
// Use ONLY the exact last saved brightness. // Use ONLY the exact last saved brightness.
float target = id(last_brightness_pct); float target = id(last_brightness_pct);
@@ -951,7 +970,7 @@ script:
lambda: 'return id(restore_target_pct) > 0.5f;' lambda: 'return id(restore_target_pct) > 0.5f;'
then: then:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; // reflect our intent id(ramp_switch_target_on) = true;
id(suppress_slider_sync) = true; id(suppress_slider_sync) = true;
- script.stop: ramp_off_script - script.stop: ramp_off_script
- script.execute: ramp_to_target_script - script.execute: ramp_to_target_script
@@ -962,5 +981,4 @@ script:
- lambda: 'id(ramp_switch_target_on) = false;' - lambda: 'id(ramp_switch_target_on) = false;'
- light.turn_off: - light.turn_off:
id: mosfet_leds id: mosfet_leds
transition_length: 0s transition_length: 0s
# (Removed: output.turn_off: green_led_out) # make sure LED is off if no ramp
+101 -69
View File
@@ -1,67 +1,98 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: CENTRAL STAIRS - BOTTOM LIGHTSWITCH
# CENTRAL STAIRS - BOTTOM LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.7 2025-09-24 upload to this device #:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-centralstairs-bottom.yaml
#:########################################################################################:#
# VERSIONS:
# V3.7 2025-09-24 Upload to this device
# V3.5 2025-07-24 YAML tidyups # V3.5 2025-07-24 YAML tidyups
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Double push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Zemismart KS-811 Double push button (KS-811-2)
# pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Light switch at bottom of the central stairs
# - Button 1 toggles Relay 1 (Main Stair Lights - Lower) - physically connected
# - Button 2 controls Stair Footer Lights via MQTT (remote device), using Relay 2 as a local mirror state
# - On MQTT connect, publishes current Relay 1 state to mqtt_status_topic_1 to keep remote status aligned
#:########################################################################################:#
# MQTT COMMANDS:
# Remote device 1 (Main Stair Lights):
# - Command topic: ${mqtt_command_topic_1} -> ON,OFF
# - Status topic: ${mqtt_status_topic_1} -> ON,OFF
# #
# NOTES # Remote device 2 (Stair Footer Lights):
# - Light switch at top of the stairs, only the footer lights physically connected. # - Command topic: ${mqtt_command_topic_2} -> ON,OFF
# # - Status topic: ${mqtt_status_topic_2} -> ON,OFF
########################################################################################## #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Physical buttons still operate (Relay 1 local toggle; Button 2 publishes MQTT for footer lights)
# - Relay 1 state continues to be published to MQTT status topic
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Relay 1 still toggles locally and remains controllable from HA via API
# - Button 2 cannot control footer lights (MQTT publish fails)
# - Any MQTT state sync to remote devices will not occur while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Physical button 1 continues to toggle Relay 1 locally (standalone)
# - Physical button 2 cannot control footer lights (no network transport)
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Custom Naming # Device Custom Naming
device_name: "esp-centralstairs-bottom" device_name: "esp-centralstairs-bottom"
friendly_name: "Central Stair Lightswitch - Bottom (2)" friendly_name: "Central Stair Lightswitch - Bottom (2)"
description_comment: "Central Stair Lightswitch - Bottom, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2)" description_comment: "Central Stair Lightswitch - Bottom, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2) (Layout V1.1)"
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-centralstairs-bottom_ip static_ip_address: !secret esp-centralstairs-bottom_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT Device Names
mqtt_device_name_1: "stair-mainlights" mqtt_device_name_1: "stair-mainlights"
mqtt_device_name_2: "stair-footerlights" mqtt_device_name_2: "stair-footerlights"
# I/O Naming # I/O Naming
switch_1_name: "Main Stair Lights (Lower)" # Physical, but just the lower lights below the media cabinet switch_1_name: "Main Stair Lights (Lower)" # Physical, but just the lower lights below the media cabinet
switch_2_name: "Stair Footer Lights" # virtual only, nothing connected to this output switch_2_name: "Stair Footer Lights" # virtual only, nothing connected to this output
#relay_1_name: "Garage Lights"
#button_1_name: "Power Button"
#relay_icon: "mdi:lightbulb-group"
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# MQTT Controls # MQTT Controls
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
mqtt_command_topic_1: "${mqtt_command_main_topic}/${mqtt_device_name_1}" mqtt_command_topic_1: "${mqtt_command_main_topic}/${mqtt_device_name_1}"
mqtt_status_topic_1: "${mqtt_status_main_topic}/${mqtt_device_name_1}" mqtt_status_topic_1: "${mqtt_status_main_topic}/${mqtt_device_name_1}"
mqtt_command_topic_2: "${mqtt_command_main_topic}/${mqtt_device_name_2}" mqtt_command_topic_2: "${mqtt_command_main_topic}/${mqtt_device_name_2}"
mqtt_status_topic_2: "${mqtt_status_main_topic}/${mqtt_device_name_2}" mqtt_status_topic_2: "${mqtt_status_main_topic}/${mqtt_device_name_2}"
mqtt_command_ON: "ON" mqtt_command_ON: "ON"
mqtt_command_OFF: "OFF" mqtt_command_OFF: "OFF"
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
# General Settings # General Settings
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -70,6 +101,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -83,23 +115,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -108,39 +140,39 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot: #on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_2 # - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
######################################################################################### # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
######################################################################################### #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_connect: on_connect:
then: then:
- if: - if:
# Status of relay 1, which has an actual light connected
condition: condition:
lambda: 'return id(Relay_1).state;' lambda: 'return id(Relay_1).state;'
then: then:
@@ -199,26 +231,26 @@ mqtt:
then: then:
- switch.turn_off: Relay_2 - switch.turn_off: Relay_2
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
filters: filters:
- delayed_on: 30ms - delayed_on: 30ms
- delayed_off: 30ms - delayed_off: 30ms
@@ -230,7 +262,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
filters: filters:
- delayed_on: 30ms - delayed_on: 30ms
- delayed_off: 30ms - delayed_off: 30ms
@@ -251,10 +283,10 @@ binary_sensor:
payload: "${mqtt_command_ON}" payload: "${mqtt_command_ON}"
retain: false retain: false
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -275,4 +307,4 @@ switch:
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
# No mqtt.publish here (this is a mirror only) # No mqtt.publish here (this is a mirror only)
+103 -72
View File
@@ -1,67 +1,99 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: CENTRAL STAIRS - TOP LIGHTSWITCH
# CENTRAL STAIRS - TOP LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.7 2025-09-24 upload to this device #:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-centralstairs-top.yaml
#:########################################################################################:#
# VERSIONS:
# V3.7 2025-09-24 Upload to this device
# V3.5 2025-07-24 YAML tidyups # V3.5 2025-07-24 YAML tidyups
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Double push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Zemismart KS-811 Double push button (KS-811-2)
# pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Light switch at top of the central stairs
# - Button 1 controls Main Stair Lights via MQTT (remote device), using Relay 1 as a local mirror state
# - Button 2 toggles Relay 2 (Stair Footer Lights) - physically connected
# - On MQTT connect, publishes current Relay 2 state to mqtt_status_topic_2 to keep remote status aligned
#:########################################################################################:#
# MQTT COMMANDS:
# Remote device 1 (Main Stair Lights):
# - Command topic: ${mqtt_command_topic_1} -> ON,OFF
# - Status topic: ${mqtt_status_topic_1} -> ON,OFF
# #
# NOTES # Remote device 2 (Stair Footer Lights):
# - Light switch at top of the stairs # - Command topic: ${mqtt_command_topic_2} -> ON,OFF
# # - Status topic: ${mqtt_status_topic_2} -> ON,OFF
########################################################################################## #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Button 1 continues to publish MQTT commands for main stair lights
# - Button 2 continues to toggle Relay 2 locally
# - Relay 2 state continues to be published to mqtt_status_topic_2
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Button 2 still toggles Relay 2 locally and is controllable via HA API
# - Button 1 cannot control main stair lights (MQTT publish fails)
# - Any MQTT state sync to remote devices will not occur while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Button 2 continues to toggle Relay 2 locally (standalone)
# - Button 1 cannot control main stair lights (no network transport)
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Custom Naming # Device Custom Naming
device_name: "esp-centralstairs-top" device_name: "esp-centralstairs-top"
friendly_name: "Central Stair Lightswitch - Top (2)" friendly_name: "Central Stair Lightswitch - Top (2)"
description_comment: "Central Stair Lightswitch - Top, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2)" description_comment: "Central Stair Lightswitch - Top, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2) (Layout V1.1)"
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-centralstairs-top_ip static_ip_address: !secret esp-centralstairs-top_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT Device Names
mqtt_device_name_1: "stair-mainlights" mqtt_device_name_1: "stair-mainlights"
mqtt_device_name_2: "stair-footerlights" mqtt_device_name_2: "stair-footerlights"
# I/O Naming # I/O Naming
switch_1_name: "Main Stair Lights" # virtual only, nothing connected to this output switch_1_name: "Main Stair Lights" # virtual only, nothing connected to this output
switch_2_name: "Stair Footer Lights" # Footer lights connected to this relay switch_2_name: "Stair Footer Lights" # Footer lights connected to this relay
#relay_1_name: "Garage Lights"
#button_1_name: "Power Button"
#relay_icon: "mdi:lightbulb-group"
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# MQTT Controls # MQTT Controls
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
mqtt_command_topic_1: "${mqtt_command_main_topic}/${mqtt_device_name_1}" mqtt_command_topic_1: "${mqtt_command_main_topic}/${mqtt_device_name_1}"
mqtt_status_topic_1: "${mqtt_status_main_topic}/${mqtt_device_name_1}" mqtt_status_topic_1: "${mqtt_status_main_topic}/${mqtt_device_name_1}"
mqtt_command_topic_2: "${mqtt_command_main_topic}/${mqtt_device_name_2}" mqtt_command_topic_2: "${mqtt_command_main_topic}/${mqtt_device_name_2}"
mqtt_status_topic_2: "${mqtt_status_main_topic}/${mqtt_device_name_2}" mqtt_status_topic_2: "${mqtt_status_main_topic}/${mqtt_device_name_2}"
mqtt_command_ON: "ON" mqtt_command_ON: "ON"
mqtt_command_OFF: "OFF" mqtt_command_OFF: "OFF"
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
# General Settings # General Settings
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -70,6 +102,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -83,23 +116,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -108,39 +141,39 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot: #on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_2 # - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
######################################################################################### # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_connect: on_connect:
then: then:
- if: - if:
# Status of relay 1, which has an actual light connected
condition: condition:
lambda: 'return id(Relay_2).state;' lambda: 'return id(Relay_2).state;'
then: then:
@@ -199,32 +232,32 @@ mqtt:
then: then:
- switch.turn_off: Relay_2 - switch.turn_off: Relay_2
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
filters: filters:
- delayed_on: 30ms - delayed_on: 30ms
- delayed_off: 30ms - delayed_off: 30ms
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
# Toggle the remote Main Stair Lights (lower) via COMMAND topic, based on our mirrored state # Toggle the remote Main Stair Lights via COMMAND topic, based on our mirrored state
- if: - if:
condition: condition:
lambda: 'return id(Relay_1).state;' lambda: 'return id(Relay_1).state;'
@@ -243,7 +276,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
filters: filters:
- delayed_on: 30ms - delayed_on: 30ms
- delayed_off: 30ms - delayed_off: 30ms
@@ -251,10 +284,10 @@ binary_sensor:
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: Relay_2
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -275,6 +308,4 @@ switch:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_status_topic_2}" topic: "${mqtt_status_topic_2}"
payload: "${mqtt_command_OFF}" payload: "${mqtt_command_OFF}"
retain: false retain: false
+121 -73
View File
@@ -1,43 +1,69 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DATA CUPBOARD FAN CONTROL
# DATA CUPBOARD FAN CONTROL # zorruno.com layout v1.1 2026
# Fan control for Data Cupboard #:########################################################################################:#
# # REPO:
# Hardware: Yunshan 7-30V 10A Relay Board (HW-622) with ESP8266MOD # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-datacupboardfans.yaml
# #:########################################################################################:#
# VERSIONS:
# V1.3 2026-02-20 Remove invalid allow_other_uses on pulse_counter pins (ESPHome 2026.2.x) # V1.3 2026-02-20 Remove invalid allow_other_uses on pulse_counter pins (ESPHome 2026.2.x)
# V1.2 2026-02-20 Use common SNTP package, and publish fan fault/status via interval script # V1.2 2026-02-20 Use common SNTP package, and publish fan fault/status via interval script
# V1.1 2026-02-20 Fix template binary_sensor update method for ESPHome 2026.2.x # V1.1 2026-02-20 Fix template binary_sensor update method for ESPHome 2026.2.x
# V1.0 2026-02-20 Initial Version # V1.0 2026-02-20 Initial Version
# #:########################################################################################:#
# NOTES # HARDWARE:
# Yunshan 7-30V 10A Relay Board (HW-622) with ESP8266MOD
#:########################################################################################:#
# OPERATION NOTES:
# - Fan tach inputs are on GPIO1/GPIO3 (UART pins). Logger UART is disabled (baud_rate: 0). # - Fan tach inputs are on GPIO1/GPIO3 (UART pins). Logger UART is disabled (baud_rate: 0).
# - DHT22 data is on GPIO0 (boot-strap pin). Usually OK, but if you ever get boot issues, # - DHT22 data is on GPIO0 (boot-strap pin). Usually OK, but if you ever get boot issues,
# move the DHT22 to a different GPIO if your board allows. # move the DHT22 to a different GPIO if your board allows.
# - Using common/sntp_common.yaml for time and diagnostic time text sensors. # - Using common/sntp_common.yaml for time and diagnostic time text sensors.
########################################################################################## # - Thermostat logic uses hysteresis thresholds (On temp / Off temp) plus a manual override.
########################################################################################## # - Fan fault is evaluated periodically, with grace windows after boot and relay changes.
#:########################################################################################:#
# MQTT COMMANDS:
# Base topic: ${mqtt_main_topic}
# - ${mqtt_main_topic}/relay/set : ON,OFF
# - ${mqtt_main_topic}/override/set : ON,OFF
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Fan control logic still runs on-device (thermostat + override)
# - MQTT commands still work and fan status/fault still publishes via MQTT (common_mqtt)
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Fan control logic still runs on-device (thermostat + override)
# - HA can still control entities via API, but MQTT command topics will not work
# c) Entire WiFi/Network OFFLINE
# - Fan control logic still runs on-device (thermostat + override)
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
########################################################################################## # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-datacupboardfans" device_name: "esp-datacupboardfans"
friendly_name: "Data Cupboard Fans" friendly_name: "Data Cupboard Fans"
description_comment: "Fan control for Data Cupboard" description_comment: "Fan control for Data Cupboard (Layout V1.1)"
device_area: "Data Cupboard" device_area: "Data Cupboard"
# Project Naming # Project Naming
project_name: "Yunshan.HW-622 ESP8266MOD Relay Board" project_name: "Yunshan.HW-622 ESP8266MOD Relay Board"
project_version: "v1.3" project_version: "v1.3"
# Passwords # Passwords and Secrets (Unfortunately, you cannot use substitutions inside secret names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-datacupboardfans_ip static_ip_address: !secret esp-datacupboardfans_ip
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT Controls # MQTT Controls
mqtt_device_name: "data-cupboard-fans" mqtt_device_name: "data-cupboard-fans"
mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}"
@@ -67,9 +93,10 @@ substitutions:
default_temp_on: "35" default_temp_on: "35"
default_temp_off: "28" default_temp_off: "28"
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
########################################################################################## # https://esphome.io/components/packages.html
#:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -78,6 +105,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API #### #### HOME ASSISTANT API ####
common_api: !include common_api: !include
@@ -99,9 +127,10 @@ packages:
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
########################################################################################## # https://esphome.io/components/esphome.html
#:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -120,9 +149,11 @@ esphome:
- script.execute: apply_fan_control - script.execute: apply_fan_control
- script.execute: evaluate_fan_fault - script.execute: evaluate_fan_fault
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
########################################################################################## # https://esphome.io/components/esp8266/
# https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp12e board: esp12e
restore_from_flash: true restore_from_flash: true
@@ -133,75 +164,87 @@ preferences:
mdns: mdns:
disabled: false disabled: false
########################################################################################## #:########################################################################################:#
# LOGGING # LOGGING:
########################################################################################## # https://esphome.io/components/logger.html
#:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 baud_rate: 0
########################################################################################## #:########################################################################################:#
# GLOBALS # GLOBAL VARIABLES:
########################################################################################## # https://esphome.io/components/globals.html
#:########################################################################################:#
globals: globals:
# Max temperature tracking # Max temperature tracking
- id: g_max_temp_today - id: g_max_temp_today
type: float type: float
restore_value: yes restore_value: true
initial_value: "-1000.0" initial_value: "-1000.0"
- id: g_max_temp_yesterday - id: g_max_temp_yesterday
type: float type: float
restore_value: yes restore_value: true
initial_value: "-1000.0" initial_value: "-1000.0"
- id: g_max_temp_month - id: g_max_temp_month
type: float type: float
restore_value: yes restore_value: true
initial_value: "-1000.0" initial_value: "-1000.0"
- id: g_max_temp_last_month - id: g_max_temp_last_month
type: float type: float
restore_value: yes restore_value: true
initial_value: "-1000.0" initial_value: "-1000.0"
- id: g_max_temp_year - id: g_max_temp_year
type: float type: float
restore_value: yes restore_value: true
initial_value: "-1000.0" initial_value: "-1000.0"
# Last seen date parts (for rollover) # Last seen date parts (for rollover)
- id: g_last_day - id: g_last_day
type: int type: int
restore_value: yes restore_value: true
initial_value: "0" initial_value: "0"
- id: g_last_month - id: g_last_month
type: int type: int
restore_value: yes restore_value: true
initial_value: "0" initial_value: "0"
- id: g_last_year - id: g_last_year
type: int type: int
restore_value: yes restore_value: true
initial_value: "0" initial_value: "0"
# Fault evaluation grace timing # Fault evaluation grace timing
- id: boot_ms - id: boot_ms
type: uint32_t type: uint32_t
restore_value: no restore_value: false
initial_value: "0"
- id: relay_last_change_ms
type: uint32_t
restore_value: no
initial_value: "0" initial_value: "0"
########################################################################################## - id: relay_last_change_ms
# INTERVAL (periodic evaluations) type: uint32_t
restore_value: false
initial_value: "0"
#:########################################################################################:#
# INTERVAL:
# https://esphome.io/components/interval.html
#:########################################################################################:#
# Periodic evaluations
# NOTE: common_sntp also defines its own interval (60s) for its fallback clock. # NOTE: common_sntp also defines its own interval (60s) for its fallback clock.
##########################################################################################
interval: interval:
- interval: 5s - interval: 5s
then: then:
- script.execute: evaluate_fan_fault - script.execute: evaluate_fan_fault
########################################################################################## #:########################################################################################:#
# SWITCHES (Relay + Override) # SWITCHES:
########################################################################################## # https://esphome.io/components/switch/
#:########################################################################################:#
switch: switch:
# Relay output (GPIO4) - powers both fans # Relay output (GPIO4) - powers both fans
- platform: gpio - platform: gpio
@@ -239,9 +282,11 @@ switch:
- script.execute: apply_fan_control - script.execute: apply_fan_control
- script.execute: evaluate_fan_fault - script.execute: evaluate_fan_fault
########################################################################################## #:########################################################################################:#
# NUMBERS (On/Off thresholds with hysteresis) # NUMBERS:
########################################################################################## # https://esphome.io/components/number/
#:########################################################################################:#
# On/Off thresholds with hysteresis
number: number:
- platform: template - platform: template
name: "Fans On Temperature" name: "Fans On Temperature"
@@ -275,9 +320,10 @@ number:
set_action: set_action:
- script.execute: apply_fan_control - script.execute: apply_fan_control
########################################################################################## #:########################################################################################:#
# BINARY SENSORS (Door + Fault) # BINARY SENSORS:
########################################################################################## # https://esphome.io/components/binary_sensor/
#:########################################################################################:#
binary_sensor: binary_sensor:
# Door status on GPIO5 # Door status on GPIO5
- platform: gpio - platform: gpio
@@ -298,17 +344,19 @@ binary_sensor:
id: fan_fault id: fan_fault
device_class: problem device_class: problem
########################################################################################## #:########################################################################################:#
# STATUS LED (GPIO2) # STATUS LED:
########################################################################################## # https://esphome.io/components/status_led.html
#:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: true inverted: true
########################################################################################## #:########################################################################################:#
# SENSORS (Temp/Humidity + Fan RPM + Max temp templates) # SENSORS:
########################################################################################## # https://esphome.io/components/sensor/
#:########################################################################################:#
sensor: sensor:
# DHT22 on GPIO0 # DHT22 on GPIO0
- platform: dht - platform: dht
@@ -419,19 +467,22 @@ sensor:
lambda: |- lambda: |-
return id(g_max_temp_year); return id(g_max_temp_year);
########################################################################################## #:########################################################################################:#
# TEXT SENSOR (Normal/Fault status) - published by script # TEXT SENSORS:
# https://esphome.io/components/text_sensor/
#:########################################################################################:#
# Normal/Fault status - published by script
# NOTE: common_sntp also defines its own text_sensors (time status etc). # NOTE: common_sntp also defines its own text_sensors (time status etc).
##########################################################################################
text_sensor: text_sensor:
- platform: template - platform: template
name: "${fan_status_name}" name: "${fan_status_name}"
id: fan_status id: fan_status
icon: "mdi:fan-alert" icon: "mdi:fan-alert"
########################################################################################## #:########################################################################################:#
# SCRIPTS # SCRIPTS:
########################################################################################## # https://esphome.io/components/script.html
#:########################################################################################:#
script: script:
# Apply fan control logic (override + hysteresis thresholds) # Apply fan control logic (override + hysteresis thresholds)
- id: apply_fan_control - id: apply_fan_control
@@ -498,9 +549,6 @@ script:
const float req = id(fan_relay).state ? ${rpm_min_when_relay_on} : ${rpm_min_when_relay_off}; const float req = id(fan_relay).state ? ${rpm_min_when_relay_on} : ${rpm_min_when_relay_off};
// Requirement as requested:
// - Relay OFF => both fans must be > 1800 RPM
// - Relay ON => both fans must be > 3000 RPM
const bool fault = (r1 < req) || (r2 < req); const bool fault = (r1 < req) || (r2 < req);
id(fan_fault).publish_state(fault); id(fan_fault).publish_state(fault);
@@ -569,9 +617,9 @@ script:
id(max_temp_last_month).publish_state(id(g_max_temp_last_month)); id(max_temp_last_month).publish_state(id(g_max_temp_last_month));
id(max_temp_year).publish_state(id(g_max_temp_year)); id(max_temp_year).publish_state(id(g_max_temp_year));
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS (device-specific) # MQTT (DEVICE-SPECIFIC COMMAND SUBSCRIPTIONS):
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Relay control # Relay control
+61 -41
View File
@@ -1,24 +1,43 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DATA CUPBOARD POWER MONITOR - LEFT
# DATA CUPBOARD POWER MONITOR - LEFT # zorruno.com layout v1.1 2026
# #:########################################################################################:#
# Controlled by a Athom Smart Plug V2 No Relay # REPO:
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-datacupboardpower-left.yaml
# #:########################################################################################:#
# VERSIONS:
# V1.0 2025-08-28 First Setup # V1.0 2025-08-28 First Setup
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # Athom Smart Plug V2 (No Relay) - Power Monitor
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml
#:########################################################################################:#
# OPERATION NOTES:
# - Power monitoring only (no relay)
# - Uses Athom common package: common/athompowermonv2norelay_common.yaml
# - Energy sensor can be hidden via hide_energy_sensor substitution
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device continues metering and publishing via MQTT (common_mqtt)
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device continues metering and HA can read values via API
# - MQTT publish/subscribe will not function while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Device continues metering locally but cannot report data to HA/MQTT
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-datacupboardpower-left" device_name: "esp-datacupboardpower-left"
friendly_name: "Data Cupboard Power Monitor - Left" friendly_name: "Data Cupboard Power Monitor - Left"
description_comment: "Data Cupboard Left :: Athom Smart Plug Power V2 (No relay)" description_comment: "Data Cupboard Left :: Athom Smart Plug Power V2 (No relay) (Layout V1.1)"
device_area: "Data Cupboard" device_area: "Data Cupboard"
# Project Naming # Project Naming
@@ -30,20 +49,22 @@ substitutions:
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-datacupboardpower-left_ip static_ip_address: !secret esp-datacupboardpower-left_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device General Settings # Device General Settings
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for general sensors etc update_interval: "60s" # update time for general sensors etc
# Device Specific Settings (Athom Power Monitor Plug V2) # Device Specific Settings (Athom Power Monitor Plug V2)
sensor_update_interval: "10s" sensor_update_interval: "10s"
hide_energy_sensor: "true" # boolean (used by "internal:") hide_energy_sensor: "true" # boolean (used by "internal:")
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -52,6 +73,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -65,21 +87,20 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
# Device Specific included packages #### DEVICE SPECIFIC: Athom Power Monitor Plug V2 (No Relay) ####
# Athom Power Monitor Plug V2 (No Relay)
common_athompowermonV2: !include common_athompowermonV2: !include
file: common/athompowermonv2norelay_common.yaml file: common/athompowermonv2norelay_common.yaml
vars: vars:
@@ -87,10 +108,10 @@ packages:
sensor_update_interval: "${sensor_update_interval}" sensor_update_interval: "${sensor_update_interval}"
hide_energy_sensor: "${hide_energy_sensor}" hide_energy_sensor: "${hide_energy_sensor}"
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -102,10 +123,10 @@ esphome:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp8266.html # https://esphome.io/components/esp8266.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true restore_from_flash: true
@@ -117,11 +138,10 @@ preferences:
mdns: mdns:
disabled: false disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome LOGGING # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 # free UART for CSE7766 baud_rate: 0 # free UART for CSE7766
+63 -42
View File
@@ -1,50 +1,71 @@
#:########################################################################################:#
########################################################################################## # TITLE: DATA CUPBOARD POWER MONITOR - RIGHT
########################################################################################## # zorruno.com layout v1.1 2026
# DATA CUPBOARD POWER MONITOR - RIGHT #:########################################################################################:#
# # REPO:
# Controlled by a Athom Smart Plug V2 No Relay # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-datacupboardpower-right.yaml
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml #:########################################################################################:#
# # VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 2025-08-28 First Setup # V1.0 2025-08-28 First Setup
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # Athom Smart Plug V2 (No Relay) - Power Monitor
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml
#:########################################################################################:#
# OPERATION NOTES:
# - Power monitoring only (no relay)
# - Uses Athom common package: common/athompowermonv2norelay_common.yaml
# - Energy sensor can be hidden via hide_energy_sensor substitution
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device continues metering and publishing via MQTT (common_mqtt)
# - HA entities are unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device continues metering and HA can read values via API
# - MQTT publish/subscribe will not function while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Device continues metering locally but cannot report data to HA/MQTT
# - SNTP not needed (no timeclocks; loss of network does not affect timing)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-datacupboardpower-right" device_name: "esp-datacupboardpower-right"
friendly_name: "Data Cupboard Power Monitor - Right" friendly_name: "Data Cupboard Power Monitor - Right"
description_comment: "Data Cupboard Right :: Athom Smart Plug Power V2 (No relay)" description_comment: "Data Cupboard Right :: Athom Smart Plug Power V2 (No relay) (Layout V1.1)"
device_area: "Data Cupboard" device_area: "Data Cupboard"
# Project Naming # Project Naming
project_name: "Athom Technology.Smart Plug V2 NR" project_name: "Athom Technology.Smart Plug V2 NR"
project_version: "v1.0" project_version: "v1.1"
# Passwords (unfortunately you cannot use substitutions inside secrets names) # Passwords (unfortunately you cannot use substitutions inside secrets names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-datacupboardpower-right_ip static_ip_address: !secret esp-datacupboardpower-right_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device General Settings # Device General Settings
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for general sensors etc update_interval: "60s" # update time for general sensors etc
# Device Specific Settings (Athom Power Monitor Plug V2) # Device Specific Settings (Athom Power Monitor Plug V2)
sensor_update_interval: "10s" sensor_update_interval: "10s"
hide_energy_sensor: "true" # boolean (used by "internal:") hide_energy_sensor: "true" # boolean (used by "internal:")
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -53,6 +74,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -66,21 +88,20 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
# Device Specific included packages #### DEVICE SPECIFIC: Athom Power Monitor Plug V2 (No Relay) ####
# Athom Power Monitor Plug V2 (No Relay)
common_athompowermonV2: !include common_athompowermonV2: !include
file: common/athompowermonv2norelay_common.yaml file: common/athompowermonv2norelay_common.yaml
vars: vars:
@@ -88,10 +109,10 @@ packages:
sensor_update_interval: "${sensor_update_interval}" sensor_update_interval: "${sensor_update_interval}"
hide_energy_sensor: "${hide_energy_sensor}" hide_energy_sensor: "${hide_energy_sensor}"
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -103,10 +124,10 @@ esphome:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp8266.html # https://esphome.io/components/esp8266.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true restore_from_flash: true
@@ -118,10 +139,10 @@ preferences:
mdns: mdns:
disabled: false disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome LOGGING # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 # free UART for CSE7766 baud_rate: 0 # free UART for CSE7766
+106 -73
View File
@@ -1,55 +1,83 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS DISHWASHER POWER MONITOR
# DOWNSTAIRS DISHWASHER POWER MONITOR # zorruno.com layout v1.1 2026
# #:########################################################################################:#
# Controlled by a Athom Smart Plug V1 # REPO:
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstdishwasher.yaml
# #:########################################################################################:#
# VERSIONS:
# V1.4 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.3 2025-08-27 Changed to Athom V2 # V1.3 2025-08-27 Changed to Athom V2
# V1.2 2025-06-15 Changed to Athom V1 # V1.2 2025-06-15 Changed to Athom V1
# V1.1 2025-06-12 Tidyups and packages added # V1.1 2025-06-12 Tidyups and packages added
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # Athom Smart Plug V2 (ESP8285) with power monitoring
# - Power monitoring handled by: common/athompowermonv2_common.yaml
#:########################################################################################:#
# OPERATION NOTES:
# - Power monitoring smart plug for the downstairs dishwasher.
# - Uses common WiFi, API, MQTT, SNTP, and diagnostics packages.
# - "Power On State" select controls restore behavior using the restore_mode global:
# - Always Off
# - Always On
# - Restore Previous State
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device continues measuring power locally.
# - MQTT topics (if used elsewhere) and network remain available; HA entities will be unavailable until HA returns.
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable/visible from Home Assistant via API.
# - MQTT functionality from common_mqtt (publishes/subscribes) will not work while MQTT is down.
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available.
# - Device continues operating locally using last stored settings.
# - Accurate time is NOT needed (SNTP not needed) for core plug operation.
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstdishwasher" device_name: "esp-downstdishwasher"
friendly_name: "Downstairs Dishwasher Power" friendly_name: "Downstairs Dishwasher Power"
description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V2" description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V2 (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Athom Technology.Smart Plug V2" # Project Details project_name: "Athom Technology.Smart Plug V2"
project_version: "v1.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.4"
# Passwords (unfortunately you can't use substitutions inside secrets names) # Passwords (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-downstdishwasher_ip static_ip_address: !secret esp-downstdishwasher_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device General Settings # Device General Settings
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# Device Specific Settings # Device Specific Settings
# Athom Power Monitor Plug V2 # Athom Power Monitor Plug V2
relay_icon: "mdi:power-socket-au" relay_icon: "mdi:power-socket-au"
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
sensor_update_interval: "10s" sensor_update_interval: "10s"
relay_restore_mode: RESTORE_DEFAULT_ON relay_restore_mode: RESTORE_DEFAULT_ON
hide_energy_sensor: "true" hide_energy_sensor: "true"
##########################################################################################
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -58,6 +86,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -71,18 +100,18 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
# Device Specific included packages # Device Specific included packages
# Athom Power Monitor Plug # Athom Power Monitor Plug
@@ -96,15 +125,16 @@ packages:
power_plug_type: "${relay_icon}" power_plug_type: "${relay_icon}"
hide_energy_sensor: "${hide_energy_sensor}" hide_energy_sensor: "${hide_energy_sensor}"
##########################################################################################
# ESPHome #:########################################################################################:#
# ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
name_add_mac_suffix: false name_add_mac_suffix: false
min_version: 2024.6.0 min_version: 2024.6.0
project: project:
@@ -116,27 +146,27 @@ esphome:
- select.set_index: - select.set_index:
id: power_mode id: power_mode
index: !lambda |- index: !lambda |-
return id(restore_mode)-1; return id(restore_mode) - 1;
- lambda: |- - lambda: |-
switch(id(restore_mode)) switch (id(restore_mode)) {
{ case 1: {
case 1:{ id(relay).turn_off();
id(relay).turn_off(); break;
break;
}
case 2:{
id(relay).turn_on();
break;
}
default:{
break;
}
} }
case 2: {
id(relay).turn_on();
break;
}
default: {
break;
}
}
##########################################################################################
# ESP Platform and Framework #:########################################################################################:#
# https://esphome.io/components/esp32.html # ESP PLATFORM AND FRAMEWORK:
########################################################################################## # https://esphome.io/components/esp8266.html
#:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
@@ -148,18 +178,20 @@ preferences:
mdns: mdns:
disabled: false disabled: false
##########################################################################################
# ESPHome LOGGING
# https://esphome.io/components/logger.html
##########################################################################################
logger:
level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # LOGGING: ESPHome Logging Enable
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger:
level: "${log_level}"
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg power monitor UART)
#:########################################################################################:#
# GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html#global-variables
#:########################################################################################:#
globals: globals:
# 0 = Always_Off. 1 = Restore_Power_Off. 2 = Always_On. # 0 = Always_Off. 1 = Restore_Power_Off. 2 = Always_On.
- id: restore_mode - id: restore_mode
@@ -167,14 +199,15 @@ globals:
restore_value: yes restore_value: yes
initial_value: "2" initial_value: "2"
##########################################################################################
# SELECT COMPONENT #:########################################################################################:#
# SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
########################################################################################## #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Power On State" name: "Power On State"
id: "power_mode" id: power_mode
optimistic: true optimistic: true
icon: mdi:electric-switch icon: mdi:electric-switch
options: options:
@@ -184,4 +217,4 @@ select:
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
id(restore_mode)=i+1; id(restore_mode) = i + 1;
+231 -242
View File
@@ -1,83 +1,111 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS KITCHEN - OVER PANTRY LEDS
# Title: DOWNSTAIRS KITCHEN - OVER PANTRY LEDS # zorruno.com layout v1.1 2026
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstairskitchleds.yaml #:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstairskitchleds.yaml
#:########################################################################################:#
# VERSIONS:
# v2.1 2026-02-25 Updated yaml to zorruno layout V1.1
# v2.0 2025-09-15 A bunch of fixes.
# v1.5 2025-09-04 Adopt ramped "Restore Brightness" (0->last non-zero), avoid boot blip (ALWAYS_OFF + high-priority on_boot),
# add flash-write coalescing (persist once at end of ramps), guards for edge cases, and flash_write_interval=5min
# v1.4 2025-08-22 Improved power loss/on actions
# v1.3 2025-08-22 Added a "max on time" setting (1-48 h, 0 = no limit)
# v1.2 2025-08-21 Added defaults to "Device Specific Settings" in substitutions & a PWM % view
# v1.1 2025-08-18 Full tidy-up as general-purpose LED strip controller
# v1.0 2025-08-17 First setup (and replacement of Tasmota)
#:########################################################################################:#
# HARDWARE:
# - Sinilink MOSFET Board XY-WFMS (ESP8266) - sometimes listed as "XY-VFMS"
# https://devices.esphome.io/devices/Sinilink-XY-WFMS
# #
# v2.0 - 2025-09-15 A bunch of fixes. # - 3D-printed case for Sinilink XY-WFMS
# v1.5 - 2025-09-04 Adopt ramped "Restore Brightness" (0→last non-zero), avoid boot blip (ALWAYS_OFF + high-priority on_boot), # https://cults3d.com/en/3d-model/tool/snapfit-enclosure-for-esp8266-sinilink-xy-wfms-5v-36v-mosfet-switch-module
# add flash-write coalescing (persist once at end of ramps), guards for edge cases, and flash_write_interval=5min
# v1.4 - 2025-08-22 Improved power loss/on actions
# v1.3 - 2025-08-22 Added a "max on time” setting (1-48 h, 0 = no limit)
# v1.2 - 2025-08-21 Added defaults to “Device Specific Settings” in substitutions & a PWM % view
# v1.1 - 2025-08-18 Full tidy-up as general-purpose LED strip controller
# v1.0 - 2025-08-17 First setup (and replacement of Tasmota)
# #
# ------------------------------------------
# OPERATION (as of v2.0)
# ------------------------------------------
# 1. General-purpose LED controller.
# 2. Designed for the Sinilink XY-WFMS board with a MOSFET output (claimed 5A, 5-36 V DC), but will suit similar mosfet boards.
# 3. (In SUBSTITUTIONS) setting for MAX % output to extend LED life (ie can ensure it is only ever 95%)
# 4. (In SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
# 5. (In SUBSTITUTIONS) PWM frequency is set to 1kHz by default. You can increase it, but higher values caused
# resets on Sinilink device. On ESP32 you can run much higher (~40 kHz).
# 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but could be.
# With a 1 MB flash, space is tight and only minimal optimisation has been done so far.
# 7. (PACKAGES) include common items: network settings, diagnostic entities, MQTT, and SNTP (optional).
# 8. Default behaviours, for recovery from lost power or reset:
# - "Fade up to full": fade from floor to max on boot.
# - "Restore Brightness": fade from floor to the last non-zero brightness on boot (should be no on/off blip/flash).
# - "Remain Off": stays off on boot.
# 9. Green LED rule: ON while any ramp script is executing, otherwise OFF. The red LED follows the
# output (it shares the MOSFET GPIO). (Obviously this depends on hardware)
# 10. Fade timing scales with the configured values (proportionally when starting mid-brightness).
# 11. Exposed in Home Assistant/MQTT:
# - Startup action (On,Off,Restore)
# - Fade Up / Fade Down / Fade Stop buttons
# - Fade Up/Down toggle switch
# - Normal On/Off switch (quick ramp up/down)
# - Fade up/down times (0-60s)
# - Output % (pre-gamma) and PWM % (post-gamma)
# - Output Set (1-100, respects min/max). This also changes with other output so reflects value.
# - Many device diagnostics (from the included 'diagnostics' package)
# - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit)
###########################################################################################
# Hardware: Sinilink MOSFET Board XY-WFMS (ESP8266) - sometimes listed as "XY-VFMS"
# https://devices.esphome.io/devices/Sinilink-XY-WFMS
# ------------------------------------------
# DEVICE GPIO (Sinilink XY-WFMS) # DEVICE GPIO (Sinilink XY-WFMS)
# ------------------------------------------ # - GPIO02 Blue LED, active-low (used for ESPHome status)
# GPIO02 Blue LED, active-low (used for ESPHome status) # - GPIO04 MOSFET output (0V when switched) and Red LED
# GPIO04 MOSFET output (0V when switched) and Red LED # - GPIO12 Toggle button
# GPIO12 Toggle button # - GPIO13 Green LED (used to display fading status)
# GPIO13 Green LED (used to display fading status) #:########################################################################################:#
# OPERATION NOTES:
# - OPERATION (as of v2.0)
# 1. General-purpose LED controller.
# 2. Designed for the Sinilink XY-WFMS board with a MOSFET output (claimed 5A, 5-36 V DC), but will suit similar mosfet boards.
# 3. (In SUBSTITUTIONS) setting for MAX % output to extend LED life (ie can ensure it is only ever 95%)
# 4. (In SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
# 5. (In SUBSTITUTIONS) PWM frequency is set to 1kHz by default. You can increase it, but higher values caused
# resets on Sinilink device. On ESP32 you can run much higher (~40 kHz).
# 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but could be.
# With a 1 MB flash, space is tight and only minimal optimisation has been done so far.
# 7. (PACKAGES) include common items: network settings, diagnostic entities, MQTT, and SNTP (optional).
# 8. Default behaviours, for recovery from lost power or reset:
# - "Fade up to full": fade from floor to max on boot.
# - "Restore Brightness": fade from floor to the last non-zero brightness on boot (should be no on/off blip/flash).
# - "Remain Off": stays off on boot.
# 9. Green LED rule: ON while any ramp script is executing, otherwise OFF. The red LED follows the
# output (it shares the MOSFET GPIO). (Obviously this depends on hardware)
# 10. Fade timing scales with the configured values (proportionally when starting mid-brightness).
# 11. Exposed in Home Assistant/MQTT:
# - Startup action (On,Off,Restore)
# - Fade Up / Fade Down / Fade Stop buttons
# - Fade Up/Down toggle switch
# - Normal On/Off switch (quick ramp up/down)
# - Fade up/down times (0-60s)
# - Output % (pre-gamma) and PWM % (post-gamma)
# - Output Set (1-100, respects min/max). This also changes with other output so reflects value.
# - Many device diagnostics (from the included 'diagnostics' package)
# - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit)
#:########################################################################################:#
# MQTT COMMANDS:
# - Command topic:
# ${mqtt_local_command_topic}/light/set
# Payload "${mqtt_local_device_command_ON}" -> fade up (switch ON)
# Payload "${mqtt_local_device_command_OFF}" -> fade down (switch OFF)
# #
# 3D-printed case for Sinilink XY-WFMS # - Status topic:
# https://cults3d.com/en/3d-model/tool/snapfit-enclosure-for-esp8266-sinilink-xy-wfms-5v-36v-mosfet-switch-module # ${mqtt_local_status_topic}/light/state
# # Payload "${mqtt_local_device_command_ON}" / "${mqtt_local_device_command_OFF}"
########################################################################################## #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - MQTT control continues to work
# - LED control logic continues locally
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - HA/API control continues to work (if API enabled)
# - MQTT commands/status will not work while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - No HA/API and no MQTT control available
# - Local button still controls fade up/down
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstairskitchleds" # yaml file should be device_name.yaml device_name: "esp-downstairskitchleds" # yaml file should be device_name.yaml
friendly_name: "Downstairs Kitchen LEDs" friendly_name: "Downstairs Kitchen LEDs"
description_comment: "Downstairs Kitchen Over Pantry LEDs :: Sinilink XY-WFMS" description_comment: "Downstairs Kitchen Over Pantry LEDs :: Sinilink XY-WFMS (Layout V1.1)"
device_area: "Downstairs Kitchen" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Kitchen" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sinilink.XY-WFMS" # Project details. Manufacturer before the dot, device after the dot. project_name: "Sinilink.XY-WFMS" # Project details. Manufacturer before the dot, device after the dot.
project_version: "v2.0" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version project_version: "v2.1" # Project version denotes release of the YAML file, allowing checking of deployed vs latest version
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names) # Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-downstairskitchleds_ip # CHANGE THIS static_ip_address: !secret esp-downstairskitchleds_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT LOCAL Controls # MQTT LOCAL Controls
mqtt_local_device_name: "downstairskitchen-pantryleds" mqtt_local_device_name: "downstairskitchen-pantryleds"
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
@@ -88,24 +116,24 @@ substitutions:
mqtt_local_device_command_OFF: "OFF" mqtt_local_device_command_OFF: "OFF"
# Device Specific Settings # Device Specific Settings
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
update_interval: "20s" # Update time for general sensors, etc. update_interval: "20s" # Update time for general sensors, etc.
led_gamma: "1.2" # Gamma from 1.2-3 is sensible to normalise the LED fading vs PWM led_gamma: "1.2" # Gamma from 1.2-3 is sensible to normalise the LED fading vs PWM
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics
max_on_default_hours: "24" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off max_on_default_hours: "24" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off
pwm_frequency: "1000" # PWM output Frequency in Hz. High enough to avoid audible/visible artifacts pwm_frequency: "1000" # PWM output Frequency in Hz. High enough to avoid audible/visible artifacts
# Device Specific GPIO (so we can easily update for other devices) # Device Specific GPIO (so we can easily update for other devices)
device_status_led: GPIO02 device_status_led: GPIO02
device_mosfet_out: GPIO04 device_mosfet_out: GPIO04
device_usr_button: GPIO12 # if no button, this is just a fake/safeish choice so it compiles with the generic yaml device_usr_button: GPIO12 # if no button, this is just a fake/safeish choice so it compiles with the generic yaml
device_fading_led: GPIO13 # if no LED, this is just a fake/safeish choice so it compiles with the generic yaml device_fading_led: GPIO13 # if no LED, this is just a fake/safeish choice so it compiles with the generic yaml
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -114,6 +142,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -127,22 +156,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome CORE CONFIGURATION # ESPHOME: Core Configuration
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -190,25 +220,10 @@ esphome:
# Boot complete: allow OFF handlers again # Boot complete: allow OFF handlers again
- lambda: 'id(booting) = false;' - lambda: 'id(booting) = false;'
# NEW: force indicator OFF after boot logic #:########################################################################################:#
# (Removed: output.turn_off: green_led_out)
# Only if you want to play with build flags...
# platformio_options:
# build_unflags:
# - -flto
# build_flags:
# - -fno-lto
# - -Wl,--gc-sections
# - -ffunction-sections
# - -fdata-sections
# - -DNDEBUG
##########################################################################################
# ESP PLATFORM AND FRAMEWORK # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp8266.html # https://esphome.io/components/esp8266.html
# https://esphome.io/components/esp32.html #:########################################################################################:#
##########################################################################################
esp8266: esp8266:
board: esp01_1m board: esp01_1m
restore_from_flash: true # restore some values on reboot restore_from_flash: true # restore some values on reboot
@@ -219,118 +234,127 @@ mdns:
preferences: preferences:
flash_write_interval: 2min # enough time to update values for reboots, but not enough to wear flash flash_write_interval: 2min # enough time to update values for reboots, but not enough to wear flash
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBALS
# https://esphome.io/components/globals.html # https://esphome.io/components/globals.html
########################################################################################## #:########################################################################################:#
globals: globals:
# Minimum Brightness % for LEDs (will switch off if <=) # Minimum Brightness % for LEDs (will switch off if <=)
- id: min_brightness_pct - id: min_brightness_pct
type: int type: int
restore_value: true restore_value: true
initial_value: "${minimum_led_output}" # start/finish at X% initial_value: "${minimum_led_output}" # start/finish at X%
# Maximum Brightness % for LEDs (should never go beyond this) # Maximum Brightness % for LEDs (should never go beyond this)
- id: max_brightness_pct - id: max_brightness_pct
type: int type: int
restore_value: false restore_value: false
initial_value: "${maximum_led_output}" # hard cap; never exceed this initial_value: "${maximum_led_output}" # hard cap; never exceed this
# The maximum time the lights will stay on, in hours. Just in case they are left on. 0 = forever
# The maximum time the lights will stay on, in hours. 0 = forever
- id: max_on_hours - id: max_on_hours
type: int type: int
restore_value: true restore_value: true
initial_value: "${max_on_default_hours}" initial_value: "${max_on_default_hours}"
# Compile time Gamma # Compile time Gamma
- id: led_gamma_f - id: led_gamma_f
type: float type: float
restore_value: false restore_value: false
initial_value: ${led_gamma} # <-- numeric at compile time initial_value: ${led_gamma}
# Default Fading Up Time (Selectable and will be retained) # Default Fading Up Time (Selectable and will be retained)
- id: ramp_up_ms # fade-in when turned ON - id: ramp_up_ms
type: int type: int
restore_value: true restore_value: true
initial_value: '5000' # 5 s initial_value: "5000" # 5 s
# Default Fading Down Time (Selectable and will be retained)
- id: ramp_down_ms # fade-out when turned OFF
type: int
restore_value: true
initial_value: '10000' # 10 s
# Action on Restart. (0=Fade full, 1=Restore brightness, 2=Remain off)
- id: restart_mode
type: int
restore_value: true
initial_value: '0' # default = Fade Up to Full (so can be deployed with no other setup)
# Determine last fade direction. # Default Fading Down Time (Selectable and will be retained)
# true when you asked the light to end up ON (Ramp Up) - id: ramp_down_ms
# false when you asked the light to end up OFF (Ramp Down) type: int
restore_value: true
initial_value: "10000" # 10 s
# Action on Restart (0=Fade full, 1=Restore brightness, 2=Remain off)
- id: restart_mode
type: int
restore_value: true
initial_value: "0"
# true when you asked the light to end up ON (Ramp Up); false when OFF (Ramp Down)
- id: ramp_switch_target_on - id: ramp_switch_target_on
type: bool type: bool
restore_value: true restore_value: true
initial_value: 'false' initial_value: "false"
# Prevent jitter when adjusting the slider # Prevent jitter when adjusting the slider
- id: suppress_slider_sync - id: suppress_slider_sync
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
# actual 0..100 seen last time, for restart
- id: last_brightness_pct # actual 0..100 seen last time, for restart
- id: last_brightness_pct
type: float type: float
restore_value: true restore_value: true
initial_value: '0.0' initial_value: "0.0"
# last published "Output Set (0-100)" integer # last published "Output Set (0-100)" integer
- id: last_set_pos - id: last_set_pos
type: int type: int
restore_value: false restore_value: false
initial_value: '-1' initial_value: "-1"
# helper to keep blink time == transition time
# helper to keep blink time == transition time
- id: last_ramp_ms - id: last_ramp_ms
type: int type: int
restore_value: false restore_value: false
initial_value: '0' initial_value: "0"
# target for "Restore Brightness" scripted ramp # target for "Restore Brightness" scripted ramp
- id: restore_target_pct - id: restore_target_pct
type: float type: float
restore_value: false restore_value: false
initial_value: '0.0' initial_value: "0.0"
# true while a scripted ramp is in progress (to limit flash writes) # true while a scripted ramp is in progress (to limit flash writes)
- id: is_ramping - id: is_ramping
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
# guards OFF persistence during startup caused by restore_mode: ALWAYS_OFF # guards OFF persistence during startup caused by restore_mode: ALWAYS_OFF
- id: booting - id: booting
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'true' initial_value: "true"
# true only while we are performing a ramp-down that briefly turns the light ON to hit the floor # true only while we are performing a ramp-down that briefly turns the light ON to hit the floor
- id: ramping_for_off - id: ramping_for_off
type: bool type: bool
restore_value: false restore_value: false
initial_value: 'false' initial_value: "false"
########################################################################################## #:########################################################################################:#
# LOGGER COMPONENT # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
# Logs all log messages through the serial port and through MQTT topics. #:########################################################################################:#
##########################################################################################
logger: logger:
level: "${log_level}" # INFO Level suggested, or DEBUG for testing level: "${log_level}"
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) baud_rate: 0
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: ${device_status_led} number: ${device_status_led}
inverted: true inverted: true
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT: Device-specific command triggers
# This adds device-specific MQTT command triggers to the common MQTT configuration. #:########################################################################################:#
##########################################################################################
mqtt: mqtt:
on_message: on_message:
# Light control to ramp up # Light control to ramp up
@@ -338,18 +362,19 @@ mqtt:
payload: "${mqtt_local_device_command_ON}" payload: "${mqtt_local_device_command_ON}"
then: then:
- switch.turn_on: mosfet_ramp_switch - switch.turn_on: mosfet_ramp_switch
# Light control to ramp down # Light control to ramp down
- topic: "${mqtt_local_command_topic}/light/set" - topic: "${mqtt_local_command_topic}/light/set"
payload: "${mqtt_local_device_command_OFF}" payload: "${mqtt_local_device_command_OFF}"
then: then:
- switch.turn_off: mosfet_ramp_switch - switch.turn_off: mosfet_ramp_switch
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
switch: switch:
# Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce) # Ramp-aware ON/OFF for HA (asymmetric; no bounce)
- platform: template - platform: template
id: mosfet_ramp_switch id: mosfet_ramp_switch
name: "${friendly_name} Fade Up-Down" name: "${friendly_name} Fade Up-Down"
@@ -367,10 +392,10 @@ switch:
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
button: button:
# Start ramping UP (from current level) # Start ramping UP (from current level)
- platform: template - platform: template
@@ -402,15 +427,12 @@ button:
name: "${friendly_name} Fade Stop" name: "${friendly_name} Fade Stop"
icon: mdi:pause icon: mdi:pause
on_press: on_press:
# Stop any pending scripts (and their delayed actions)
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.stop: ramp_off_script - script.stop: ramp_off_script
- lambda: |- - lambda: |-
// We are no longer ramping (up or down)
id(ramping_for_off) = false; id(ramping_for_off) = false;
id(is_ramping) = false; id(is_ramping) = false;
// Freeze the light at its *current* level by overwriting the transition
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
auto call = id(mosfet_leds).make_call(); auto call = id(mosfet_leds).make_call();
@@ -420,18 +442,15 @@ button:
call.perform(); call.perform();
} }
// Persist the exact frozen level so restore survives a reboot
if (cv.is_on()) { if (cv.is_on()) {
float pct = cv.get_brightness() * 100.0f; float pct = cv.get_brightness() * 100.0f;
id(last_brightness_pct) = pct; id(last_brightness_pct) = pct;
} }
#:########################################################################################:#
# SELECT
#########################################################################################
# SELECT COMPONENT
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
######################################################################################### #:########################################################################################:#
select: select:
- platform: template - platform: template
id: restart_action id: restart_action
@@ -453,10 +472,10 @@ select:
id(restart_mode) = 2; id(restart_mode) = 2;
} }
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSOR
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
id: btn_gpio12 id: btn_gpio12
@@ -475,24 +494,22 @@ binary_sensor:
condition: condition:
lambda: 'return id(ramp_switch_target_on);' lambda: 'return id(ramp_switch_target_on);'
then: then:
# Target is currently ON -> press should go OFF (start ramp-down)
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
else: else:
# Target is currently OFF -> press should go ON (start ramp-up)
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
- script.stop: ramp_off_script - script.stop: ramp_off_script
- script.execute: ramp_on_script - script.execute: ramp_on_script
########################################################################################## #:########################################################################################:#
# SENSOR COMPONENT # SENSOR
# https://esphome.io/components/sensor/ # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
id: mosfet_output_pct id: mosfet_output_pct
@@ -500,17 +517,15 @@ sensor:
unit_of_measurement: "%" unit_of_measurement: "%"
icon: mdi:percent icon: mdi:percent
accuracy_decimals: 0 accuracy_decimals: 0
update_interval: 2s # consider 200ms if you want fewer updates update_interval: 2s
lambda: |- lambda: |-
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f; return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f;
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
// If not suppressing sync, update the 0..100 slider only when its INT changes
if (!id(suppress_slider_sync)) { if (!id(suppress_slider_sync)) {
float actual = x; // x is current Output (%) float actual = x;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; if (maxp <= minp) maxp = minp + 1.0f;
@@ -541,28 +556,26 @@ sensor:
if (pwm > 1.0f) pwm = 1.0f; if (pwm > 1.0f) pwm = 1.0f;
return pwm * 100.0f; return pwm * 100.0f;
########################################################################################## #:########################################################################################:#
# OUTPUT COMPONENT # OUTPUT
# https://esphome.io/components/light/index.html # https://esphome.io/components/output/
########################################################################################## #:########################################################################################:#
# An OUTPUT can be binary (0,1) or float, which is any value between 0 and 1.
# PWM Outputs such as "ledc" are float. https://esphome.io/components/output/ledc.html
##########################################################################################
output: output:
- platform: esp8266_pwm - platform: esp8266_pwm
id: mosfet_pwm id: mosfet_pwm
pin: ${device_mosfet_out} pin: ${device_mosfet_out}
frequency: ${pwm_frequency} frequency: ${pwm_frequency}
- platform: gpio - platform: gpio
id: green_led_out # Green LED id: green_led_out
pin: pin:
number: ${device_fading_led} number: ${device_fading_led}
inverted: false inverted: false
########################################################################################## #:########################################################################################:#
# LIGHT COMPONENT # LIGHT
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: monochromatic - platform: monochromatic
id: mosfet_leds id: mosfet_leds
@@ -573,7 +586,6 @@ light:
icon: mdi:led-strip-variant icon: mdi:led-strip-variant
gamma_correct: "${led_gamma}" gamma_correct: "${led_gamma}"
# ON: publish state, track intent, arm watchdog if configured
on_turn_on: on_turn_on:
- output.turn_on: green_led_out - output.turn_on: green_led_out
- mqtt.publish: - mqtt.publish:
@@ -581,7 +593,6 @@ light:
payload: "${mqtt_local_device_command_ON}" payload: "${mqtt_local_device_command_ON}"
retain: true retain: true
- lambda: |- - lambda: |-
// Do not flip "intent to ON" when we're inside an OFF ramp's floor-kick
if (!id(ramping_for_off)) { if (!id(ramping_for_off)) {
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
} }
@@ -592,8 +603,6 @@ light:
then: then:
- script.execute: max_on_watchdog - script.execute: max_on_watchdog
# OFF: publish state, track intent, clear watchdog, and persist OFF so Mode 1 will not restore
# Guarded by booting flag so the automatic OFF at boot from ALWAYS_OFF does not zero persistence.
on_turn_off: on_turn_off:
- output.turn_off: green_led_out - output.turn_off: green_led_out
- if: - if:
@@ -611,31 +620,29 @@ light:
id(last_set_pos) = 0; id(last_set_pos) = 0;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
# Cap brightness to max_brightness_pct without a visible step
on_state: on_state:
- lambda: |- - lambda: |-
const float cap = id(max_brightness_pct) / 100.0f; const float cap = id(max_brightness_pct) / 100.0f;
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (!cv.is_on()) return; if (!cv.is_on()) return;
const float b = cv.get_brightness(); const float b = cv.get_brightness();
if (b <= cap + 0.001f) return; // no call if already at/under cap if (b <= cap + 0.001f) return;
auto call = id(mosfet_leds).make_call(); auto call = id(mosfet_leds).make_call();
call.set_state(true); call.set_state(true);
call.set_brightness(cap); call.set_brightness(cap);
call.set_transition_length(0); call.set_transition_length(0);
call.perform(); call.perform();
#:########################################################################################:#
########################################################################################## # NUMBER
# NUMBER COMPONENT
# https://esphome.io/components/number/ # https://esphome.io/components/number/
########################################################################################## #:########################################################################################:#
number: number:
- platform: template - platform: template
id: cfg_ramp_up_s id: cfg_ramp_up_s
name: "${friendly_name} Fade Up Time (s)" name: "${friendly_name} Fade Up Time (s)"
entity_category: config entity_category: config
unit_of_measurement: s unit_of_measurement: "s"
icon: mdi:timer-sand icon: mdi:timer-sand
mode: slider mode: slider
min_value: 0 min_value: 0
@@ -655,7 +662,7 @@ number:
id: cfg_ramp_down_s id: cfg_ramp_down_s
name: "${friendly_name} Fade Down Time (s)" name: "${friendly_name} Fade Down Time (s)"
entity_category: config entity_category: config
unit_of_measurement: s unit_of_measurement: "s"
icon: mdi:timer-sand-complete icon: mdi:timer-sand-complete
mode: slider mode: slider
min_value: 0 min_value: 0
@@ -679,24 +686,22 @@ number:
min_value: 0 min_value: 0
max_value: 100 max_value: 100
step: 1 step: 1
# Show current position mapped into 0..100 across [min..max]
lambda: |- lambda: |-
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f; // 0..100 actual float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0 if (maxp <= minp) maxp = minp + 1.0f;
if (actual <= 0.0f) return 0.0f; // when OFF, show 0 if (actual <= 0.0f) return 0.0f;
float pos = (actual - minp) * 100.0f / (maxp - minp); float pos = (actual - minp) * 100.0f / (maxp - minp);
if (pos < 0.0f) pos = 0.0f; if (pos < 0.0f) pos = 0.0f;
if (pos > 100.0f) pos = 100.0f; if (pos > 100.0f) pos = 100.0f;
return floorf(pos + 0.5f); // integer return floorf(pos + 0.5f);
set_action: set_action:
- if: - if:
condition: condition:
lambda: 'return x <= 0.0f;' lambda: 'return x <= 0.0f;'
then: then:
# 0 means OFF
- lambda: 'id(suppress_slider_sync) = true;' - lambda: 'id(suppress_slider_sync) = true;'
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.stop: ramp_off_script - script.stop: ramp_off_script
@@ -706,16 +711,15 @@ number:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = false; id(ramp_switch_target_on) = false;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
id(last_brightness_pct) = 0.0f; // persist OFF immediately id(last_brightness_pct) = 0.0f;
id(last_set_pos) = 0; id(last_set_pos) = 0;
- delay: 400ms - delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;' - lambda: 'id(suppress_slider_sync) = false;'
else: else:
# Map 1..100 - [min..max] and set ON
- lambda: |- - lambda: |-
id(suppress_slider_sync) = true; id(suppress_slider_sync) = true;
float pos = x; // 0..100 float pos = x;
if (pos < 1.0f) pos = 1.0f; // 0 is OFF if (pos < 1.0f) pos = 1.0f;
if (pos > 100.0f) pos = 100.0f; if (pos > 100.0f) pos = 100.0f;
id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f)); id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f));
- script.stop: ramp_off_script - script.stop: ramp_off_script
@@ -723,7 +727,7 @@ number:
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
brightness: !lambda |- brightness: !lambda |-
float pos = id(led_output_set_pct).state; // 1..100 float pos = id(led_output_set_pct).state;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; if (maxp <= minp) maxp = minp + 1.0f;
@@ -733,13 +737,13 @@ number:
transition_length: 250ms transition_length: 250ms
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; id(ramp_switch_target_on) = true;
float pos = id(led_output_set_pct).state; // 1..100 float pos = id(led_output_set_pct).state;
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (maxp <= minp) maxp = minp + 1.0f; if (maxp <= minp) maxp = minp + 1.0f;
float out_pct = minp + (pos * (maxp - minp) / 100.0f); float out_pct = minp + (pos * (maxp - minp) / 100.0f);
if (out_pct > maxp) out_pct = maxp; if (out_pct > maxp) out_pct = maxp;
id(last_brightness_pct) = out_pct; // persist exact target now id(last_brightness_pct) = out_pct;
- delay: 400ms - delay: 400ms
- lambda: 'id(suppress_slider_sync) = false;' - lambda: 'id(suppress_slider_sync) = false;'
@@ -747,7 +751,7 @@ number:
id: cfg_max_on_hours id: cfg_max_on_hours
name: "${friendly_name} Max On (h)" name: "${friendly_name} Max On (h)"
entity_category: config entity_category: config
unit_of_measurement: h unit_of_measurement: "h"
icon: mdi:timer-cog icon: mdi:timer-cog
mode: slider mode: slider
min_value: 0 min_value: 0
@@ -758,7 +762,7 @@ number:
set_action: set_action:
- lambda: |- - lambda: |-
int hrs = (int) x; int hrs = (int) x;
if (hrs < 0) hrs = 0; if (hrs < 0) hrs = 0;
if (hrs > 48) hrs = 48; if (hrs > 48) hrs = 48;
id(max_on_hours) = hrs; id(max_on_hours) = hrs;
id(cfg_max_on_hours).publish_state((float) hrs); id(cfg_max_on_hours).publish_state((float) hrs);
@@ -773,20 +777,16 @@ number:
then: then:
- script.execute: max_on_watchdog - script.execute: max_on_watchdog
########################################################################################## #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call. #:########################################################################################:#
##########################################################################################
script: script:
# Script: ramp up from current level. Obey global max. (LED ON while ramping)
- id: ramp_on_script - id: ramp_on_script
mode: restart mode: restart
then: then:
- lambda: 'id(is_ramping) = true;' - lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script - script.stop: ramp_off_script
# Ensure we start at at least the floor without a visible "pop".
- if: - if:
condition: condition:
lambda: |- lambda: |-
@@ -798,7 +798,6 @@ script:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;' brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
transition_length: 80ms transition_length: 80ms
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(max_brightness_pct) / 100.0f;' brightness: !lambda 'return id(max_brightness_pct) / 100.0f;'
@@ -814,7 +813,7 @@ script:
id(last_ramp_ms) = id(ramp_up_ms); id(last_ramp_ms) = id(ramp_up_ms);
return (uint32_t) id(last_ramp_ms); return (uint32_t) id(last_ramp_ms);
} }
if (curr > cap) curr = cap; if (curr > cap) curr = cap;
if (curr < floor) curr = floor; if (curr < floor) curr = floor;
float frac = (cap - curr) / (cap - floor); float frac = (cap - curr) / (cap - floor);
if (frac < 0.0f) frac = 0.0f; if (frac < 0.0f) frac = 0.0f;
@@ -827,16 +826,14 @@ script:
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
float pct = cv.get_brightness() * 100.0f; float pct = cv.get_brightness() * 100.0f;
id(last_brightness_pct) = pct; // persist final level id(last_brightness_pct) = pct;
} }
# Script: ramp to a specific target (Restore Brightness path). (LED ON while ramping)
- id: ramp_to_target_script - id: ramp_to_target_script
mode: restart mode: restart
then: then:
- lambda: 'id(is_ramping) = true;' - lambda: 'id(is_ramping) = true;'
- script.stop: ramp_off_script - script.stop: ramp_off_script
# Ensure we start at the floor cleanly.
- if: - if:
condition: condition:
lambda: |- lambda: |-
@@ -848,7 +845,6 @@ script:
id: mosfet_leds id: mosfet_leds
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;' brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
transition_length: 80ms transition_length: 80ms
# Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms.
- light.turn_on: - light.turn_on:
id: mosfet_leds id: mosfet_leds
brightness: !lambda |- brightness: !lambda |-
@@ -870,7 +866,7 @@ script:
return (uint32_t) id(last_ramp_ms); return (uint32_t) id(last_ramp_ms);
} }
if (curr > cap) curr = cap; if (curr > cap) curr = cap;
if (curr < floor) curr = floor; if (curr < floor) curr = floor;
float frac = (cap - curr) / (cap - floor); float frac = (cap - curr) / (cap - floor);
if (frac < 0.0f) frac = 0.0f; if (frac < 0.0f) frac = 0.0f;
@@ -883,11 +879,9 @@ script:
const auto &cv = id(mosfet_leds).current_values; const auto &cv = id(mosfet_leds).current_values;
if (cv.is_on()) { if (cv.is_on()) {
float pct = cv.get_brightness() * 100.0f; float pct = cv.get_brightness() * 100.0f;
id(last_brightness_pct) = pct; // persist final level id(last_brightness_pct) = pct;
} }
# Script: ramp down from current level to floor, then cleanly cut to OFF. (LED ON while ramping)
- id: ramp_off_script - id: ramp_off_script
mode: restart mode: restart
then: then:
@@ -918,7 +912,7 @@ script:
- lambda: |- - lambda: |-
id(is_ramping) = false; id(is_ramping) = false;
id(ramping_for_off) = false; id(ramping_for_off) = false;
id(last_brightness_pct) = 0.0f; // persist OFF for restore path id(last_brightness_pct) = 0.0f;
id(last_set_pos) = 0; id(last_set_pos) = 0;
id(led_output_set_pct).publish_state(0); id(led_output_set_pct).publish_state(0);
@@ -940,20 +934,17 @@ script:
- script.stop: ramp_on_script - script.stop: ramp_on_script
- script.execute: ramp_off_script - script.execute: ramp_off_script
# Deferred restore to avoid early-boot races and ensure we apply the last saved level
- id: deferred_restore_brightness - id: deferred_restore_brightness
mode: restart mode: restart
then: then:
- delay: 5s # let preferences/globals load and light settle - delay: 5s
- lambda: |- - lambda: |-
// Use ONLY the exact last saved brightness.
float target = id(last_brightness_pct); float target = id(last_brightness_pct);
// Clamp into [min..max] only if we are restoring a non-zero target
float minp = (float) id(min_brightness_pct); float minp = (float) id(min_brightness_pct);
float maxp = (float) id(max_brightness_pct); float maxp = (float) id(max_brightness_pct);
if (target > 0.0f && target < minp) target = minp; if (target > 0.0f && target < minp) target = minp;
if (target > maxp) target = maxp; if (target > maxp) target = maxp;
id(restore_target_pct) = target; id(restore_target_pct) = target;
@@ -962,16 +953,14 @@ script:
lambda: 'return id(restore_target_pct) > 0.5f;' lambda: 'return id(restore_target_pct) > 0.5f;'
then: then:
- lambda: |- - lambda: |-
id(ramp_switch_target_on) = true; // reflect our intent id(ramp_switch_target_on) = true;
id(suppress_slider_sync) = true; id(suppress_slider_sync) = true;
- script.stop: ramp_off_script - script.stop: ramp_off_script
- script.execute: ramp_to_target_script - script.execute: ramp_to_target_script
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);' - delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
- lambda: 'id(suppress_slider_sync) = false;' - lambda: 'id(suppress_slider_sync) = false;'
else: else:
# Exact last was 0 -> remain OFF
- lambda: 'id(ramp_switch_target_on) = false;' - lambda: 'id(ramp_switch_target_on) = false;'
- light.turn_off: - light.turn_off:
id: mosfet_leds id: mosfet_leds
transition_length: 0s transition_length: 0s
# (Removed: output.turn_off: green_led_out) # make sure LED is off if no ramp
+101 -71
View File
@@ -1,53 +1,77 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS BATHROOM MAIN LIGHTSWITCH
# DOWNSTAIRS BATHROOM MAIN LIGHTSWITCH # zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstbathswitch.yaml
#:########################################################################################:#
# VERSIONS:
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
# V1.0 2025-02-14 Initial Version # V1.0 2025-02-14 Initial Version
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Triple push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Zemismart KS-811 Triple push button (KS-811-3)
# # pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
# NOTES #:########################################################################################:#
# - # OPERATION NOTES:
# # - Triple wall switch for Downstairs Bathroom
########################################################################################## # - Button 1 toggles Relay 1 (Main Lights)
########################################################################################## # - Button 2 toggles Relay 2 (Cabinet Light)
# - Button 3 controls Relay 3 (Extract Fan) using multi-click timing:
# - Single click: toggle, or run for 5 minutes then off
# - Double click: run for 30 minutes then off
# - Triple click: run for 4 hours then off
# - Hold (2s+): toggle permanently
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Switch continues operating locally (buttons drive relays)
# - If MQTT is used elsewhere in your system, this device itself does not require it for basic operation
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Switch continues operating locally (buttons drive relays)
# - HA can still control/read the relays via API
# c) Entire WiFi/Network OFFLINE
# - Switch continues operating locally (buttons drive relays)
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstbathswitch" device_name: "esp-downstbathswitch"
friendly_name: "Downstairs Bath Lightswitch (3)" friendly_name: "Downstairs Bath Lightswitch (3)"
description_comment: "Downstairs Bathroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Light (1), Cabinet Light (2), Extract Fan (3)" description_comment: "Downstairs Bathroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Light (1), Cabinet Light (2), Extract Fan (3) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Zemismart Technologies.KS-811 Triple" # Project Details
project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Project Naming
api_key: !secret esp-downstbathswitch_api_key # unfortunately you can't use substitutions inside secrets names project_name: "Zemismart Technologies.KS-811 Triple" # Project Details
ota_pass: !secret esp-downstbathswitch_ota_pass # unfortunately you can't use substitutions inside secrets names project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords (unfortunately you cannot use substitutions inside secrets names)
api_key: !secret esp-downstbathswitch_api_key
ota_pass: !secret esp-downstbathswitch_ota_pass
static_ip_address: !secret esp-downstbathswitch_ip static_ip_address: !secret esp-downstbathswitch_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# Switch Naming # Switch Naming
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
switch_2_name: "Cabinet Light" switch_2_name: "Cabinet Light"
switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -56,6 +80,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -69,65 +94,70 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}"
project:
name: "${project_name}"
version: "${project_version}"
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
########################################################################################## #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: True inverted: true
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
@@ -136,7 +166,7 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: Relay_2
@@ -145,10 +175,10 @@ binary_sensor:
pin: pin:
number: GPIO4 number: GPIO4
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 3: ${switch_3_name}" name: "Button 3: ${switch_3_name}"
on_multi_click: on_multi_click:
# Single click: 1 press relay on for 5 minutes # Single click: 1 press -> relay on for 5 minutes
- timing: - timing:
- ON for at most 0.5s - ON for at most 0.5s
- OFF for at least 0.5s - OFF for at least 0.5s
@@ -163,7 +193,7 @@ binary_sensor:
- delay: 5min - delay: 5min
- switch.turn_off: Relay_3 - switch.turn_off: Relay_3
# Double click: 2 presses relay on for 30 minutes # Double click: 2 presses -> relay on for 30 minutes
- timing: - timing:
- ON for at most 0.5s - ON for at most 0.5s
- OFF for at most 0.5s - OFF for at most 0.5s
@@ -180,7 +210,7 @@ binary_sensor:
- delay: 30min - delay: 30min
- switch.turn_off: Relay_3 - switch.turn_off: Relay_3
# Triple click: 3 presses relay on for 4 hours # Triple click: 3 presses -> relay on for 4 hours
- timing: - timing:
- ON for at most 0.5s - ON for at most 0.5s
- OFF for at most 0.5s - OFF for at most 0.5s
@@ -199,7 +229,7 @@ binary_sensor:
- delay: 4h - delay: 4h
- switch.turn_off: Relay_3 - switch.turn_off: Relay_3
# Hold: pressed for 1 second or more relay toggles permanently # Hold: pressed for 2 seconds or more -> relay toggles permanently
- timing: - timing:
- ON for at least 2s - ON for at least 2s
then: then:
@@ -211,22 +241,22 @@ binary_sensor:
else: else:
- switch.turn_on: Relay_3 - switch.turn_on: Relay_3
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: Relay_1
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: Relay_3
+146 -177
View File
@@ -1,15 +1,22 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS BATHROOM HEATED TOWEL RAIL
# DOWNSTAIRS BATHROOM HEATED TOWEL RAIL # zorruno.com layout v1.1 2026
# Controlled by a Sonoff Basic #:########################################################################################:#
# # REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstbathtowelrail.yaml
#:########################################################################################:#
# VERSIONS:
# V2.3 2026-02-25 Updated yaml to zorruno layout V1.1
# V2.2 2026-01-30 Added Morning/Evening Timer enable switches (gate timer windows) # V2.2 2026-01-30 Added Morning/Evening Timer enable switches (gate timer windows)
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost # V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
# V1.1 2025-04-12 Fixes to timers and offline modes # V1.1 2025-04-12 Fixes to timers and offline modes
# V1.0 2025-02-14 Initial Version # V1.0 2025-02-14 Initial Version
# #:########################################################################################:#
# INSTRUCTIONS # HARDWARE:
# Controlled by a Sonoff Basic
#:########################################################################################:#
# OPERATION NOTES:
# - It allows the device to work in a standalone timer style operation # - It allows the device to work in a standalone timer style operation
# - The timer has a morning and evening time (but no weekday/weekend settings) # - The timer has a morning and evening time (but no weekday/weekend settings)
# - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot) # - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot)
@@ -17,55 +24,68 @@
# - It uses SNTP for time setting (but obviously only if wifi & networking are working) # - It uses SNTP for time setting (but obviously only if wifi & networking are working)
# - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon) # - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon)
# - If on a network and there is a MQTT server, you can set the on/off times via MQTT (See below commands) # - If on a network and there is a MQTT server, you can set the on/off times via MQTT (See below commands)
# - You can set 4 modes ON/OFF/TIMER/BOOST via MQTT. Setting BOOST gives you a oneshot operation # - You can set 4 modes ON/OFF/TIMER/BOOST via MQTT. Setting BOOST gives you a oneshot operation
# - Any new timer times set via MQTT will be remembered though a reboot # - Any new timer times set via MQTT will be remembered though a reboot
# - On startup, or a reboot, the device will always turn on for the BOOST Duration (BOOST mode, default 2 hours) # - On startup, or a reboot, the device will always turn on for the BOOST Duration (BOOST mode, default 2 hours)
# - TIMER mode will always be switched on after BOOST mode is complete # - TIMER mode will always be switched on after BOOST mode is complete
# - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown # - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot) # - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot)
# #:########################################################################################:#
# MQTT Commands # MQTT COMMANDS:
# Values will be set in place on the update_interval time, not immediately # Values will be set in place on the update_interval time, not immediately
# Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting) # Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting)
# mqtt_timer_topic/morning-on/06:00 : Time device will go on # mqtt_timer_topic/morning-on/06:00 : Time device will go on
# mqtt_timer_topic/morning-off/08:00 : Time device will go off # mqtt_timer_topic/morning-off/08:00 : Time device will go off
# mqtt_timer_topic/evening-on/09:00 : Time device will go on # mqtt_timer_topic/evening-on/09:00 : Time device will go on
# mqtt_timer_topic/evening-off/00:00 : Time device will go off # mqtt_timer_topic/evening-off/00:00 : Time device will go off
# mqtt_timer_topic/boost-time/0000 : Time in minutes device will temporarily go on for (1-1439) # mqtt_timer_topic/boost-time/0000 : Time in minutes device will temporarily go on for (1-1439)
# mqtt_timer_topic/operation/ON : Device permanently on # mqtt_timer_topic/operation/ON : Device permanently on
# mqtt_timer_topic/operation/OFF : Device permanently off # mqtt_timer_topic/operation/OFF : Device permanently off
# mqtt_timer_topic/operation/TIMER : Device will obey timer settings # mqtt_timer_topic/operation/TIMER : Device will obey timer settings
# mqtt_timer_topic/operation/BOOST : Turn on for (boost_duration) minutes then BOOST (also on startup) # mqtt_timer_topic/operation/BOOST : Turn on for (boost_duration) minutes then BOOST (also on startup)
# #
# operation_mode: # operation_mode:
# 0 = OFF # 0 = OFF
# 1 = ON # 1 = ON
# 2 = TIMER # 2 = TIMER
# 3 = BOOST # 3 = BOOST
# #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - The towel rail will stick to its assigned schedule (and should remember on reboot)
# - Schedule times and on/off switching can still occur via MQTT
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - With no MQTT automation controllers, the towel rail will still run its timer logic locally
# - If internet/wifi is still available, timing will be accurate (SNTP)
# c) Entire WiFi/Network OFFLINE
# - The towel rail will still run its timer logic locally, however timing will likely shift without SNTP
# - Timeclocks will drift without network (SNTP). Time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstbathtowelrail" device_name: "esp-downstbathtowelrail"
friendly_name: "Downstairs Bathroom Towelrail" friendly_name: "Downstairs Bathroom Towelrail"
description_comment: "Heated Towel Rail, Downstairs Bathroom :: Sonoff Basic" description_comment: "Heated Towel Rail, Downstairs Bathroom :: Sonoff Basic (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
project_version: "v2.2" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v2.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Passwords (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-downstbathtowelrail_ip static_ip_address: !secret esp-downstbathtowelrail_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
relay_icon: "mdi:heating-coil" relay_icon: "mdi:heating-coil"
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
@@ -73,18 +93,16 @@ substitutions:
# Timer Settings # Timer Settings
mqtt_timer_topic: "viewroad-commands/downstbath-towelrail" # Topics you will use to change stuff mqtt_timer_topic: "viewroad-commands/downstbath-towelrail" # Topics you will use to change stuff
boost_duration_default: "120" # Minutes to stay ON in BOOST mode before reverting to TIMER boost_duration_default: "120" # Minutes to stay ON in BOOST mode before reverting to TIMER
morning_on_default: "420" # Default in minutes from midnight. Default 07:00 => 420 morning_on_default: "420" # Default in minutes from midnight. Default 07:00 => 420
morning_off_default: "450" # Default in minutes from midnight. Default 07:30 => 450 morning_off_default: "450" # Default in minutes from midnight. Default 07:30 => 450
evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260 evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260
evening_off_default: "1320" # Default in minutes from midnight. Default 22:00 => 1320 => 1440 is midnight evening_off_default: "1320" # Default in minutes from midnight. Default 22:00 => 1320
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -93,6 +111,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -111,31 +130,34 @@ packages:
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
project:
name: "${project_name}"
version: "${project_version}"
platformio_options: platformio_options:
build_flags: build_flags:
- "-Os" # optimize for size - "-Os" # optimize for size
- "-Wl,--gc-sections" # drop unused code/data - "-Wl,--gc-sections" # drop unused code/data
#- "-fno-exceptions" # strip C++ exceptions #- "-fno-exceptions" # strip C++ exceptions
#- "-fno-rtti" # strip C++ RTTI #- "-fno-rtti" # strip C++ RTTI
on_boot: on_boot:
priority: 900 # High priority to run after globals are initialized priority: 900 # High priority to run after globals are initialized
then: then:
# This evaluates if we switch on 4+ times in 20 seconds # This evaluates if we switch on 4+ times in 20 seconds
# If so, just change to on mode permanently. # If so, just change to on mode permanently.
@@ -176,15 +198,16 @@ esphome:
id(boost_timer) = 0; // and reset boost_timer = 0 (for time sync if no sntp) id(boost_timer) = 0; // and reset boost_timer = 0 (for time sync if no sntp)
ESP_LOGI("power_cycle", "Boot count=%d => BOOST mode", id(boot_count)); ESP_LOGI("power_cycle", "Boot count=%d => BOOST mode", id(boot_count));
} }
- script.execute: evaluate_relay_state # Check what the relay should be doing straight away - script.execute: evaluate_relay_state # Check what the relay should be doing straight away
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
############################################# # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m # The original sonoff basic
restore_from_flash: True # restore some values on reboot restore_from_flash: true # restore some values on reboot
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
@@ -192,21 +215,21 @@ preferences:
mdns: mdns:
disabled: true disabled: true
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
#################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
# Relay Switch (Sonoff Basic Relay on GPIO12) # Relay Switch (Sonoff Basic Relay on GPIO12)
#################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Towel Rail Power" name: "Towel Rail Power"
@@ -242,12 +265,11 @@ switch:
on_turn_off: on_turn_off:
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
########################################################################################## #:########################################################################################:#
# Global Variables for use in automations etc # GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/guides/automations.html#global-variables
########################################################################################## #:########################################################################################:#
globals: globals:
# Tracks the time (in seconds from midnight) at the previous boot # Tracks the time (in seconds from midnight) at the previous boot
- id: last_boot_time_s - id: last_boot_time_s
type: int type: int
@@ -260,31 +282,31 @@ globals:
restore_value: true restore_value: true
initial_value: "0" initial_value: "0"
# Morning On time (minutes from midnight), # Morning On time (minutes from midnight)
- id: morning_on - id: morning_on
type: int type: int
restore_value: true restore_value: true
initial_value: "${morning_on_default}" initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight), # Morning Off time (minutes from midnight)
- id: morning_off - id: morning_off
type: int type: int
restore_value: true restore_value: true
initial_value: "${morning_off_default}" initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight), # Evening On time (minutes from midnight)
- id: evening_on - id: evening_on
type: int type: int
restore_value: true restore_value: true
initial_value: "${evening_on_default}" initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight), # Evening Off time (minutes from midnight)
- id: evening_off - id: evening_off
type: int type: int
restore_value: true restore_value: true
initial_value: "${evening_off_default}" initial_value: "${evening_off_default}"
# Boost Duration (minutes), # Boost Duration (minutes)
- id: boost_duration - id: boost_duration
type: int type: int
restore_value: true restore_value: true
@@ -312,18 +334,16 @@ globals:
restore_value: false restore_value: false
initial_value: "0" initial_value: "0"
########################################################################################## #:########################################################################################:#
# Text Sensors # TEXT SENSORS:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
############################
# MQTT Subscriptions
############################
############################
# MQTT Subscriptions
############################
############################
# Morning On time => "HH:MM" # Morning On time => "HH:MM"
############################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Morning On Time Setting" name: "Morning On Time Setting"
id: morning_on_topic id: morning_on_topic
@@ -340,9 +360,7 @@ text_sensor:
ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str());
} }
############################
# Morning Off time => "HH:MM" # Morning Off time => "HH:MM"
############################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Morning Off Time Setting" name: "Morning Off Time Setting"
id: morning_off_topic id: morning_off_topic
@@ -359,9 +377,7 @@ text_sensor:
ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str());
} }
############################
# Evening On time => "HH:MM" # Evening On time => "HH:MM"
############################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Evening On Time Setting" name: "Evening On Time Setting"
id: evening_on_topic id: evening_on_topic
@@ -378,9 +394,7 @@ text_sensor:
ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str());
} }
############################
# Evening Off time => "HH:MM" # Evening Off time => "HH:MM"
############################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Evening Off Time Setting" name: "Evening Off Time Setting"
id: evening_off_topic id: evening_off_topic
@@ -397,9 +411,7 @@ text_sensor:
ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str());
} }
############################
# Boost duration => integer minutes (1-1439) # Boost duration => integer minutes (1-1439)
############################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Boost Duration" name: "Boost Duration"
id: boost_time_topic id: boost_time_topic
@@ -409,7 +421,6 @@ text_sensor:
then: then:
- lambda: |- - lambda: |-
int v = 0; int v = 0;
// Parse as integer
if (sscanf(x.c_str(), "%d", &v) == 1 && v >= 1 && v <= 1439) { if (sscanf(x.c_str(), "%d", &v) == 1 && v >= 1 && v <= 1439) {
id(boost_duration) = v; id(boost_duration) = v;
ESP_LOGI("boost_time","Received new Boost Duration: %d mins", v); ESP_LOGI("boost_time","Received new Boost Duration: %d mins", v);
@@ -417,9 +428,7 @@ text_sensor:
ESP_LOGW("boost_time","Invalid boost_time '%s'", x.c_str()); ESP_LOGW("boost_time","Invalid boost_time '%s'", x.c_str());
} }
####################################################
# Subscribe to operation mode: OFF, ON, TIMER, BOOST # Subscribe to operation mode: OFF, ON, TIMER, BOOST
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
id: timer_operation_mode_topic id: timer_operation_mode_topic
topic: "${mqtt_timer_topic}/operation" topic: "${mqtt_timer_topic}/operation"
@@ -427,14 +436,12 @@ text_sensor:
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
// Check only the first character for mode
char c = x.c_str()[0]; char c = x.c_str()[0];
if (c == 'T') { // "TIMER" if (c == 'T') {
id(operation_mode) = 2; id(operation_mode) = 2;
} else if (c == 'O') { // "ON" or "OFF" } else if (c == 'O') {
// second letter N->ON, F->OFF
id(operation_mode) = (x.size() > 1 && x[1] == 'N') ? 1 : 0; id(operation_mode) = (x.size() > 1 && x[1] == 'N') ? 1 : 0;
} else if (c == 'B') { // "BOOST" } else if (c == 'B') {
id(operation_mode) = 3; id(operation_mode) = 3;
id(boost_timer) = 0; id(boost_timer) = 0;
} else { } else {
@@ -442,13 +449,10 @@ text_sensor:
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
######################################################
# Expose the current operation mode (OFF, ON, TIMER, BOOST) # Expose the current operation mode (OFF, ON, TIMER, BOOST)
######################################################
- platform: template - platform: template
name: "Operation Mode State" name: "Operation Mode State"
lambda: |- lambda: |-
// 0=OFF, 1=ON, 2=TIMER, 3=BOOST
switch (id(operation_mode)) { switch (id(operation_mode)) {
case 0: return {"OFF"}; case 0: return {"OFF"};
case 1: return {"ON"}; case 1: return {"ON"};
@@ -458,66 +462,54 @@ text_sensor:
} }
update_interval: 5s update_interval: 5s
######################################################
# Expose the "Morning On" time as a text (HH:MM) # Expose the "Morning On" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Morning On Time" name: "Timeclock: Morning On Time"
lambda: |- lambda: |-
int hour = id(morning_on) / 60; int hour = id(morning_on) / 60;
int minute = id(morning_on) % 60; int minute = id(morning_on) % 60;
// Increase to 16 for safety
char buff[16]; char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Morning Off" time as a text (HH:MM) # Expose the "Morning Off" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Morning Off Time" name: "Timeclock: Morning Off Time"
lambda: |- lambda: |-
int hour = id(morning_off) / 60; int hour = id(morning_off) / 60;
int minute = id(morning_off) % 60; int minute = id(morning_off) % 60;
// Increase to 16 for safety
char buff[16]; char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Evening On" time as a text (HH:MM) # Expose the "Evening On" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Evening On Time" name: "Timeclock: Evening On Time"
lambda: |- lambda: |-
int hour = id(evening_on) / 60; int hour = id(evening_on) / 60;
int minute = id(evening_on) % 60; int minute = id(evening_on) % 60;
// Increase to 16 for safety
char buff[16]; char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Evening Off" time as a text (HH:MM) # Expose the "Evening Off" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Evening Off Time" name: "Timeclock: Evening Off Time"
lambda: |- lambda: |-
int hour = id(evening_off) / 60; int hour = id(evening_off) / 60;
int minute = id(evening_off) % 60; int minute = id(evening_off) % 60;
// Increase to 16 for safety
char buff[16]; char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute); snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
@@ -534,11 +526,9 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay).state) { if (id(relay).state) {
// Relay is ON: turn it OFF and set mode to 0 (TIMER)
id(relay).turn_off(); id(relay).turn_off();
id(operation_mode) = 2; id(operation_mode) = 2;
} else { } else {
// Relay is OFF: turn it ON and set mode to 3 (BOOST)
id(relay).turn_on(); id(relay).turn_on();
id(operation_mode) = 3; id(operation_mode) = 3;
} }
@@ -548,16 +538,16 @@ binary_sensor:
lambda: |- lambda: |-
return id(relay).state; return id(relay).state;
########################################################################################## #:########################################################################################:#
# Sensors # SENSORS:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
name: "Timeclock: Boost Duration" name: "Timeclock: Boost Duration"
id: boost_duration_time id: boost_duration_time
unit_of_measurement: "mins" unit_of_measurement: "mins"
accuracy_decimals: "0" accuracy_decimals: 0
update_interval: "${update_interval}" update_interval: "${update_interval}"
lambda: |- lambda: |-
return id(boost_duration); return id(boost_duration);
@@ -566,9 +556,9 @@ sensor:
name: "Mins from Midnight" name: "Mins from Midnight"
id: mins_from_midnight id: mins_from_midnight
unit_of_measurement: "mins" unit_of_measurement: "mins"
accuracy_decimals: "0" accuracy_decimals: 0
update_interval: "${update_interval}" update_interval: "${update_interval}"
internal: True # No need to show this in Home Assistant internal: true
lambda: |- lambda: |-
return id(current_mins); return id(current_mins);
@@ -578,41 +568,35 @@ sensor:
id: timer_minutes_remaining id: timer_minutes_remaining
unit_of_measurement: "Mins" unit_of_measurement: "Mins"
update_interval: 5s update_interval: 5s
accuracy_decimals: "0" accuracy_decimals: 0
lambda: |- lambda: |-
// always zero if relay is off
if (!id(relay).state) { if (!id(relay).state) {
return 0; return 0;
} }
int rem = 0; int rem = 0;
// only calculate for mode 2 (scheduled) or mode 3 (BOOST)
if (id(operation_mode) == 2) { if (id(operation_mode) == 2) {
int a = id(morning_off) - id(current_mins); int a = id(morning_off) - id(current_mins);
int b = id(evening_off) - id(current_mins); int b = id(evening_off) - id(current_mins);
// if a is negative, use b; otherwise pick the smaller of a or b
rem = (a < 0) ? b : (a < b ? a : b); rem = (a < 0) ? b : (a < b ? a : b);
} }
else if (id(operation_mode) == 3) { else if (id(operation_mode) == 3) {
rem = id(boost_duration) - id(boost_timer); rem = id(boost_duration) - id(boost_timer);
} }
// never return negative
return rem > 0 ? rem : 0; return rem > 0 ? rem : 0;
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/
################################################################################################# #:########################################################################################:#
button: button:
- platform: template - platform: template
name: "Boost now" name: "Boost now"
id: boost_button id: boost_button
icon: "mdi:play-circle-outline" icon: "mdi:play-circle-outline"
on_press: on_press:
# 1) reset BOOST timer and set mode
- lambda: |- - lambda: |-
id(boost_timer) = 0; id(boost_timer) = 0;
id(operation_mode) = 3; id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
- platform: template - platform: template
@@ -621,25 +605,22 @@ button:
icon: "mdi:restore" icon: "mdi:restore"
on_press: on_press:
- lambda: |- - lambda: |-
// Restore all timing globals to their YAML defaults id(morning_on) = ${morning_on_default};
id(morning_on) = ${morning_on_default}; id(morning_off) = ${morning_off_default};
id(morning_off) = ${morning_off_default}; id(evening_on) = ${evening_on_default};
id(evening_on) = ${evening_on_default}; id(evening_off) = ${evening_off_default};
id(evening_off) = ${evening_off_default}; id(boost_duration) = ${boost_duration_default};
id(boost_duration)= ${boost_duration_default}; id(operation_mode) = 2;
// Reset mode to TIMER and clear any running boost id(boost_timer) = 0;
id(operation_mode)= 2;
id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied"); ESP_LOGI("timer","Default timer settings applied");
# Restore timer enable switches to ON (defaults)
- switch.turn_on: morning_timer_enable - switch.turn_on: morning_timer_enable
- switch.turn_on: evening_timer_enable - switch.turn_on: evening_timer_enable
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/
################################################################################################# #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Operation Mode" name: "Operation Mode"
@@ -650,8 +631,6 @@ select:
- "ON" - "ON"
- "TIMER" - "TIMER"
- "BOOST" - "BOOST"
# show the current mode
lambda: |- lambda: |-
switch (id(operation_mode)) { switch (id(operation_mode)) {
case 1: return std::string("ON"); case 1: return std::string("ON");
@@ -659,43 +638,37 @@ select:
case 3: return std::string("BOOST"); case 3: return std::string("BOOST");
default: return std::string("OFF"); default: return std::string("OFF");
} }
# when changed in HA, set mode & re-evaluate
set_action: set_action:
- lambda: |- - lambda: |-
if (x == "OFF") { id(operation_mode) = 0; } if (x == "OFF") { id(operation_mode) = 0; }
else if (x == "ON") { id(operation_mode) = 1; } else if (x == "ON") { id(operation_mode) = 1; }
else if (x == "TIMER") { id(operation_mode) = 2; } else if (x == "TIMER") { id(operation_mode) = 2; }
else { // BOOST else {
id(boost_timer) = 0; id(boost_timer) = 0;
id(operation_mode) = 3; id(operation_mode) = 3;
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
################################################################################################# #:########################################################################################:#
# Script: evaluate and drive the relay
script: script:
- id: evaluate_relay_state - id: evaluate_relay_state
then: then:
- lambda: |- - lambda: |-
int mode = id(operation_mode); int mode = id(operation_mode);
// BOOST just forces the relay on
if (mode == 3) { if (mode == 3) {
id(relay).turn_on(); id(relay).turn_on();
return; return;
} }
// OFF -> always off
if (mode == 0) { if (mode == 0) {
id(relay).turn_off(); id(relay).turn_off();
return; return;
} }
// ON -> always on
if (mode == 1) { if (mode == 1) {
id(relay).turn_on(); id(relay).turn_on();
return; return;
@@ -705,14 +678,12 @@ script:
{ {
bool should_on = false; bool should_on = false;
// Morning window only applies when Morning Timer Enable is enabled
if (id(morning_timer_enable).state) { if (id(morning_timer_enable).state) {
if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) { if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) {
should_on = true; should_on = true;
} }
} }
// Evening window only applies when Evening Timer Enable is enabled
if (id(evening_timer_enable).state) { if (id(evening_timer_enable).state) {
if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off)) { if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off)) {
should_on = true; should_on = true;
@@ -723,16 +694,15 @@ script:
else id(relay).turn_off(); else id(relay).turn_off();
} }
################################################################################################# #:########################################################################################:#
# INTERVAL COMPONENT # INTERVAL COMPONENT:
# https://esphome.io/components/interval.html # https://esphome.io/components/interval.html
################################################################################################# #:########################################################################################:#
# Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state
interval: interval:
- interval: "1min" - interval: "1min"
then: then:
- lambda: |- - lambda: |-
// - update current_mins via SNTP or fallback // update current_mins via SNTP or fallback
if (!id(sntp_time).now().is_valid()) { if (!id(sntp_time).now().is_valid()) {
id(current_mins)++; id(current_mins)++;
if (id(current_mins) >= 1440) id(current_mins) = 0; if (id(current_mins) >= 1440) id(current_mins) = 0;
@@ -741,12 +711,11 @@ interval:
id(current_mins) = now.hour * 60 + now.minute; id(current_mins) = now.hour * 60 + now.minute;
} }
// - if in BOOST, advance boost_timer and expire when done // if in BOOST, advance boost_timer and expire when done
if (id(operation_mode) == 3) { if (id(operation_mode) == 3) {
id(boost_timer)++; id(boost_timer)++;
if (id(boost_timer) >= id(boost_duration)) { if (id(boost_timer) >= id(boost_duration)) {
id(operation_mode) = 2; id(operation_mode) = 2;
//id(mqtt_client).publish("${mqtt_timer_topic}/operation", "TIMER");
} }
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
+81 -112
View File
@@ -1,62 +1,71 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS BEDROOM 2 LIGHTSWITCH
# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH # zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstbedrm2lights.yaml
#:########################################################################################:#
# VERSIONS:
# V3.6 2026-02-25 Updated yaml to zorruno layout V1.1
# V3.5 2025-07-24 YAML tidyups # V3.5 2025-07-24 YAML tidyups
########################################################################################## #:########################################################################################:#
# Zemismart KS-811 Single push button # HARDWARE:
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # Controlled by a Zemismart KS-811 Single push button
# # pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
# NOTES #:########################################################################################:#
# - # OPERATION NOTES:
# # - Single-button wall switch controlling a single relay output.
########################################################################################## # - Button press toggles the relay state (Main Lights).
########################################################################################## # - KS-811-1 button input is GPIO0 (note: boot-strap pin).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - The device will keep operating locally (button still toggles the relay).
# - MQTT may still function (if used elsewhere), but HA entities will be unavailable until HA returns.
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - The device remains controllable from Home Assistant via API.
# - Local button control continues to work.
# c) Entire WiFi/Network OFFLINE
# - The device continues to operate locally (button toggles relay).
# - SNTP is not needed (no timeclocks used).
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstbedrm2lights" device_name: "esp-downstbedrm2lights"
friendly_name: "Downstairs Bedroom 2 Lightswitch (1)" friendly_name: "Downstairs Bedroom 2 Lightswitch (1)"
description_comment: "Downstairs Bedroom 2 Main Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1)" description_comment: "Downstairs Bedroom 2 Main Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Single" # Project Details project_name: "Zemismart Technologies.KS-811 Single" # Project Details
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.6" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-downstbedrm2lights_ip static_ip_address: !secret esp-downstbedrm2lights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for for general sensors etc
# MQTT LOCAL Controls
#mqtt_device_name: "downst-bedroom2-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 REMOTE Controls
# Switch/Relay/Button Naming & Icons # Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group" #relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
#switch_2_name: "Nil"
#switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -65,6 +74,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -78,23 +88,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -103,96 +113,55 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing 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) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# GPIO16 for KS-811 first button UNLESS # GPIO16 for KS-811 first button UNLESS it is a single button KS-811 in which case it is GPIO00
# it is a single button KS-811 in which case it is GPIO00
- platform: gpio - platform: gpio
pin: pin:
number: GPIO0 number: GPIO0
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: relay_1
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) #:########################################################################################:#
# - platform: gpio # SWITCH COMPONENT:
# pin:
# number: GPIO05
# mode: INPUT
# inverted: True
# name: "Button 2: ${switch_2_name}"
# on_press:
# - switch.toggle: Relay_2
# GPIO04 for third button (only for KS-811-3 Triple)
# - platform: gpio
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
# GPIO13 for KS-811 first button UNLESS it is KS-811-1 then it is GIPO12 # GPIO13 for KS-811 first relay UNLESS it is KS-811-1 then it is GPIO12
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO12 pin: GPIO12
id: Relay_1 id: relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
# - platform: gpio
# name: "Relay 2: ${switch_2_name}"
# pin: GPIO12
# id: Relay_2
# GPIO14 for third relay (only for KS-811-3 Triple)
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3
+95 -61
View File
@@ -1,49 +1,79 @@
############################################# #:########################################################################################:#
############################################# # TITLE: DOWNSTAIRS KITCHEN MAIN LIGHTSWITCH
# DOWNSTAIRS KITCHEN MAIN LIGHTSWITCH # zorruno.com layout v1.1 2026
# V2.0 2025-06-05 YAML tidyups #:########################################################################################:#
# V1.0 2025-03-28 Initial Version # REPO:
############################################# # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstkitchlights.yaml
# Zemismart KS-811 Triple push button #:########################################################################################:#
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # VERSIONS:
# # v2.1 2026-02-25 Updated yaml to zorruno layout V1.1
# NOTES # v2.0 2025-06-05 YAML tidyups
# - # v1.0 2025-03-28 Initial Version
# #:########################################################################################:#
############################################# # HARDWARE:
############################################# # - Zemismart KS-811 Triple push button (ESP8266)
# - ESP8266 board: esp01_1m
# - Pinout/schematic:
# https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Downstairs Kitchen main lightswitch (3-gang logical)
# - Relay 1: Dining Light
# - Relay 2: Kitchen Light
# - Relay 3: Extract Fan (virtual only, no power connected to 3rd relay)
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Physical buttons continue to toggle relays
# - MQTT (if used) continues to work
# - HA API is unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Physical buttons continue to toggle relays
# - HA API control continues to work (if enabled)
# - MQTT features will not work while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - Physical buttons continue to toggle relays
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstkitchlights" device_name: "esp-downstkitchlights"
friendly_name: "Downstairs Kitchen Lightswitch (3)" friendly_name: "Downstairs Kitchen Lightswitch (3)"
description_comment: "Downstairs Kitch Main Lightswitch using a Zemismart KS-811 Triple Push Button. Dining Light (1), Kitchen Light (2), Extract Fan (3)" description_comment: "Downstairs Kitch Main Lightswitch using a Zemismart KS-811 Triple Push Button. Dining Light (1), Kitchen Light (2), Extract Fan (3) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Passwords # Project Naming
project_name: "Zemismart Technologies.KS-811 Triple"
project_version: "v2.1"
# Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-downstkitchlights_ip static_ip_address: !secret esp-downstkitchlights_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# Switch Naming # Switch Naming
switch_1_name: "Dining Light" switch_1_name: "Dining Light"
switch_2_name: "Kitchen Light" switch_2_name: "Kitchen Light"
switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -52,6 +82,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -65,66 +96,69 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: ${device_name} name: "${device_name}"
friendly_name: ${friendly_name} friendly_name: "${friendly_name}"
comment: ${description_comment} # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: ${device_area} area: "${device_area}"
project:
name: "${project_name}"
version: "${project_version}"
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
############################################# #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
############################################# #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
############################################# #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
############################################# #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: yes
############################################# #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
############################################# #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: True
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # This pin doesn't support interrupts so use polling. Only suppresses a warning.
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
@@ -147,22 +181,22 @@ binary_sensor:
on_press: on_press:
- switch.toggle: Relay_3 - switch.toggle: Relay_3
############################################# #:########################################################################################:#
# SWITCH COMPONENT # SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
############################################# #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: Relay_1
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: Relay_3
+101 -109
View File
@@ -1,31 +1,65 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS LOUNGE ENTRY LIGHTSWITCH
# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.6 2025-07-24 YAML tidyups #:########################################################################################:#
########################################################################################## # REPO:
# Zemismart KS-811 Single push button # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstloungeentry.yaml
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ #:########################################################################################:#
# VERSIONS:
# v3.7 2026-02-25 Updated yaml to zorruno layout V1.1
# v3.6 2025-07-24 YAML tidyups
#:########################################################################################:#
# HARDWARE:
# - Zemismart KS-811 Single push button (ESP8266)
# - ESP8266 board: esp01_1m
# - Pinout/schematic:
# https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - This KS-811 single button is used as a remote MQTT controller (no physical load connected).
# - Button press publishes MQTT to toggle a remote device light (based on our mirrored Relay_1 state).
# - Relay_1 is used as a mirrored state holder only (kept in sync via the remote device status topic).
#:########################################################################################:#
# MQTT COMMANDS:
# - Remote command topic:
# ${mqtt_remote_device_command_topic}
# Payloads:
# ${mqtt_remote_device_command_on}
# ${mqtt_remote_device_command_off}
# #
# NOTES # - Remote status topic (mirrors remote state to Relay_1):
# - # ${mqtt_remote_status_topic}
# # Expected payloads:
########################################################################################## # ${mqtt_remote_device_command_on}
########################################################################################## # ${mqtt_remote_device_command_off}
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Button continues to control the remote device via MQTT (broker must be reachable)
# - Relay_1 mirror continues to update from the remote status topic
# b) MQTT OFFLINE (or broker unreachable)
# - Button presses cannot control the remote device (publish fails)
# - Relay_1 mirror will not update (no remote status updates)
# c) Entire WiFi/Network OFFLINE
# - No remote control possible (MQTT unavailable)
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstloungeentry" device_name: "esp-downstloungeentry"
friendly_name: "Downstairs Lounge Entry Lightswitch (1)" friendly_name: "Downstairs Lounge Entry Lightswitch (1)"
description_comment: "Downstairs Lounge Entry Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1)" description_comment: "Downstairs Lounge Entry Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Single" # Project Details project_name: "Zemismart Technologies.KS-811 Single"
project_version: "v3.6" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.7"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
@@ -34,35 +68,28 @@ substitutions:
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
# Device Settings # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE # Don't forget to switch it back when changed.
update_interval: "60s" # update time for for general sensors etc current_ip_address: ${static_ip_address}
# MQTT LOCAL Controls # Device Settings
#mqtt_device_name: "downst-lounge-entry-light" log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
#mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA update_interval: "60s" # update time for general sensors etc
#mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# MQTT REMOTE Controls # MQTT REMOTE Controls
mqtt_remote_device_name: "downst-lounge-main-lights" mqtt_remote_device_name: "downst-lounge-main-lights"
mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/light1/set" mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/light1/set"
mqtt_remote_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/light1/state" # Topic we will use to view status locally without HA mqtt_remote_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/light1/state"
mqtt_remote_device_command_on: "On" mqtt_remote_device_command_on: "On"
mqtt_remote_device_command_off: "Off" mqtt_remote_device_command_off: "Off"
# Switch/Relay/Button Naming & Icons # Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights" # NOTE there is no physical connection to the lights on this switch switch_1_name: "Main Lights" # NOTE there is no physical connection to the lights on this switch
#switch_2_name: "Nil"
#switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -71,6 +98,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -84,23 +112,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -109,70 +137,68 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT: Device-specific MQTT command triggers
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Mirror remote state onto Relay_1 (only toggle if a change is needed)
- topic: "${mqtt_remote_status_topic}" - topic: "${mqtt_remote_status_topic}"
payload: "${mqtt_remote_device_command_on}" payload: "${mqtt_remote_device_command_on}"
then: then:
- delay: 50ms - delay: 50ms
- if: - if:
condition: condition:
lambda: 'return !id(Relay_1).state;' # Only turn on if currently OFF lambda: 'return !id(Relay_1).state;'
then: then:
- switch.turn_on: Relay_1 - switch.turn_on: Relay_1
- topic: "${mqtt_remote_status_topic}" - topic: "${mqtt_remote_status_topic}"
payload: "${mqtt_remote_device_command_off}" payload: "${mqtt_remote_device_command_off}"
then: then:
- delay: 50ms - delay: 50ms
- if: - if:
condition: condition:
lambda: 'return id(Relay_1).state;' # Only turn off if currently ON lambda: 'return id(Relay_1).state;'
then: then:
- switch.turn_off: Relay_1 - switch.turn_off: Relay_1
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO02
inverted: yes inverted: yes
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# GPIO16 for KS-811 first button UNLESS it is KS-811-1 in which case it is GPIO00 # GPIO16 for KS-811 first button UNLESS it is KS-811-1 in which case it is GPIO00
- platform: gpio - platform: gpio
pin: pin:
number: GPIO0 number: GPIO0
@@ -189,47 +215,13 @@ binary_sensor:
return "${mqtt_remote_device_command_on}"; return "${mqtt_remote_device_command_on}";
} }
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) #:########################################################################################:#
# - platform: gpio # SWITCH
# pin:
# number: GPIO05
# mode: INPUT
# inverted: True
# name: "Button 2: ${switch_2_name}"
# on_press:
# - switch.toggle: Relay_2
# GPIO04 for third button (only for KS-811-3 Triple)
# - platform: gpio
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
# GPIO13 for KS-811 first button UNLESS it is KS-811-1 then it is GPIO12 # GPIO13 for KS-811 first button UNLESS it is KS-811-1 then it is GPIO12
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO12 pin: GPIO12
id: Relay_1 id: Relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
# - platform: gpio
# name: "Relay 2: ${switch_2_name}"
# pin: GPIO12
# id: Relay_2
# GPIO14 for third relay (only for KS-811-3 Triple)
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3
+117 -105
View File
@@ -1,60 +1,95 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS LOUNGE MAIN LIGHTS
# DOWNSTAIRS LOUNGE MAIN LIGHTS # zorruno.com layout v1.1 2026
# V3.5 2025-07-28 YAML tidyups #:########################################################################################:#
########################################################################################## # REPO:
# Zemismart KS-811 Triple push button # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstloungemain.yaml
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ #:########################################################################################:#
# VERSIONS:
# v3.6 2026-02-25 Updated yaml to zorruno layout V1.1
# v3.5 2025-07-28 YAML tidyups
#:########################################################################################:#
# HARDWARE:
# - Zemismart KS-811 Triple push button (ESP8266)
# - Pinout/Schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - 3-gang KS-811 triple switch.
# - Button 1 toggles Relay 1 (Main Lights). Relay 1 also supports local MQTT ON/OFF commands.
# - Relay 1 publishes MQTT state updates on turn on/off.
# - Button 2 toggles Relay 2 (Back Wall Lights).
# - Button 3 toggles Relay 3 (Spare). NOTE: nothing connected to this output (as noted).
# - GPIO16 does not support interrupts; polling is used for Button 1 (suppresses warning).
#:########################################################################################:#
# MQTT COMMANDS:
# - Local command topic (Main Lights):
# ${mqtt_local_command_topic}/light1/set
# Payload "On" -> Relay 1 ON
# Payload "Off" -> Relay 1 OFF
# #
# NOTES # - Local status topic (Main Lights):
# - # ${mqtt_local_status_topic}/light1/state
# Payload "On" / "Off" published when Relay 1 changes state
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Physical buttons still control relays locally.
# - MQTT local control still works if broker is reachable.
# #
########################################################################################## # b) MQTT OFFLINE (or broker unreachable)
########################################################################################## # - Physical buttons still control relays locally.
# - HA/API control (if available) still works, but no MQTT command/status.
#
# c) Entire WiFi/Network OFFLINE
# - Physical buttons still control relays locally.
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstloungemain" device_name: "esp-downstloungemain"
friendly_name: "Downstairs Lounge Main Lightswitch (3)" friendly_name: "Downstairs Lounge Main Lightswitch (3)"
description_comment: "Downstairs Bedroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Back Wall Lights (2), Spare (3)" description_comment: "Downstairs Bedroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Back Wall Lights (2), Spare (3) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat"
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Triple" # Project Details project_name: "Zemismart Technologies.KS-811 Triple"
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.6"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-downstloungemain_ip static_ip_address: !secret esp-downstloungemain_ip
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO"
update_interval: "60s" # update time for for general sensors etc update_interval: "60s"
# MQTT LOCAL Controls # MQTT LOCAL Controls
mqtt_device_name: "downst-lounge-main-lights" mqtt_device_name: "downst-lounge-main-lights"
mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}"
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}"
# MQTT REMOTE Controls # Switch/Relay/Button Naming
# Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
switch_2_name: "Back Wall Lights" switch_2_name: "Back Wall Lights"
switch_3_name: "Spare" # NOTE, Nothing connected to this switch output switch_3_name: "Spare" # NOTE, Nothing connected to this switch output
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -63,6 +98,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -76,135 +112,114 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" 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 #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}"
area: "${device_area}" area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false
board_flash_mode: dout # Default is dout board_flash_mode: dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT: Device-specific MQTT command triggers
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Light control # Main Lights control (Relay 1)
- topic: "${mqtt_local_command_topic}/light1/set" - topic: "${mqtt_local_command_topic}/light1/set"
payload: "On" payload: "On"
then: then:
- switch.turn_on: Relay_1 - switch.turn_on: relay_1
- topic: "${mqtt_local_command_topic}/light1/set" - topic: "${mqtt_local_command_topic}/light1/set"
payload: "Off" payload: "Off"
then: then:
- switch.turn_off: Relay_1 - switch.turn_off: relay_1
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# GPIO16 for KS-811 first button UNLESS # Button 1 (GPIO16) - polling (GPIO16 has no interrupts)
# it is a single button KS-811 in which case it is GPIO00
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: relay_1
# - mqtt.publish:
# topic: "${mqtt_local_command_topic}"
# payload: !lambda |-
# if (id(Relay_1).state) {
# return "${mqtt_local_command_off}";
# } else {
# return "${mqtt_local_command_on}";
# }
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) # Button 2 (GPIO05)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: relay_2
# GPIO04 for third button (only for KS-811-3 Triple) # Button 3 (GPIO04)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO4 number: GPIO4
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 3: ${switch_3_name}" name: "Button 3: ${switch_3_name}"
on_press: on_press:
- switch.toggle: Relay_3 - switch.toggle: relay_3
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
# GPIO13 for KS-811 first button UNLESS it is KS-811-1 then it is GIPO12 # Relay 1 (GPIO13) + publish MQTT status
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: relay_1
# publish status updates when the light turns on/off:
on_turn_on: on_turn_on:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_local_status_topic}/light1/state" topic: "${mqtt_local_status_topic}/light1/state"
@@ -214,17 +229,14 @@ switch:
topic: "${mqtt_local_status_topic}/light1/state" topic: "${mqtt_local_status_topic}/light1/state"
payload: "Off" payload: "Off"
# Relay 2 (GPIO12)
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: relay_2
# GPIO14 for third relay (only for KS-811-3 Triple) # Relay 3 (GPIO14)
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: relay_3
+91 -104
View File
@@ -1,60 +1,76 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS LOUNGE OUTSIDE LIGHTS
# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.5 2025-07-24 YAML tidyups #:########################################################################################:#
########################################################################################## # REPO:
# Zemismart KS-811 Double push button # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstloungeoutside.yaml
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ #:########################################################################################:#
# VERSIONS:
# v3.6 2026-02-25 Updated yaml to zorruno layout V1.1
# v3.5 2025-07-24 YAML tidyups
#:########################################################################################:#
# HARDWARE:
# - Zemismart KS-811 Double push button (ESP8266)
# - Pinout/Schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - 2-gang KS-811 double switch.
# - Button 1 toggles Relay 1 (Outside Lights).
# - Button 2 toggles Relay 2 (Spare).
# - GPIO16 does not support interrupts; polling is used for Button 1 (suppresses warning).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Physical buttons still control relays locally.
# - MQTT is optional; device operates as a normal switch without HA.
# #
# NOTES # b) MQTT OFFLINE (or broker unreachable)
# - # - Physical buttons still control relays locally.
# - HA/API control (if available) still works, but no MQTT command/status.
# #
########################################################################################## # c) Entire WiFi/Network OFFLINE
########################################################################################## # - Physical buttons still control relays locally.
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstloungeoutside" device_name: "esp-downstloungeoutside"
friendly_name: "Downstairs Lounge Outside Lights (2)" friendly_name: "Downstairs Lounge Outside Lights (2)"
description_comment: "Downstairs Lounge Outside Lightswitch using a Zemismart KS-811 Double Push Button. Outside Lights (1), Spare (2)" description_comment: "Downstairs Lounge Outside Lightswitch using a Zemismart KS-811 Double Push Button. Outside Lights (1), Spare (2) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat"
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Triple" # Project Details project_name: "Zemismart Technologies.KS-811 Double"
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.6"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-downstloungeoutside_ip static_ip_address: !secret esp-downstloungeoutside_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO"
update_interval: "60s" # update time for for general sensors etc update_interval: "60s"
# MQTT LOCAL Controls # Switch/Relay/Button Naming
#mqtt_device_name: "downst-bedroom2-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 REMOTE Controls
# Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Outside Lights" switch_1_name: "Outside Lights"
switch_2_name: "Spare" switch_2_name: "Spare"
#switch_3_name: "Nil" #switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -63,6 +79,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -76,121 +93,91 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" 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 #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}"
area: "${device_area}" area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false
board_flash_mode: dout # Default is dout board_flash_mode: dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# GPIO16 for KS-811 first button UNLESS # Button 1 (GPIO16) - polling (GPIO16 has no interrupts)
# it is a single button KS-811 in which case it is GPIO00
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: relay_1
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) # Button 2 (GPIO05)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: relay_2
# GPIO04 for third button (only for KS-811-3 Triple) #:########################################################################################:#
# - platform: gpio # SWITCH
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
# GPIO13 for KS-811 first button # Relay 1 (GPIO13)
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple) # Relay 2 (GPIO12)
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: relay_2
# GPIO14 for third relay (only for KS-811-3 Triple)
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3
+99 -89
View File
@@ -1,62 +1,77 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: DOWNSTAIRS MASTER BEDROOM 1 LIGHTS
# DOWNSTAIRS MASTER BEDROOM 1 LIGHTS # zorruno.com layout v1.1 2026
# V3.5 2025-07-24 YAML tidyups #:########################################################################################:#
########################################################################################## # REPO:
# Zemismart KS-811 Triple push button # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstmasterbedrmlights.yaml
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ #:########################################################################################:#
# # VERSIONS:
# NOTES # v3.6 2026-02-25 Updated yaml to zorruno layout V1.1
# - # v3.5 2025-07-24 YAML tidyups
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # - Zemismart KS-811 Triple push button (ESP8266)
# - ESP8266 board: esp01_1m
# - Pinout/schematic:
# https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Downstairs Master Bedroom 1 main lightswitch using a KS-811 (triple style device).
# - Intended circuits:
# 1) Main Lights (Relay 1 / Button 1)
# 2) Wardrobe Lights (Relay 2 / Button 2)
# 3) Spare (not configured in this YAML; commented sections provided)
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Local button control continues to toggle relays.
# - MQTT/API publishing to HA may not be available until HA returns.
# b) MQTT OFFLINE (or broker unreachable)
# - Local button control continues to toggle relays.
# - MQTT state updates (if any) will not publish.
# c) Entire WiFi/Network OFFLINE
# - Local button control continues to toggle relays.
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-downstmasterbedrmlights" device_name: "esp-downstmasterbedrmlights"
friendly_name: "Downstairs Master Bedroom 1 Lightswitch (2)" friendly_name: "Downstairs Master Bedroom 1 Lightswitch (2)"
description_comment: "Downstairs Master Bedroom 1 Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Wardrobe Lights (2), Spare (3)" description_comment: "Downstairs Master Bedroom 1 Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Wardrobe Lights (2), Spare (3) (Layout V1.1)"
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double"
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.6"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-downstmasterbedrmlights_ip static_ip_address: !secret esp-downstmasterbedrmlights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT LOCAL Controls
#mqtt_device_name: "downst-bedroom2-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 REMOTE Controls
# Switch/Relay/Button Naming & Icons # Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
switch_2_name: "Wardrobe Lights" switch_2_name: "Wardrobe Lights"
#switch_3_name: "Spare" #switch_3_name: "Spare"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -65,6 +80,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -78,23 +94,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -103,56 +119,52 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO02 number: GPIO02
inverted: yes inverted: yes
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# GPIO16 for KS-811 first button # GPIO16 for KS-811 first button
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: True
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only suppresses a warning.
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple) # GPIO05 for second button (only for KS-811-2 Double or -3 Triple)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO05 number: GPIO05
@@ -162,37 +174,35 @@ binary_sensor:
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: Relay_2
# GPIO04 for third button (only for KS-811-3 Triple) # GPIO04 for third button (only for KS-811-3 Triple)
# - platform: gpio # - platform: gpio
# pin: # pin:
# number: GPIO4 # number: GPIO4
# mode: INPUT # mode: INPUT
# inverted: True # inverted: True
# name: "Button 3: ${switch_3_name}" # name: "Button 3: ${switch_3_name}"
# on_press: # on_press:
# - switch.toggle: Relay_3 # - switch.toggle: Relay_3
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
# GPIO13 for KS-811 first relay # GPIO13 for KS-811 first relay
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: Relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple) # GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
# GPIO14 for third relay (only for KS-811-3 Triple) # GPIO14 for third relay (only for KS-811-3 Triple)
# - platform: gpio # - platform: gpio
# name: "Relay 3: ${switch_3_name}" # name: "Relay 3: ${switch_3_name}"
# pin: GPIO14 # pin: GPIO14
# id: Relay_3 # id: Relay_3
+90 -64
View File
@@ -1,35 +1,66 @@
############################################# #:########################################################################################:#
############################################# # TITLE: OUTSIDE ENTRANCE BLUETOOTH PROXY
# ESP32 # zorruno.com layout v1.1 2026
# Bluetooth Proxy #:########################################################################################:#
############################################# # REPO:
############################################# # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-entbtproxy.yaml
#:########################################################################################:#
# VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 Unknown Initial version
#:########################################################################################:#
# HARDWARE:
# - D1 Mini ESP32 (ESP32)
#:########################################################################################:#
# OPERATION NOTES:
# - Bluetooth Proxy for ESPHome / Home Assistant (BLE tracking + proxy)
# - Uses ESP-IDF framework for stability and (often) smaller binary size
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - BLE scanning/proxy continues running
# - HA entities unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - BLE scanning/proxy continues running
# - MQTT features (if any) will not function until MQTT returns
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - BLE scanning continues locally, but proxy functions needing network will not be usable
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
############################################# #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming
device_name: "esp-entbtproxy" device_name: "esp-entbtproxy"
friendly_name: "Outside Entrance Bluetooth Proxy" friendly_name: "Outside Entrance Bluetooth Proxy"
description_comment: "D1 Mini ESP32 outside entranceway with BT Proxy" description_comment: "D1 Mini ESP32 outside entranceway with BT Proxy (Layout V1.1)"
api_key: !secret esp-entbtproxy_api_key #unfortunately you can't use substitutions in secrets names device_area: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
ota_pass: !secret esp-entbtproxy_ota_pass #unfortunately you can't use substitutions in secrets names
# Project Naming
project_name: "Generic.ESP32 Bluetooth Proxy"
project_version: "v1.1"
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-entbtproxy_api_key
ota_pass: !secret esp-entbtproxy_ota_pass
static_ip_address: !secret esp-entbtproxy_ip static_ip_address: !secret esp-entbtproxy_ip
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
room: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
############################################# # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# SPECIFIC PROJECT VARIABLE SUBSTITUTIONS # Don't forget to switch it back when changed.
############################################# current_ip_address: ${static_ip_address}
#
#
########################################################################################## # Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for general sensors etc
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -38,6 +69,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -51,68 +83,62 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_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
min_version: 2024.6.0 #
############################################# #:########################################################################################:#
# ESP Platform and Framework # 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
area: "${device_area}"
min_version: 2024.6.0
project:
name: "${project_name}"
version: "${project_version}"
#:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
############################################# #:########################################################################################:#
esp32: esp32:
board: esp32dev board: esp32dev
framework: framework:
#type: arduino type: esp-idf # Suggested ESP-IDF framework
type: esp-idf #Suggested Use ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang. version: recommended
version: recommended #recommended, latest or dev
advanced: advanced:
minimum_chip_revision: "3.1" # This makes the binary slightly smaller minimum_chip_revision: "3.1" # This makes the binary slightly smaller
############################################# #:########################################################################################:#
# ESPHome Logging Enable # LOGGING:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART if you want
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
############################################# #:########################################################################################:#
# Bluetooth # BLUETOOTH:
# https://esphome.io/components/bluetooth_proxy.html # https://esphome.io/components/bluetooth_proxy.html
# https://esphome.io/components/esp32_ble_tracker.html # https://esphome.io/components/esp32_ble_tracker.html
# Remember that this takes a LOT of processing. On the #:########################################################################################:#
# ESP32, enable the IDF framework, and disable the
# Web server component. Changing to the IDF framework
# needs to be via cable not OTA to change the
# partition setup.
#############################################
bluetooth_proxy: bluetooth_proxy:
active: true active: true
esp32_ble_tracker: esp32_ble_tracker:
scan_parameters: scan_parameters:
# We currently use the defaults to ensure Bluetooth # Defaults used so Bluetooth can co-exist with WiFi
# can co-exist with WiFi In the future we may be able to active: true
# enable the built-in coexistence logic in ESP-IDF
active: true
+336 -271
View File
@@ -1,53 +1,92 @@
############################################# #:########################################################################################:#
############################################# # TITLE: OUTSIDE ENTRANCE MULTISENSOR
# # zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-entmulti.yaml
#:########################################################################################:#
# VERSIONS:
# V1.2 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.1 2026-02-23
# - Add full header + project metadata block
# - Fix LD2140 -> LD2410 typos throughout
# - Normalize booleans and tidy naming consistency
# - Prefix LD2410 entity names with friendly name for cleaner HA entities
# - Add LD2410 buttons (factory reset/restart/query) + text sensors (fw version/bt mac)
# - Add composite Occupancy sensor (mmWave OR PIR) with delayed-off
# - Correct UART comments (LD2410 uses 256000 baud out-of-box in ESPHome)
# V1.0 2026-02-xx Initial version (as provided)
#:########################################################################################:#
# HARDWARE:
# - D1 Mini ESP32 (ESP32)
# - HI-LINK LD2410 mmWave presence sensor (UART)
# - PIR sensor on GPIO13
# - 2x RF vibration inputs (bins) on GPIO4 and GPIO15
# #
############################################# # NOTES:
############################################# # - ESPHome 2026.1+ requires API encryption and OTA SHA256 authentication.
# Ensure your common package files are updated accordingly.
# - LD2410 via ESPHome uses 256000 baud by default; parity NONE, stop_bits 1.
# - GPIO2/GPIO15 are strapping pins on ESP32. You are already suppressing warnings,
# but be aware boot behavior can be affected by external circuitry on these pins.
#:########################################################################################:#
# OPERATION NOTES:
# - Provides LD2410 presence (moving/still/target), plus PIR motion and 2x vibration inputs.
# - Composite Occupancy sensor is mmWave OR PIR with delayed-off for stable lighting triggers.
# - Device is sensor-driven only (no timeclocks); SNTP is optional for diagnostics/time entities.
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Sensors continue running locally
# - MQTT (if enabled/online) continues publishing; HA entities unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Sensors remain available to Home Assistant via API
# - MQTT-based automations/commands will not work while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT
# - Sensors continue running locally; automation depends on local logic only
# - Accurate time is NOT needed (SNTP not needed); loss of network does not affect timing
#:########################################################################################:#
############################################# #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming
device_name: "esp-entmulti" device_name: "esp-entmulti"
friendly_name: "Outside Entrance Multisensor" friendly_name: "Outside Entrance Multisensor"
description_comment: "D1 Mini ESP32 outside entranceway with, mmWave presence, PIR and more" description_comment: "D1 Mini ESP32 outside entranceway with mmWave presence, PIR and more (Layout V1.1)"
api_key: !secret esp-entmulti_api_key #unfortunately you can't use substitutions in secrets names device_area: "Entranceway" # Allows ESP device to be automatically linked to an Area in Home Assistant.
ota_pass: !secret esp-entmulti_ota_pass #unfortunately you can't use substitutions in secrets names
static_ip_address: !secret esp-entmulti_ip
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_time: 30s #update time for for general temp sensors etc
update_interval: "60s" # update time for for general sensors etc
room: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
############################################# # Project Naming (shown in ESPHome dashboard / HA device info)
# SPECIFIC PROJECT VARIABLE SUBSTITUTIONS project_name: "zorruno.esp-entmulti"
############################################# project_version: "v1.2"
#
#
#if NOT using a secrets file, just replace these with the passwords etc (in quotes) # Passwords & Secrets
#wifi_ssid: !secret wifi_ssid api_key: !secret esp-entmulti_api_key
#wifi_password: !secret wifi_password ota_pass: !secret esp-entmulti_ota_pass
#fallback_ap_password: !secret fallback_ap_password static_ip_address: !secret esp-entmulti_ip # unfortunately you can't use substitutions inside secrets names
#Add these if we are giving it a static ip, or remove them in the Wifi section mqtt_command_main_topic: !secret mqtt_command_main_topic
#static_ip_address: !secret esp-entmulti_static_ip mqtt_status_main_topic: !secret mqtt_status_main_topic
#static_ip_gateway: !secret esp-entmulti_gateway
#static_ip_subnet: !secret esp-entmulti_subnet
#mqtt_server: !secret mqtt_server # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
#mqtt_username: !secret mqtt_username # Don't forget to switch it back when changed.
#mqtt_password: !secret mqtt_password current_ip_address: ${static_ip_address}
#mqtt_topic: "esphome" #main topic for the mqtt server, call it what you like
#web_server_username: !secret web_server_username # MQTT LOCAL Controls (default to this device name to avoid accidental cross-device topics)
#web_server_password: !secret web_server_password #mqtt_local_device_name: "${device_name}"
#mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}"
#mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}"
########################################################################################## # Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
update_interval: "60s" # general sensor update interval (if/when used)
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -56,6 +95,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -69,378 +109,403 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: ${device_name} name: "${device_name}"
friendly_name: ${friendly_name} friendly_name: "${friendly_name}"
comment: ${description_comment} #appears on the esphome page in HA comment: "${description_comment}" # appears on the ESPHome page in HA
min_version: 2024.6.0 area: "${device_area}"
project:
name: "${project_name}"
version: "${project_version}"
min_version: 2026.2.0
#:########################################################################################:#
############################################# # ESP PLATFORM AND FRAMEWORK:
# ESP Platform and Framework
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
############################################# #:########################################################################################:#
esp32: esp32:
board: esp32dev board: esp32dev
framework: framework:
#type: arduino #type: arduino
type: esp-idf #Suggested Use ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang. type: esp-idf
version: recommended #recommended, latest or dev version: recommended
############################################# #:########################################################################################:#
# ESPHome external or custom components to use # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/external_components.html
# https://github.com/ssieb/esphome_components/tree/master/components/serial
#############################################
#external_components:
# - source:
# type: git
# url: https://github.com/ssieb/custom_components #Thanks for @ssieb components.
# components: [ serial ] #text_sensor that reads lines for a uart. Also, a sensor that reads single binary values from the uart.
#############################################
# ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0 # set to 0 for no logging via UART (keeps UART free for sensors)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
############################################# #:########################################################################################:#
# i2c bus # UART: LD2410 Serial
# https://esphome.io/components/i2c.html
# 10, 50, 100, 200, 800 are possible settings
# for frequency, 50kHz is default
#############################################
#i2c:
# sda: GPIO19
# scl: GPIO21
# scan: True #look for devices on boot up and report
#frequency: 100kHz
#############################################
# UART Serial
# hardware on EPS32, but software, and can be glitchy on ESP8266
# https://esphome.io/components/uart.html # https://esphome.io/components/uart.html
############################################# #:########################################################################################:#
uart: uart:
id: ld2410_uart id: ld2410_uart
rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang rx_pin: GPIO16
tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17
baud_rate: 256000 # default for LD2410 is 25600, 8, 0, NONE baud_rate: 256000
data_bits: 8 data_bits: 8
stop_bits: 1 stop_bits: 1
parity: NONE parity: NONE
############################################# #:########################################################################################:#
# Bluetooth # STATUS LED:
# https://esphome.io/components/bluetooth_proxy.html
# https://esphome.io/components/esp32_ble_tracker.html
# Remember that this takes a LOT of processing. On the
# ESP32, enable the IDF framework, and disable the
# Web server component. Changing to the IDF framework
# needs to be via cable not OTA to change the
# partition setup.
#############################################
#bluetooth_proxy:
# active: true
# cache_services: true
#
#esp32_ble_tracker:
# scan_parameters:
# active: true
# continuous: false
#############################################
# Global Variables for use in automations etc
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
#############################################
#############################################
# General esp status LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
############################################# #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 #ESP32 Onboard LED number: GPIO2
ignore_strapping_warning: True #https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins ignore_strapping_warning: true
inverted: false inverted: false
############################################# #:########################################################################################:#
# Interval Automations # LD2410:
# https://esphome.io/guides/automations.html
#############################################
#############################################
# LD2410 Sensors
# https://esphome.io/components/sensor/ld2410.html # https://esphome.io/components/sensor/ld2410.html
# https://www.hlktech.net/index.php?id=988 #:########################################################################################:#
#############################################
ld2410: ld2410:
id: ld2410_1
uart_id: ld2410_uart uart_id: ld2410_uart
############################################# #:########################################################################################:#
# Number Sensors (custom component) # NUMBER:
# refer https://github.com/ssieb/esphome_components/tree/master/components/serial # https://esphome.io/components/number/
############################################# #:########################################################################################:#
number: number:
- platform: ld2410 - platform: ld2410
ld2410_id: ld2410_1
timeout: timeout:
name: Timeout name: "${friendly_name} LD2410 Timeout"
entity_category: config
light_threshold: light_threshold:
name: Light Threshold name: "${friendly_name} LD2410 Light Threshold"
entity_category: config
max_move_distance_gate: max_move_distance_gate:
name: Max Move Distance Gate name: "${friendly_name} LD2410 Max Move Distance Gate"
entity_category: config
max_still_distance_gate: max_still_distance_gate:
name: Max Still Distance Gate name: "${friendly_name} LD2410 Max Still Distance Gate"
entity_category: config
g0: g0:
move_threshold: move_threshold:
name: g0 move threshold name: "${friendly_name} LD2410 G0 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g0 still threshold name: "${friendly_name} LD2410 G0 Still Threshold"
entity_category: config
g1: g1:
move_threshold: move_threshold:
name: g1 move threshold name: "${friendly_name} LD2410 G1 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g1 still threshold name: "${friendly_name} LD2410 G1 Still Threshold"
entity_category: config
g2: g2:
move_threshold: move_threshold:
name: g2 move threshold name: "${friendly_name} LD2410 G2 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g2 still threshold name: "${friendly_name} LD2410 G2 Still Threshold"
entity_category: config
g3: g3:
move_threshold: move_threshold:
name: g3 move threshold name: "${friendly_name} LD2410 G3 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g3 still threshold name: "${friendly_name} LD2410 G3 Still Threshold"
entity_category: config
g4: g4:
move_threshold: move_threshold:
name: g4 move threshold name: "${friendly_name} LD2410 G4 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g4 still threshold name: "${friendly_name} LD2410 G4 Still Threshold"
entity_category: config
g5: g5:
move_threshold: move_threshold:
name: g5 move threshold name: "${friendly_name} LD2410 G5 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g5 still threshold name: "${friendly_name} LD2410 G5 Still Threshold"
entity_category: config
g6: g6:
move_threshold: move_threshold:
name: g6 move threshold name: "${friendly_name} LD2410 G6 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g6 still threshold name: "${friendly_name} LD2410 G6 Still Threshold"
entity_category: config
g7: g7:
move_threshold: move_threshold:
name: g7 move threshold name: "${friendly_name} LD2410 G7 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g7 still threshold name: "${friendly_name} LD2410 G7 Still Threshold"
entity_category: config
g8: g8:
move_threshold: move_threshold:
name: g8 move threshold name: "${friendly_name} LD2410 G8 Move Threshold"
entity_category: config
still_threshold: still_threshold:
name: g8 still threshold name: "${friendly_name} LD2410 G8 Still Threshold"
entity_category: config
#The ld2410 select allows you to control your LD2410 Sensor. #:########################################################################################:#
#distance_resolution (Optional): Control the gates distance resolution. Can be 0.75m or 0.2m. Defaults to 0.75m. All options from Select. # SELECT:
#baud_rate (Optional): Control the serial port baud rate. Defaults to 256000. Once changed, all sensors will stop working until a fresh install with an updated UART Component configuration. All options from Select. # https://esphome.io/components/select/index.html
#light_function (Optional): If set, will affect the OUT pin value, based on light threshold. Can be off, low or above. Defaults to off. All options from Select. #:########################################################################################:#
#out_pin_level (Optional): Control OUT pin away value. Can be low or high. Defaults to low. All options from Select.
#ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component if you are using multiple components.
select: select:
- platform: ld2410 - platform: ld2410
distance_resolution: ld2410_id: ld2410_1
name: ${friendly_name} LD2140 Distance Resolution
distance_resolution:
name: "${friendly_name} LD2410 Distance Resolution"
entity_category: config
baud_rate: baud_rate:
name: ${friendly_name} LD2140 Baud Rate name: "${friendly_name} LD2410 Baud Rate"
entity_category: config
light_function: light_function:
name: ${friendly_name} LD2140 Light Function name: "${friendly_name} LD2410 Light Function"
entity_category: config
out_pin_level: out_pin_level:
name: ${friendly_name} LD2140 Out Pin Level name: "${friendly_name} LD2410 Out Pin Level"
entity_category: config
############################################# #:########################################################################################:#
# General Sensors # SENSOR:
# https://esphome.io/components/sensor/index.html # https://esphome.io/components/sensor/
############################################# #:########################################################################################:#
sensor: sensor:
# - platform: bme280_i2c
# address: 0x76
# update_interval: ${update_time}
# temperature:
# name: ${friendly_name} BME280 Temp
# accuracy_decimals: 1
# oversampling: 2x
# pressure:
# name: ${friendly_name} BME280 Pressure
# oversampling: 2x
# humidity:
# name: ${friendly_name} BME280 Humidity
# accuracy_decimals: 1
# oversampling: 2x
#The ld2410 sensor values
- platform: ld2410 - platform: ld2410
ld2410_id: ld2410_1
light: light:
name: Light name: "${friendly_name} LD2410 Light"
entity_category: diagnostic
moving_distance: moving_distance:
name : Moving Distance name: "${friendly_name} LD2410 Moving Distance"
entity_category: diagnostic
still_distance: still_distance:
name: Still Distance name: "${friendly_name} LD2410 Still Distance"
entity_category: diagnostic
moving_energy: moving_energy:
name: Move Energy name: "${friendly_name} LD2410 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: Still Energy name: "${friendly_name} LD2410 Still Energy"
entity_category: diagnostic
detection_distance: detection_distance:
name: Detection Distance name: "${friendly_name} LD2410 Detection Distance"
entity_category: diagnostic
g0: g0:
move_energy: move_energy:
name: g0 move energy name: "${friendly_name} LD2410 G0 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g0 still energy name: "${friendly_name} LD2410 G0 Still Energy"
entity_category: diagnostic
g1: g1:
move_energy: move_energy:
name: g1 move energy name: "${friendly_name} LD2410 G1 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g1 still energy name: "${friendly_name} LD2410 G1 Still Energy"
entity_category: diagnostic
g2: g2:
move_energy: move_energy:
name: g2 move energy name: "${friendly_name} LD2410 G2 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g2 still energy name: "${friendly_name} LD2410 G2 Still Energy"
entity_category: diagnostic
g3: g3:
move_energy: move_energy:
name: g3 move energy name: "${friendly_name} LD2410 G3 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g3 still energy name: "${friendly_name} LD2410 G3 Still Energy"
entity_category: diagnostic
g4: g4:
move_energy: move_energy:
name: g4 move energy name: "${friendly_name} LD2410 G4 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g4 still energy name: "${friendly_name} LD2410 G4 Still Energy"
entity_category: diagnostic
g5: g5:
move_energy: move_energy:
name: g5 move energy name: "${friendly_name} LD2410 G5 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g5 still energy name: "${friendly_name} LD2410 G5 Still Energy"
entity_category: diagnostic
g6: g6:
move_energy: move_energy:
name: g6 move energy name: "${friendly_name} LD2410 G6 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g6 still energy name: "${friendly_name} LD2410 G6 Still Energy"
entity_category: diagnostic
g7: g7:
move_energy: move_energy:
name: g7 move energy name: "${friendly_name} LD2410 G7 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g7 still energy name: "${friendly_name} LD2410 G7 Still Energy"
entity_category: diagnostic
g8: g8:
move_energy: move_energy:
name: g8 move energy name: "${friendly_name} LD2410 G8 Move Energy"
entity_category: diagnostic
still_energy: still_energy:
name: g8 still energy name: "${friendly_name} LD2410 G8 Still Energy"
entity_category: diagnostic
# The ld2410 switch allows you to control your LD2410 Sensor. #:########################################################################################:#
#Bluetooth switch is only useful of you have a B or C model # SWITCH:
# https://esphome.io/components/switch/
#:########################################################################################:#
switch: switch:
- platform: ld2410 - platform: ld2410
ld2410_id: ld2410_1
engineering_mode: engineering_mode:
name: ${friendly_name} LD2140 Engineering Mode name: "${friendly_name} LD2410 Engineering Mode"
entity_category: config
# Only useful if you have a B/C model (bluetooth hardware present)
#bluetooth: #bluetooth:
#name: ${friendly_name} LD2140 Control Bluetooth # name: "${friendly_name} LD2410 Bluetooth Enable"
# entity_category: config
#The ld2410 button allows resetting
#button:
# - platform: ld2410
# factory_reset:
# name: ${friendly_name} LD2140 Factory reset"
# restart:
# name: ${friendly_name} LD2140 Restart
## query_params:
# name: Query Parameters
#############################################
# Text Sensors
# refer https://esphome.io/components/text_sensor/index.html
#############################################
#The ld2410 text sensor allows you to get information about your LD2410 Sensor.
#Bluetooth sensor is only useful of you have a B or C model
#text_sensor:
# - platform: ld2410
# version:
# name: ${friendly_name} LD2140 Firmware Version
#mac_address:
#name: ${friendly_name} LD2140 BT MAC Address
#############################################
# Binary Sensors
# https://esphome.io/components/binary_sensor/index.html
#############################################
binary_sensor:
#:########################################################################################:#
# BUTTON:
# https://esphome.io/components/button/index.html
#:########################################################################################:#
button:
- platform: ld2410 - platform: ld2410
has_target: ld2410_id: ld2410_1
name: ${friendly_name} Presence
has_moving_target:
name: ${friendly_name} Moving Target
has_still_target:
name: ${friendly_name} Still Target
out_pin_presence_status:
name: ${friendly_name} LD2140 Out Pin Presence Status
#Standard PIR Sensor factory_reset:
name: "${friendly_name} LD2410 Factory Reset"
entity_category: config
restart:
name: "${friendly_name} LD2410 Restart"
entity_category: config
query_params:
name: "${friendly_name} LD2410 Query Params"
entity_category: diagnostic
#:########################################################################################:#
# TEXT SENSOR:
# https://esphome.io/components/text_sensor/
#:########################################################################################:#
text_sensor:
- platform: ld2410
ld2410_id: ld2410_1
version:
name: "${friendly_name} LD2410 Firmware Version"
entity_category: diagnostic
mac_address:
name: "${friendly_name} LD2410 Bluetooth MAC"
entity_category: diagnostic
#:########################################################################################:#
# BINARY SENSOR:
# https://esphome.io/components/binary_sensor/
#:########################################################################################:#
binary_sensor:
# LD2410 presence states
- platform: ld2410
ld2410_id: ld2410_1
has_target:
name: "${friendly_name} Presence"
id: mmwave_presence
has_moving_target:
name: "${friendly_name} Moving Target"
id: mmwave_moving
has_still_target:
name: "${friendly_name} Still Target"
id: mmwave_still
out_pin_presence_status:
name: "${friendly_name} LD2410 Out Pin Presence Status"
entity_category: diagnostic
# Standard PIR Sensor
- platform: gpio - platform: gpio
id: pir_motion
pin: pin:
number: GPIO13 number: GPIO13
mode: mode:
input: True input: true
pullup: True pullup: false
inverted: True inverted: false
filters: filters:
- delayed_on: 50ms - delayed_on: 50ms
name: ${friendly_name} PIR Sensor name: "${friendly_name} PIR Sensor"
device_class: motion device_class: motion
#RF Input from Vibration Sensor (Green Bin) # RF Input from Vibration Sensor (Green Bin)
- platform: gpio - platform: gpio
id: green_bin_motion
pin: pin:
number: GPIO04 number: GPIO4
mode: mode:
input: true input: true
pullup: true pullup: true
inverted: True inverted: true
filters: filters:
- delayed_on: 20ms - delayed_on: 20ms
name: ${friendly_name} Green Bin motion name: "${friendly_name} Green Bin Motion"
device_class: vibration device_class: vibration
#RF Input from Vibration Sensor (Red Bin) # RF Input from Vibration Sensor (Red Bin)
- platform: gpio - platform: gpio
id: red_bin_motion
pin: pin:
number: GPIO15 number: GPIO15
mode: mode:
input: true input: true
pullup: true pullup: true
ignore_strapping_warning: true # GPIO15: This just supresses a warning, we know what we are doing ignore_strapping_warning: true
inverted: True inverted: true
filters: filters:
- delayed_on: 20ms - delayed_on: 20ms
name: ${friendly_name} Red Bin motion name: "${friendly_name} Red Bin Motion"
device_class: vibration device_class: vibration
# Composite occupancy (mmWave OR PIR) for lighting/automation use
- platform: template
name: "${friendly_name} Occupancy"
device_class: occupancy
lambda: |-
return id(mmwave_presence).state || id(pir_motion).state;
filters:
- delayed_off: 30s
+81 -85
View File
@@ -1,59 +1,75 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: ENTRANCE BATHROOM LIGHTSWITCH
# ENTRANCE BATHROOM LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.7 2025-09-34 upload to this bathroom #:########################################################################################:#
# V3.5 2025-07-24 YAML tidyups # REPO:
########################################################################################## # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-entrancebathrmlights.yaml
# Zemismart KS-811 Double push button #:########################################################################################:#
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # VERSIONS:
# # v3.8 2026-02-25 Updated yaml to zorruno layout V1.1
# NOTES # v3.7 2025-09-34 Upload to this bathroom (as noted in original header)
# - Light switch with light and extract fan # v3.5 2025-07-24 YAML tidyups
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # - Zemismart KS-811 Double push button (ESP8266)
# - ESP8266 board: esp01_1m
# - Pinout/schematic:
# https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Entrance bathroom switch with 2 outputs:
# 1) Main Lights
# 2) Extract Fan
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Local button control continues to toggle relays.
# - MQTT/API publishing to HA may not be available until HA returns.
# b) MQTT OFFLINE (or broker unreachable)
# - Local button control continues to toggle relays.
# - MQTT state updates (if any) will not publish.
# c) Entire WiFi/Network OFFLINE
# - Local button control continues to toggle relays.
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-entrancebathrmlights" device_name: "esp-entrancebathrmlights"
friendly_name: "Entrance Bathroom Lightswitch (2)" friendly_name: "Entrance Bathroom Lightswitch (2)"
description_comment: "Entrance bathroom lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Extract Fan (2)" description_comment: "Entrance bathroom lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Extract Fan (2) (Layout V1.1)"
device_area: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double"
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.8"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-entrancebathrmlights_ip static_ip_address: !secret esp-entrancebathrmlights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:lightbulb-group" log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for general sensors etc
update_interval: "60s" # update time for for general sensors etc
# MQTT LOCAL Controls
#mqtt_device_name: "bedroom2-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
# Switch Naming # Switch Naming
switch_1_name: "Main Lights" switch_1_name: "Main Lights"
switch_2_name: "Extract Fan" switch_2_name: "Extract Fan"
#switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -62,6 +78,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -75,22 +92,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -99,50 +117,46 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: yes
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: True
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only suppresses a warning.
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
@@ -156,20 +170,10 @@ binary_sensor:
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: Relay_2
# KS-811-2 is a double only #:########################################################################################:#
# - platform: gpio # SWITCH
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -179,12 +183,4 @@ switch:
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
# KS-811-2 is a double only
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3
+111 -89
View File
@@ -1,59 +1,83 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: MAIN ENTRANCE LIGHTSWITCH
# Main Entrance LIGHTSWITCH # zorruno.com layout v1.1 2026
# V3.7 2025-09-15 upload to this lightswitch from copy #:########################################################################################:#
# # REPO:
########################################################################################## # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-entrancelightswitch.yaml
# Zemismart KS-811 Double push button #:########################################################################################:#
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # VERSIONS:
# # V3.8 2026-02-25 Updated yaml to zorruno layout V1.1
# NOTES # V3.7 2025-09-15 Upload to this lightswitch from copy
# - Light switch with 2 sets of lights #:########################################################################################:#
# # HARDWARE:
########################################################################################## # - Zemismart KS-811 Double push button (ESP8266)
########################################################################################## # - Status LED: GPIO2
# - Buttons: GPIO16 (Button 1), GPIO5 (Button 2)
# - Relays: GPIO13 (Relay 1), GPIO12 (Relay 2)
# - Pinout/schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Button 1 toggles Relay 1 (Entrance Lights).
# - Relay 2 is forced ON at boot (permanently on) to power an external light controller.
# - Button 2 is currently not assigned to any action (relay remains ON from boot).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Physical button control continues (Relay 1 toggles locally)
# - Relay 2 remains ON (external controller stays powered)
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Physical button control continues
# - HA control continues via API
# c) Entire WiFi/Network OFFLINE
# - Physical button control continues (local operation)
# - Relay 2 remains ON (external controller stays powered)
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-entrancelightswitch" device_name: "esp-entrancelightswitch"
friendly_name: "Main Entrance Lightswitch (2)" friendly_name: "Main Entrance Lightswitch (2)"
description_comment: "Main Entrance lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Bench Lights (2)" description_comment: "Main Entrance lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Bench Lights (2) (Layout V1.1)"
device_area: "Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Zemismart Technologies.KS-811 Double" # Project Details project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v3.7" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v3.8" # Project version denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-entrancelightswitch_ip static_ip_address: !secret esp-entrancelightswitch_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic #mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic #mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:lightbulb-group" log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for general sensors etc
update_interval: "60s" # update time for for general sensors etc
# MQTT LOCAL Controls # MQTT LOCAL Controls
#mqtt_device_name: "bedroom2-lights" #mqtt_device_name: "bedroom2-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_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}"
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA #mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}"
# Switch Naming # Switch Naming
switch_1_name: "Entrance Lights" switch_1_name: "Entrance Lights"
switch_2_name: "External Light Controller" #permanently on, and pushbutton sends MQTT switch_2_name: "External Light Controller" # permanently on, and pushbutton sends MQTT (not configured here)
#switch_3_name: "Nil" #switch_3_name: "Nil"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -62,6 +86,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -75,22 +100,23 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
######################################################################################### #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -99,50 +125,48 @@ esphome:
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
on_boot: on_boot:
priority: 200 priority: 200
then: then:
- switch.turn_on: Relay_2 # Permanently on - switch.turn_on: Relay_2 # Permanently on
######################################################################################### #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
######################################################################################### #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false # Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only suppresses a warning.
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: Relay_1
@@ -151,25 +175,25 @@ binary_sensor:
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
# on_press: #on_press:
# - switch.toggle: Relay_2 # - switch.toggle: Relay_2
# KS-811-2 is a double only # KS-811-2 is a double only
# - platform: gpio #- platform: gpio
# pin: # pin:
# number: GPIO4 # number: GPIO4
# mode: INPUT # mode: INPUT
# inverted: True # inverted: true
# name: "Button 3: ${switch_3_name}" # name: "Button 3: ${switch_3_name}"
# on_press: # on_press:
# - switch.toggle: Relay_3 # - switch.toggle: Relay_3
######################################################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
######################################################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
@@ -181,10 +205,8 @@ switch:
pin: GPIO12 pin: GPIO12
id: Relay_2 id: Relay_2
# KS-811-2 is a double only # KS-811-2 is a double only
# - platform: gpio #- platform: gpio
# name: "Relay 3: ${switch_3_name}" # name: "Relay 3: ${switch_3_name}"
# pin: GPIO14 # pin: GPIO14
# id: Relay_3 # id: Relay_3
+969
View File
@@ -0,0 +1,969 @@
##########################################################################################
##########################################################################################
# FRONT ENTRANCEWAY LED LIGHT CONTROLS
# File: esp-entranceoutsideledlights.yaml
#
# v1.0 - 2026-02-23 Initial version (converted from Tasmota)
#
# Hardware: H801 (ESP8266EX) 5-channel PWM MOSFET LED controller
#
###########################################################################################
# NOTES
# - H801 PWM outputs (typical / ESPHome Devices):
# PWM1 / R -> GPIO15
# PWM2 / G -> GPIO13
# PWM3 / B -> GPIO12
# PWM4 / W1 -> GPIO14
# PWM5 / W2 -> GPIO4
# Some templates swap G/B labeling (GPIO12 vs GPIO13). If outputs appear swapped,
# just swap out2_pwm_pin and out3_pwm_pin below.
#
# - We expose helper entities per channel:
# * On/Off switch (ramps using per-channel ramp time)
# * Brightness slider 0-100% normalized to the per-channel hard limit
# * Ramp time (seconds) for a full 0 -> hard limit transition
# * Hard limit (percent) absolute cap for that channel
#
# - Underlying PWM light entities are INTERNAL so HA cannot bypass the hard limit.
#
##########################################################################################
##########################################################################################
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
##########################################################################################
substitutions:
# Device Naming
device_name: "esp-entranceoutsideledlights"
friendly_name: "Front Entranceway LED Light controls"
description_comment: "H801 ESP8266 5-channel PWM LED controller (Entranceway)"
device_area: "Entranceway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "H801.5CH PWM LED Controller"
project_version: "v1.0"
# Passwords & Secrets
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-entranceoutsideledlights_ip # unfortunately you can't use substitutions inside secrets names
#mqtt_command_main_topic: !secret mqtt_command_main_topic
#mqtt_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT LOCAL Controls (optional, kept for consistency with your templates)
#mqtt_local_device_name: "entranceoutsideledlights"
#mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}"
#mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}"
# Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
update_interval: "60s"
# OUTPUT NAMES
out1_name: "Main Entrance Outside LED Lights"
out2_name: "Number 16 LED Light"
out3_name: "Spare 3"
out4_name: "Spare 4"
out5_name: "Spare 5"
# H801 PWM PINS (easy swap here if needed)
out1_pwm_pin: "GPIO15"
out2_pwm_pin: "GPIO13"
out3_pwm_pin: "GPIO12"
out4_pwm_pin: "GPIO14"
out5_pwm_pin: "GPIO4"
pwm_frequency: "1000 Hz"
##########################################################################################
# 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_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include
file: common/api_common.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}"
#### 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
#############################################
# 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
min_version: 2025.11.0
area: ${device_area}
project:
name: ${project_name}
version: ${project_version}
#############################################
# ESP Platform and Framework
# https://esphome.io/components/esp8266.html
#############################################
esp8266:
board: esp01_1m
#############################################
# ESPHome Logging Enable
# https://esphome.io/components/logger.html
#############################################
logger:
level: ${log_level}
baud_rate: 0 # set to 0 for no logging via UART
##########################################################################################
# OUTPUTS (H801 PWM MOSFET CHANNELS)
##########################################################################################
output:
- platform: esp8266_pwm
id: out1_pwm
pin: ${out1_pwm_pin}
frequency: ${pwm_frequency}
- platform: esp8266_pwm
id: out2_pwm
pin: ${out2_pwm_pin}
frequency: ${pwm_frequency}
- platform: esp8266_pwm
id: out3_pwm
pin: ${out3_pwm_pin}
frequency: ${pwm_frequency}
- platform: esp8266_pwm
id: out4_pwm
pin: ${out4_pwm_pin}
frequency: ${pwm_frequency}
- platform: esp8266_pwm
id: out5_pwm
pin: ${out5_pwm_pin}
frequency: ${pwm_frequency}
##########################################################################################
# INTERNAL LIGHTS (do not expose to HA; use helper entities below)
##########################################################################################
light:
- platform: monochromatic
id: out1_light_raw
name: "${out1_name} (RAW)"
output: out1_pwm
internal: true
restore_mode: RESTORE_DEFAULT_OFF
- platform: monochromatic
id: out2_light_raw
name: "${out2_name} (RAW)"
output: out2_pwm
internal: true
restore_mode: RESTORE_DEFAULT_OFF
- platform: monochromatic
id: out3_light_raw
name: "${out3_name} (RAW)"
output: out3_pwm
internal: true
restore_mode: RESTORE_DEFAULT_OFF
- platform: monochromatic
id: out4_light_raw
name: "${out4_name} (RAW)"
output: out4_pwm
internal: true
restore_mode: RESTORE_DEFAULT_OFF
- platform: monochromatic
id: out5_light_raw
name: "${out5_name} (RAW)"
output: out5_pwm
internal: true
restore_mode: RESTORE_DEFAULT_OFF
##########################################################################################
# GLOBALS (store "last non-zero" brightness per channel)
##########################################################################################
globals:
- id: out1_last_nonzero_pct
type: float
restore_value: true
initial_value: "100.0"
- id: out2_last_nonzero_pct
type: float
restore_value: true
initial_value: "100.0"
- id: out3_last_nonzero_pct
type: float
restore_value: true
initial_value: "100.0"
- id: out4_last_nonzero_pct
type: float
restore_value: true
initial_value: "100.0"
- id: out5_last_nonzero_pct
type: float
restore_value: true
initial_value: "100.0"
##########################################################################################
# SCRIPTS (apply normalized brightness + proportional ramping)
##########################################################################################
script:
#############################################
# OUT1
#############################################
- id: out1_apply_target
mode: restart
then:
- lambda: |-
const float slider_pct = id(out1_brightness_pct).state;
const float limit_pct = id(out1_max_limit_pct).state;
const float ramp_s = id(out1_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float slider_frac = slider_pct / 100.0f;
if (slider_frac < 0.0f) slider_frac = 0.0f;
if (slider_frac > 1.0f) slider_frac = 1.0f;
float target = slider_frac * limit_frac;
float current = 0.0f;
if (id(out1_light_raw).current_values.is_on()) {
current = id(out1_light_raw).current_values.get_brightness();
}
float delta = target - current;
if (delta < 0.0f) delta = -delta;
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (delta / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
if (target <= 0.0001f) {
auto call = id(out1_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
} else {
auto call = id(out1_light_raw).turn_on();
call.set_brightness(target);
call.set_transition_length(trans_ms);
call.perform();
}
- id: out1_turn_off
mode: restart
then:
- lambda: |-
const float limit_pct = id(out1_max_limit_pct).state;
const float ramp_s = id(out1_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float current = 0.0f;
if (id(out1_light_raw).current_values.is_on()) {
current = id(out1_light_raw).current_values.get_brightness();
}
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (current / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
auto call = id(out1_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
#############################################
# OUT2
#############################################
- id: out2_apply_target
mode: restart
then:
- lambda: |-
const float slider_pct = id(out2_brightness_pct).state;
const float limit_pct = id(out2_max_limit_pct).state;
const float ramp_s = id(out2_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float slider_frac = slider_pct / 100.0f;
if (slider_frac < 0.0f) slider_frac = 0.0f;
if (slider_frac > 1.0f) slider_frac = 1.0f;
float target = slider_frac * limit_frac;
float current = 0.0f;
if (id(out2_light_raw).current_values.is_on()) {
current = id(out2_light_raw).current_values.get_brightness();
}
float delta = target - current;
if (delta < 0.0f) delta = -delta;
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (delta / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
if (target <= 0.0001f) {
auto call = id(out2_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
} else {
auto call = id(out2_light_raw).turn_on();
call.set_brightness(target);
call.set_transition_length(trans_ms);
call.perform();
}
- id: out2_turn_off
mode: restart
then:
- lambda: |-
const float limit_pct = id(out2_max_limit_pct).state;
const float ramp_s = id(out2_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float current = 0.0f;
if (id(out2_light_raw).current_values.is_on()) {
current = id(out2_light_raw).current_values.get_brightness();
}
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (current / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
auto call = id(out2_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
#############################################
# OUT3
#############################################
- id: out3_apply_target
mode: restart
then:
- lambda: |-
const float slider_pct = id(out3_brightness_pct).state;
const float limit_pct = id(out3_max_limit_pct).state;
const float ramp_s = id(out3_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float slider_frac = slider_pct / 100.0f;
if (slider_frac < 0.0f) slider_frac = 0.0f;
if (slider_frac > 1.0f) slider_frac = 1.0f;
float target = slider_frac * limit_frac;
float current = 0.0f;
if (id(out3_light_raw).current_values.is_on()) {
current = id(out3_light_raw).current_values.get_brightness();
}
float delta = target - current;
if (delta < 0.0f) delta = -delta;
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (delta / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
if (target <= 0.0001f) {
auto call = id(out3_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
} else {
auto call = id(out3_light_raw).turn_on();
call.set_brightness(target);
call.set_transition_length(trans_ms);
call.perform();
}
- id: out3_turn_off
mode: restart
then:
- lambda: |-
const float limit_pct = id(out3_max_limit_pct).state;
const float ramp_s = id(out3_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float current = 0.0f;
if (id(out3_light_raw).current_values.is_on()) {
current = id(out3_light_raw).current_values.get_brightness();
}
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (current / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
auto call = id(out3_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
#############################################
# OUT4
#############################################
- id: out4_apply_target
mode: restart
then:
- lambda: |-
const float slider_pct = id(out4_brightness_pct).state;
const float limit_pct = id(out4_max_limit_pct).state;
const float ramp_s = id(out4_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float slider_frac = slider_pct / 100.0f;
if (slider_frac < 0.0f) slider_frac = 0.0f;
if (slider_frac > 1.0f) slider_frac = 1.0f;
float target = slider_frac * limit_frac;
float current = 0.0f;
if (id(out4_light_raw).current_values.is_on()) {
current = id(out4_light_raw).current_values.get_brightness();
}
float delta = target - current;
if (delta < 0.0f) delta = -delta;
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (delta / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
if (target <= 0.0001f) {
auto call = id(out4_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
} else {
auto call = id(out4_light_raw).turn_on();
call.set_brightness(target);
call.set_transition_length(trans_ms);
call.perform();
}
- id: out4_turn_off
mode: restart
then:
- lambda: |-
const float limit_pct = id(out4_max_limit_pct).state;
const float ramp_s = id(out4_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float current = 0.0f;
if (id(out4_light_raw).current_values.is_on()) {
current = id(out4_light_raw).current_values.get_brightness();
}
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (current / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
auto call = id(out4_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
#############################################
# OUT5
#############################################
- id: out5_apply_target
mode: restart
then:
- lambda: |-
const float slider_pct = id(out5_brightness_pct).state;
const float limit_pct = id(out5_max_limit_pct).state;
const float ramp_s = id(out5_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float slider_frac = slider_pct / 100.0f;
if (slider_frac < 0.0f) slider_frac = 0.0f;
if (slider_frac > 1.0f) slider_frac = 1.0f;
float target = slider_frac * limit_frac;
float current = 0.0f;
if (id(out5_light_raw).current_values.is_on()) {
current = id(out5_light_raw).current_values.get_brightness();
}
float delta = target - current;
if (delta < 0.0f) delta = -delta;
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (delta / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
if (target <= 0.0001f) {
auto call = id(out5_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
} else {
auto call = id(out5_light_raw).turn_on();
call.set_brightness(target);
call.set_transition_length(trans_ms);
call.perform();
}
- id: out5_turn_off
mode: restart
then:
- lambda: |-
const float limit_pct = id(out5_max_limit_pct).state;
const float ramp_s = id(out5_ramp_s).state;
float limit_frac = limit_pct / 100.0f;
if (limit_frac < 0.0f) limit_frac = 0.0f;
if (limit_frac > 1.0f) limit_frac = 1.0f;
float current = 0.0f;
if (id(out5_light_raw).current_values.is_on()) {
current = id(out5_light_raw).current_values.get_brightness();
}
float full_scale = limit_frac;
if (current > full_scale) full_scale = current;
if (full_scale < 0.0001f) full_scale = 0.0001f;
uint32_t trans_ms = (uint32_t) (ramp_s * 1000.0f * (current / full_scale));
if (trans_ms > 600000) trans_ms = 600000;
auto call = id(out5_light_raw).turn_off();
call.set_transition_length(trans_ms);
call.perform();
##########################################################################################
# NUMBERS (brightness normalized to limit, plus per-channel ramp and hard limit)
##########################################################################################
number:
#############################################
# OUT1
#############################################
- platform: template
id: out1_ramp_s
name: "${out1_name} Ramp"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: "s"
min_value: 0.0
max_value: 30.0
step: 0.1
restore_value: true
initial_value: 2.0
optimistic: true
set_action:
- script.execute: out1_apply_target
- platform: template
id: out1_max_limit_pct
name: "${out1_name} Max Limit"
icon: mdi:brightness-percent
entity_category: config
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- script.execute: out1_apply_target
- platform: template
id: out1_brightness_pct
name: "${out1_name} Brightness"
icon: mdi:lightbulb-on-outline
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- lambda: |-
if (x > 0.0f) id(out1_last_nonzero_pct) = x;
- script.execute: out1_apply_target
#############################################
# OUT2
#############################################
- platform: template
id: out2_ramp_s
name: "${out2_name} Ramp"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: "s"
min_value: 0.0
max_value: 30.0
step: 0.1
restore_value: true
initial_value: 2.0
optimistic: true
set_action:
- script.execute: out2_apply_target
- platform: template
id: out2_max_limit_pct
name: "${out2_name} Max Limit"
icon: mdi:brightness-percent
entity_category: config
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- script.execute: out2_apply_target
- platform: template
id: out2_brightness_pct
name: "${out2_name} Brightness"
icon: mdi:lightbulb-on-outline
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- lambda: |-
if (x > 0.0f) id(out2_last_nonzero_pct) = x;
- script.execute: out2_apply_target
#############################################
# OUT3
#############################################
- platform: template
id: out3_ramp_s
name: "${out3_name} Ramp"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: "s"
min_value: 0.0
max_value: 30.0
step: 0.1
restore_value: true
initial_value: 2.0
optimistic: true
set_action:
- script.execute: out3_apply_target
- platform: template
id: out3_max_limit_pct
name: "${out3_name} Max Limit"
icon: mdi:brightness-percent
entity_category: config
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- script.execute: out3_apply_target
- platform: template
id: out3_brightness_pct
name: "${out3_name} Brightness"
icon: mdi:lightbulb-on-outline
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- lambda: |-
if (x > 0.0f) id(out3_last_nonzero_pct) = x;
- script.execute: out3_apply_target
#############################################
# OUT4
#############################################
- platform: template
id: out4_ramp_s
name: "${out4_name} Ramp"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: "s"
min_value: 0.0
max_value: 30.0
step: 0.1
restore_value: true
initial_value: 2.0
optimistic: true
set_action:
- script.execute: out4_apply_target
- platform: template
id: out4_max_limit_pct
name: "${out4_name} Max Limit"
icon: mdi:brightness-percent
entity_category: config
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- script.execute: out4_apply_target
- platform: template
id: out4_brightness_pct
name: "${out4_name} Brightness"
icon: mdi:lightbulb-on-outline
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- lambda: |-
if (x > 0.0f) id(out4_last_nonzero_pct) = x;
- script.execute: out4_apply_target
#############################################
# OUT5
#############################################
- platform: template
id: out5_ramp_s
name: "${out5_name} Ramp"
icon: mdi:timer-outline
entity_category: config
unit_of_measurement: "s"
min_value: 0.0
max_value: 30.0
step: 0.1
restore_value: true
initial_value: 2.0
optimistic: true
set_action:
- script.execute: out5_apply_target
- platform: template
id: out5_max_limit_pct
name: "${out5_name} Max Limit"
icon: mdi:brightness-percent
entity_category: config
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- script.execute: out5_apply_target
- platform: template
id: out5_brightness_pct
name: "${out5_name} Brightness"
icon: mdi:lightbulb-on-outline
unit_of_measurement: "%"
min_value: 0
max_value: 100
step: 1
restore_value: true
initial_value: 100
optimistic: true
set_action:
- lambda: |-
if (x > 0.0f) id(out5_last_nonzero_pct) = x;
- script.execute: out5_apply_target
##########################################################################################
# SWITCHES (On/Off that respects ramping; brightness slider remains unchanged when off)
##########################################################################################
switch:
- platform: template
id: out1_switch
name: ${out1_name}
icon: mdi:lightbulb
lambda: |-
return id(out1_light_raw).current_values.is_on();
turn_on_action:
- if:
condition:
lambda: |-
return id(out1_brightness_pct).state <= 0.0f;
then:
- number.set:
id: out1_brightness_pct
value: !lambda "return id(out1_last_nonzero_pct);"
else:
- script.execute: out1_apply_target
turn_off_action:
- script.execute: out1_turn_off
- platform: template
id: out2_switch
name: ${out2_name}
icon: mdi:lightbulb
lambda: |-
return id(out2_light_raw).current_values.is_on();
turn_on_action:
- if:
condition:
lambda: |-
return id(out2_brightness_pct).state <= 0.0f;
then:
- number.set:
id: out2_brightness_pct
value: !lambda "return id(out2_last_nonzero_pct);"
else:
- script.execute: out2_apply_target
turn_off_action:
- script.execute: out2_turn_off
- platform: template
id: out3_switch
name: ${out3_name}
icon: mdi:lightbulb
lambda: |-
return id(out3_light_raw).current_values.is_on();
turn_on_action:
- if:
condition:
lambda: |-
return id(out3_brightness_pct).state <= 0.0f;
then:
- number.set:
id: out3_brightness_pct
value: !lambda "return id(out3_last_nonzero_pct);"
else:
- script.execute: out3_apply_target
turn_off_action:
- script.execute: out3_turn_off
- platform: template
id: out4_switch
name: ${out4_name}
icon: mdi:lightbulb
lambda: |-
return id(out4_light_raw).current_values.is_on();
turn_on_action:
- if:
condition:
lambda: |-
return id(out4_brightness_pct).state <= 0.0f;
then:
- number.set:
id: out4_brightness_pct
value: !lambda "return id(out4_last_nonzero_pct);"
else:
- script.execute: out4_apply_target
turn_off_action:
- script.execute: out4_turn_off
- platform: template
id: out5_switch
name: ${out5_name}
icon: mdi:lightbulb
lambda: |-
return id(out5_light_raw).current_values.is_on();
turn_on_action:
- if:
condition:
lambda: |-
return id(out5_brightness_pct).state <= 0.0f;
then:
- number.set:
id: out5_brightness_pct
value: !lambda "return id(out5_last_nonzero_pct);"
else:
- script.execute: out5_apply_target
turn_off_action:
- script.execute: out5_turn_off
+159 -161
View File
@@ -1,56 +1,84 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: FLY SPRAYER - SINILINK XY-WFUSB
# FLY SPRAYER - Sinilink XY-WFUSB (ESP8266/ESP8285) - ESPHome # zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-flysprayer1.yaml
#:########################################################################################:#
# VERSIONS:
# v1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# v1.0 2025-05-30 Initial Version
#:########################################################################################:#
# HARDWARE:
# - Sinilink XY-WFUSB (ESP8266/ESP8285)
# - Device link: https://www.aliexpress.com/item/1005005815472269.html
# - GPIO (from Tasmota template):
# - Button = GPIO4
# - Relay = GPIO5
# - Led_i = GPIO14 (Red LED, inverted)
# - LedLink= GPIO16 (Green LED, status)
#:########################################################################################:#
# OPERATION NOTES:
# - Purpose:
# - Pulse a MOSFET/relay with 5 V to trigger a fly spray can at selectable intervals.
# - The sprayer has its own timers, but it fires whenever it is started up; we utilize that.
# - Safety / Reliability:
# - Cooldown is enforced so it never double-fires too quickly (sprayer has some memory).
# - Interval can be randomized by +- a percentage (jitter) to avoid a perfectly regular pattern.
# - Scheduling:
# - Operation modes: Night only / Day only / 24 Hours / On / Off.
# - Night window spans across midnight (night_start_h -> night_end_h).
# - Indicators:
# - Red LED (GPIO14, inverted) pulses slowly when idle; goes solid ON during spray.
# - Green LED (GPIO16) is used as the ESPHome status LED.
# - Counters / UI:
# - Total spray count (resettable).
# - Daily spray count (resets at local midnight when time is valid).
# - Countdown until next spray (seconds + friendly text).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Device continues operating locally (spray loop, cooldown, LEDs, counters).
# - You can still trigger "Spray Now" via the local button; HA UI will update when HA returns.
# #
# V1.0 2025-05-30 Initial Version # b) MQTT OFFLINE (or broker unreachable)
# - No device-specific MQTT commands are used in this YAML (MQTT section is commented out),
# so behavior is unchanged.
# #
# Device: Sinilink XY-WFUSB module https://www.aliexpress.com/item/1005005815472269.html # c) Entire WiFi/Network OFFLINE
# GPIO: Tasmota template: Button=GPIO4, Relay=GPIO5, Led_i=GPIO14, LedLink=GPIO16 # - Accurate time IS needed for Night/Day modes and daily counter reset (SNTP required).
# # - If time is invalid, this YAML is conservative for Night/Day modes (skips those cycles).
# Purpose: # 24 Hours / On still allows operation, but daily reset will not occur until time is valid.
# - Pulse a MOSFET/relay with 5 V to trigger a fly spray can at selectable intervals. #:########################################################################################:#
# - Sprayer has its own timers, but it fires whenever it is started up, which we utilise here.
# - Enforce a cooldown so it never double-fires too quickly (Sprayer has some memory)
# - Operation window select: Night only / Day only / 24 Hours / On / Off.
# - Randomize each interval by +- a percentage to avoid a perfectly regular pattern.
# - Red LED (GPIO14, inverted) pulses slowly when idle; goes solid ON during spray.
# - Green LED (GPIO16) as standard ESPHome status LED.
# - Has a resettable total spray count, and a daily spray count
# - has a countdown until next spray
#
##########################################################################################
##########################################################################################
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-flysprayer1" device_name: "esp-flysprayer1"
friendly_name: "Fly Sprayer" friendly_name: "Fly Sprayer"
description_comment: "Control of generic automatic fly sprayer on a configurable interval" description_comment: "Control of generic automatic fly sprayer on a configurable interval (Layout V1.1)"
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Lounge"
# Project Naming # Project Naming
project_name: "Generic ESP8266.XY-WFUSB" # Project Details project_name: "Generic ESP8266.XY-WFUSB"
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.1"
# Passwords & Secrets # Passwords & Secrets
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-flysprayer1_ip static_ip_address: !secret esp-flysprayer1_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO"
update_interval: "60s" # update time for for general sensors etc update_interval: "60s"
# MQTT Controls
#mqtt_device_name: "lounge-flyspray"
#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
# Hardware pins (XY-WFUSB per your Tasmota screen) # Hardware pins (XY-WFUSB per your Tasmota screen)
pin_button: 4 # GPIO4 -> momentary button (optional local trigger) pin_button: 4 # GPIO4 -> momentary button (optional local trigger)
@@ -61,19 +89,19 @@ substitutions:
# Timing configuration # Timing configuration
relay_activation_ms: 5000 # Relay Activation Time (ms). Nominally 5 seconds. relay_activation_ms: 5000 # Relay Activation Time (ms). Nominally 5 seconds.
relay_cooldown_ms: 30000 # Relay Cool Down Period (ms). Minimum gap between sprays. relay_cooldown_ms: 30000 # Relay Cool Down Period (ms). Minimum gap between sprays.
# Operation windows (local 24h). Night is from night_start_h to night_end_h across midnight. # Operation windows (local 24h). Night is from night_start_h to night_end_h across midnight.
night_start_h: 21 # 21:00 (9pm) night_start_h: 21 # 21:00 (9pm)
night_end_h: 7 # 07:00 (7am) night_end_h: 7 # 07:00 (7am)
# Interval jitter (+- percent of selected interval) # Interval jitter (+- percent of selected interval)
interval_jitter_pct: 10 # Default +-10% interval_jitter_pct: 10 # Default +-10%
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -82,6 +110,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -96,21 +125,19 @@ packages:
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome CORE CONFIGURATION # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -142,105 +169,91 @@ esphome:
id(next_spray_in_text).publish_state("Ready"); id(next_spray_in_text).publish_state("Ready");
- script.execute: spray_loop - script.execute: spray_loop
########################################################################################## #:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp8266.html # https://esphome.io/components/esp8266.html
# https://esphome.io/components/esp32.html #:########################################################################################:#
##########################################################################################
esp8266: esp8266:
board: esp8285 board: esp8285
early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false
board_flash_mode: dout # Default is dout board_flash_mode: dout
preferences: preferences:
flash_write_interval: 20s flash_write_interval: 20s
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBALS
# https://esphome.io/components/globals.html # https://esphome.io/components/globals.html
########################################################################################## #:########################################################################################:#
globals: globals:
# millisecond tick when we last fired successfully # millisecond tick when we last fired successfully
- id: last_fire_ms - id: last_fire_ms
type: uint32_t type: uint32_t
restore_value: no restore_value: no
initial_value: '0' initial_value: "0"
- id: last_wait_ms - id: last_wait_ms
type: uint32_t type: uint32_t
restore_value: no restore_value: no
initial_value: '60000' initial_value: "60000"
- id: window_allowed - id: window_allowed
type: bool type: bool
restore_value: no restore_value: no
initial_value: 'false' initial_value: "false"
# absolute millis() when the next spray countdown ends # absolute millis() when the next spray countdown ends
- id: next_target_ms - id: next_target_ms
type: uint32_t type: uint32_t
restore_value: no restore_value: no
initial_value: '0' initial_value: "0"
# total successful sprays (persists across reboots) # total successful sprays (persists across reboots)
- id: spray_count - id: spray_count
type: uint32_t type: uint32_t
restore_value: yes restore_value: yes
initial_value: '0' initial_value: "0"
# total sprays since local midnight # total sprays since local midnight
- id: spray_count_today - id: spray_count_today
type: uint32_t type: uint32_t
restore_value: yes restore_value: yes
initial_value: '0' initial_value: "0"
# day-of-month snapshot to detect midnight rollover # day-of-month snapshot to detect midnight rollover
- id: last_day - id: last_day
type: int type: int
restore_value: yes restore_value: yes
initial_value: '-1' initial_value: "-1"
########################################################################################## #:########################################################################################:#
# LOGGER COMPONENT # LOGGER
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
# Logs all log messages through the serial port and through MQTT topics. #:########################################################################################:#
##########################################################################################
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS
# This adds device-specific MQTT command triggers to the common MQTT configuration.
##########################################################################################
#mqtt:
# on_message:
# # Light control to ramp up
# - topic: "${mqtt_local_command_topic}/light/set"
# payload: "${mqtt_local_device_command_ON}"
# then:
# - switch.turn_on: mosfet_ramp_switch
# # Light control to ramp down
# - topic: "${mqtt_local_command_topic}/light/set"
# payload: "${mqtt_local_device_command_OFF}"
# then:
# - switch.turn_off: mosfet_ramp_switch
#########################################################################################
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
status_led: status_led:
pin: pin:
number: ${pin_led_green} number: ${pin_led_green}
inverted: false inverted: false
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # MQTT COMMANDS
# (No device-specific MQTT triggers are enabled in this file currently)
#:########################################################################################:#
#mqtt:
# on_message:
#:########################################################################################:#
# SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
id: relay_out id: relay_out
@@ -264,10 +277,10 @@ switch:
brightness: 50% brightness: 50%
effect: red_idle_pulse effect: red_idle_pulse
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
button: button:
- platform: template - platform: template
id: spray_now id: spray_now
@@ -276,6 +289,7 @@ button:
on_press: on_press:
then: then:
- script.execute: try_spray_now - script.execute: try_spray_now
- platform: template - platform: template
id: reset_spray_count id: reset_spray_count
name: "Reset Spray Count" name: "Reset Spray Count"
@@ -286,10 +300,10 @@ button:
id(spray_count) = 0; id(spray_count) = 0;
id(spray_count_sensor).publish_state(0); id(spray_count_sensor).publish_state(0);
######################################################################################### #:########################################################################################:#
# SELECT COMPONENT # SELECT
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
######################################################################################### #:########################################################################################:#
select: select:
- platform: template - platform: template
id: spray_interval id: spray_interval
@@ -333,12 +347,12 @@ select:
args: [ 'id(spray_operation).current_option().c_str()' ] args: [ 'id(spray_operation).current_option().c_str()' ]
- script.execute: spray_loop - script.execute: spray_loop
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
# Front panel/local button (GPIO4) - single press triggers a Spray Now (honors cooldown) # Front panel/local button (GPIO4) - triggers Spray Now (honors cooldown)
- platform: gpio - platform: gpio
id: btn_local id: btn_local
pin: pin:
@@ -352,10 +366,10 @@ binary_sensor:
then: then:
- button.press: spray_now - button.press: spray_now
########################################################################################## #:########################################################################################:#
# SENSOR COMPONENT # SENSORS
# https://esphome.io/components/sensor/ # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
# Next spray remaining time in seconds (updated by the scheduler) # Next spray remaining time in seconds (updated by the scheduler)
- platform: template - platform: template
@@ -364,7 +378,6 @@ sensor:
icon: mdi:timer-sand icon: mdi:timer-sand
unit_of_measurement: "s" unit_of_measurement: "s"
accuracy_decimals: 0 accuracy_decimals: 0
#entity_category: diagnostic
update_interval: never update_interval: never
# Total sprays counter (persisted; updated on each spray and when reset) # Total sprays counter (persisted; updated on each spray and when reset)
@@ -379,7 +392,7 @@ sensor:
filters: filters:
- round: 0 - round: 0
# Sprays since local midnight (auto-resets at midnight) # Sprays since local midnight (auto-resets at midnight when time is valid)
- platform: template - platform: template
id: spray_count_today_sensor id: spray_count_today_sensor
name: "${friendly_name} Spray Count Today" name: "${friendly_name} Spray Count Today"
@@ -391,36 +404,32 @@ sensor:
filters: filters:
- round: 0 - round: 0
########################################################################################## #:########################################################################################:#
# TEXT SENSOR COMPONENT # TEXT SENSORS
# https://esphome.io/components/text_sensor/ # https://esphome.io/components/text_sensor/
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
- platform: template - platform: template
id: next_spray_in_text id: next_spray_in_text
name: "Next Spray In" name: "Next Spray In"
icon: mdi:clock-outline icon: mdi:clock-outline
#entity_category: diagnostic
update_interval: never update_interval: never
########################################################################################## #:########################################################################################:#
# OUTPUT COMPONENT # OUTPUT
# https://esphome.io/components/light/index.html # https://esphome.io/components/output/
########################################################################################## #:########################################################################################:#
# An OUTPUT can be binary (0,1) or float, which is any value between 0 and 1.
# PWM Outputs such as "ledc" are float. https://esphome.io/components/output/ledc.html
##########################################################################################
output: output:
- platform: esp8266_pwm - platform: esp8266_pwm
id: red_led_pwm id: red_led_pwm
pin: pin:
number: ${pin_led_red} number: ${pin_led_red}
inverted: true # Tasmota showed Led_i on GPIO14 inverted: true
########################################################################################## #:########################################################################################:#
# LIGHT COMPONENT # LIGHT
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: monochromatic - platform: monochromatic
id: red_led id: red_led
@@ -435,18 +444,10 @@ light:
transition_length: 1500ms transition_length: 1500ms
update_interval: 1500ms update_interval: 1500ms
########################################################################################## #:########################################################################################:#
# NUMBER COMPONENT # SCRIPTS
# https://esphome.io/components/number/
##########################################################################################
##########################################################################################
# SCRIPT COMPONENT
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call. #:########################################################################################:#
##########################################################################################
# SCRIPTS - main loop, cooldown-safe trigger, and actual spray action
##########################################################################################
script: script:
# Cooldown-checked "Spray Now" # Cooldown-checked "Spray Now"
- id: try_spray_now - id: try_spray_now
@@ -463,7 +464,7 @@ script:
id(last_fire_ms) = millis(); id(last_fire_ms) = millis();
- script.execute: do_spray - script.execute: do_spray
else: else:
- logger.log: "Spray request ignored: Fired during cool down period." - logger.log: "Spray request ignored: fired during cool down period."
# Actual relay action for the configured activation time # Actual relay action for the configured activation time
- id: do_spray - id: do_spray
@@ -473,7 +474,7 @@ script:
id(spray_count)++; id(spray_count)++;
id(spray_count_sensor).publish_state((float) id(spray_count)); id(spray_count_sensor).publish_state((float) id(spray_count));
id(spray_count_today)++; id(spray_count_today)++;
id(spray_count_today_sensor).publish_state(id(spray_count_today)); // publish as int id(spray_count_today_sensor).publish_state(id(spray_count_today));
- switch.turn_on: relay_out - switch.turn_on: relay_out
- light.turn_on: - light.turn_on:
id: red_led id: red_led
@@ -486,7 +487,7 @@ script:
brightness: 50% brightness: 50%
effect: red_idle_pulse effect: red_idle_pulse
# Scheduler loop - waits a randomized interval, updates countdown text, checks window, then tries to spray # Scheduler loop - waits a randomized interval, updates countdown, checks window, then tries to spray
- id: spray_loop - id: spray_loop
mode: restart mode: restart
then: then:
@@ -510,8 +511,9 @@ script:
const uint32_t pct = ${interval_jitter_pct}; const uint32_t pct = ${interval_jitter_pct};
const uint32_t jitter = (base_sec * pct) / 100; const uint32_t jitter = (base_sec * pct) / 100;
const uint32_t span = (jitter * 2u) + 1u; const uint32_t span = (jitter * 2u) + 1u;
const uint32_t rnd = random_uint32() % span; // 0..(2*jitter) const uint32_t rnd = random_uint32() % span; // 0..(2*jitter)
const int32_t delta = (int32_t) rnd - (int32_t) jitter; // -jitter..+jitter const int32_t delta = (int32_t) rnd - (int32_t) jitter; // -jitter..+jitter
int32_t next_sec = (int32_t) base_sec + delta; int32_t next_sec = (int32_t) base_sec + delta;
if (next_sec < 1) next_sec = 1; if (next_sec < 1) next_sec = 1;
@@ -521,11 +523,11 @@ script:
id(last_wait_ms) = (uint32_t) next_sec * 1000u; id(last_wait_ms) = (uint32_t) next_sec * 1000u;
id(next_target_ms) = millis() + id(last_wait_ms); id(next_target_ms) = millis() + id(last_wait_ms);
// Publish an initial countdown snapshot (minutes only for text; seconds kept for numeric sensor) // Publish an initial countdown snapshot
uint32_t rem_ms = id(next_target_ms) > millis() ? (id(next_target_ms) - millis()) : 0; uint32_t rem_ms = id(next_target_ms) > millis() ? (id(next_target_ms) - millis()) : 0;
uint32_t sec = (rem_ms + 999u) / 1000u; // seconds, rounded up uint32_t sec = (rem_ms + 999u) / 1000u; // seconds, rounded up
id(next_spray_seconds).publish_state(sec); id(next_spray_seconds).publish_state(sec);
uint32_t min = (sec + 59u) / 60u; // minutes, ceiling uint32_t min = (sec + 59u) / 60u; // minutes, ceiling
char buf[16]; char buf[16];
snprintf(buf, sizeof(buf), "%u min", (unsigned) min); snprintf(buf, sizeof(buf), "%u min", (unsigned) min);
std::string countdown_txt(buf); std::string countdown_txt(buf);
@@ -562,7 +564,7 @@ script:
bool is_night; bool is_night;
if (nh > eh) is_night = (hour >= nh) || (hour < eh); if (nh > eh) is_night = (hour >= nh) || (hour < eh);
else is_night = (hour >= nh) && (hour < eh); else is_night = (hour >= nh) && (hour < eh);
in_window = !is_night; // day is the opposite of night window in_window = !is_night;
} }
if (!in_window) { if (!in_window) {
snprintf(await_buf, sizeof(await_buf), "%02d:00", ${night_end_h}); snprintf(await_buf, sizeof(await_buf), "%02d:00", ${night_end_h});
@@ -581,14 +583,14 @@ script:
then: then:
- lambda: |- - lambda: |-
uint32_t rem_ms = id(next_target_ms) > millis() ? (id(next_target_ms) - millis()) : 0; uint32_t rem_ms = id(next_target_ms) > millis() ? (id(next_target_ms) - millis()) : 0;
uint32_t sec = (rem_ms + 999u) / 1000u; // seconds, rounded up uint32_t sec = (rem_ms + 999u) / 1000u;
id(next_spray_seconds).publish_state(sec); id(next_spray_seconds).publish_state(sec);
uint32_t min = (sec + 59u) / 60u; // minutes, ceiling
uint32_t min = (sec + 59u) / 60u;
char buf[16]; char buf[16];
snprintf(buf, sizeof(buf), "%u min", (unsigned) min); snprintf(buf, sizeof(buf), "%u min", (unsigned) min);
std::string countdown_txt(buf); std::string countdown_txt(buf);
// Override text for specific modes
auto op = id(spray_operation).current_option(); auto op = id(spray_operation).current_option();
char await_buf[16]; char await_buf[16];
@@ -637,10 +639,8 @@ script:
auto n = id(sntp_time).now(); auto n = id(sntp_time).now();
int d = n.day_of_month; int d = n.day_of_month;
if (id(last_day) == -1) { if (id(last_day) == -1) {
// First valid time after boot: initialise without reset id(last_day) = d; // first valid time after boot
id(last_day) = d;
} else if (id(last_day) != d) { } else if (id(last_day) != d) {
// New day -> reset today's counter
id(last_day) = d; id(last_day) = d;
id(spray_count_today) = 0; id(spray_count_today) = 0;
id(spray_count_today_sensor).publish_state(0); id(spray_count_today_sensor).publish_state(0);
@@ -659,16 +659,15 @@ script:
allowed = true; allowed = true;
} else { } else {
if (!id(sntp_time).now().is_valid()) { if (!id(sntp_time).now().is_valid()) {
allowed = false; // no time yet; be conservative allowed = false; // no time yet; be conservative
} else { } else {
auto n = id(sntp_time).now(); auto n = id(sntp_time).now();
int hour = n.hour; // 0..23 int hour = n.hour;
int nh = ${night_start_h}; int nh = ${night_start_h};
int eh = ${night_end_h}; int eh = ${night_end_h};
bool is_night; bool is_night;
if (nh > eh) { if (nh > eh) {
// window crosses midnight (e.g., 21:00..07:00)
is_night = (hour >= nh) || (hour < eh); is_night = (hour >= nh) || (hour < eh);
} else { } else {
is_night = (hour >= nh) && (hour < eh); is_night = (hour >= nh) && (hour < eh);
@@ -683,10 +682,9 @@ script:
else ESP_LOGI("spray", "Window blocked: skipping this cycle."); else ESP_LOGI("spray", "Window blocked: skipping this cycle.");
id(window_allowed) = allowed; id(window_allowed) = allowed;
- if: - if:
condition: condition:
lambda: "return id(window_allowed);" lambda: "return id(window_allowed);"
then: then:
- script.execute: try_spray_now - script.execute: try_spray_now
+199 -155
View File
@@ -1,65 +1,109 @@
############################################# #:########################################################################################:#
############################################# # TITLE: GARAGE DB CONTROLS
# GARAGE DB CONTROLS # zorruno.com layout v1.1 2026
# Controlled by a Sonoff 4Ch R2 #:########################################################################################:#
# https://github.com/jvyoralek/homeassistant-config/blob/master/esphome/sonoff-4ch.yaml # REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-garagedbcontrols.yaml
#:########################################################################################:#
# VERSIONS:
# v1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# v1.0 2025-10-23 Initial Version
#:########################################################################################:#
# HARDWARE:
# - Sonoff 4CH R2 (ESP8266 / ESP8285)
# - Reference YAML: https://github.com/jvyoralek/homeassistant-config/blob/master/esphome/sonoff-4ch.yaml
# - Relays (4CH R2): GPIO12, GPIO5, GPIO4, GPIO15
# - Buttons (4CH R2): GPIO0, GPIO9, GPIO10, GPIO14
# - Status LED: GPIO13 (active-low)
# - Extras (as used here):
# - EV pulse input: GPIO2 (must be HIGH at boot; INPUT_PULLUP used)
# - DHT sensor: GPIO3 (note: UART RX pin on ESP8266; ensure logger baud_rate=0)
#:########################################################################################:#
# OPERATION NOTES:
# - Provides 4 relay outputs with matching local buttons.
# - Relay restore modes are set per-output (some default ON, some default OFF).
# - Includes EV charger energy monitoring via pulse input (2.0 Wh per pulse):
# - "Power Now" derived from pulse rate (pulse_meter).
# - Lifetime kWh total from pulse total (pulse_meter total).
# - 1-hour sliding average for power.
# - Daily kWh using total_daily_energy, with "Energy Yesterday" snap at 23:59 when time is valid.
# - Publishes a Tasmota-like MQTT telemetry message once per 60s with windowed Wh delta.
#:########################################################################################:#
# MQTT COMMANDS:
# - Publishes windowed EV Wh count every 60s:
# Topic: stat/tasmo-s4chan-7594-garage-1/EnergyMeterCount
# Payload example: {"EVChargerWhCount":123.456}
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Device continues relay/button operation and continues pulse metering locally.
# - MQTT telemetry publishing depends on MQTT broker availability.
# #
# V1.0 2025-10-23 Initial Version # b) MQTT OFFLINE (or broker unreachable)
# - Relays/buttons still operate locally and via HA API (if HA is available).
# - MQTT telemetry messages will not be delivered until broker returns.
# #
########################################################################################## # c) Entire WiFi/Network OFFLINE
########################################################################################## # - Accurate time IS needed for the "Energy Yesterday" snapshot at 23:59 (SNTP required).
# - Power/energy totals still accumulate, but "Energy Yesterday" will not update without valid time.
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Custom Naming # Device Naming
device_name: "esp-garagedbcontrols" device_name: "esp-garagedbcontrols"
friendly_name: "Garage DB Control" friendly_name: "Garage DB Control"
description_comment: "Garage DB Power, EV Power & Mesure, Lighting :: Sonoff 4ch R2" description_comment: "Garage DB Power, EV Power & Measure, Lighting :: Sonoff 4ch R2 (Layout V1.1)"
device_area: "Garage" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Garage"
# Project Naming
project_name: "Sonoff Technologies.Sonoff 4Ch R2"
project_version: "v1.1"
# Passwords & Secrets
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-garagedbcontrols_ip static_ip_address: !secret esp-garagedbcontrols_ip
#mqtt_device_name_1: "garage-dbcontrols"
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# General Settings
log_level: "ERROR"
update_interval: "60s"
# I/O Naming # I/O Naming
switch_1_name: "Small EV Charger" switch_1_name: "Small EV Charger"
button_1_name: "Button 1" button_1_name: "Button 1"
relay_1_icon: "mdi:power-socket-au" relay_1_icon: "mdi:power-socket-au"
switch_2_name: "Garage West Power" switch_2_name: "Garage West Power"
button_2_name: "Button 2" button_2_name: "Button 2"
relay_2_icon: "mdi:power-socket-au" relay_2_icon: "mdi:power-socket-au"
switch_3_name: "Spare 3" switch_3_name: "Spare 3"
button_3_name: "Button 3" button_3_name: "Button 3"
relay_3_icon: "mdi:toggle-switch" relay_3_icon: "mdi:toggle-switch"
switch_4_name: "Spare 4" switch_4_name: "Spare 4"
button_4_name: "Button 4" button_4_name: "Button 4"
relay_4_icon: "mdi:toggle-switch" relay_4_icon: "mdi:toggle-switch"
# Project Naming # EV pulse settings
project_name: "Sonoff Technologies.Sonoff 4Ch R2" # Project Details ev_pulse_wh: "2.0" # Wh per pulse
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version ev_pulse_filter: "10ms" # debounce pulses
ev_pulse_timeout: "2min" # set power to 0W if no pulses
ev_tasmota_tele_topic: "stat/tasmo-s4chan-7594-garage-1/EnergyMeterCount"
# MQTT Controls #:########################################################################################:#
#mqtt_command_main_topic: !secret mqtt_command_main_topic
#mqtt_status_main_topic: !secret mqtt_status_main_topic
#mqtt_command_topic_1: "${mqtt_command_main_topic}/${mqtt_device_name_1}"
#mqtt_status_topic_1: "${mqtt_status_main_topic}/${mqtt_device_name_1}"
#mqtt_command_ON: "ON"
#mqtt_command_OFF: "OFF"
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
# General Settings
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
##########################################################################################
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -68,6 +112,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -81,27 +126,28 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}"
area: "${device_area}" area: "${device_area}"
project:
name: "${project_name}"
version: "${project_version}"
# On boot, initialise the window start so the first publish isn't huge # On boot, initialise the window start so the first publish isn't huge
on_boot: on_boot:
priority: -10 priority: -10
@@ -113,123 +159,149 @@ esphome:
id(ev_last_total_kwh) = 0.0f; id(ev_last_total_kwh) = 0.0f;
} }
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
#board: esp01_1m restore_from_flash: true
restore_from_flash: True # restore some values on reboot
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
mdns: mdns:
disabled: False disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # STATUS LED
# https://esphome.io/components/status_led.html
#:########################################################################################:#
status_led:
pin:
number: GPIO13
inverted: yes
#:########################################################################################:#
# GLOBALS
# https://esphome.io/components/globals.html
#:########################################################################################:#
globals:
# Store the last published total (kWh) for 60s delta windowing
- id: ev_last_total_kwh
type: float
restore_value: true
initial_value: "0.0"
- id: ev_energy_yesterday_kwh
type: float
restore_value: true
initial_value: "0.0"
# Track last day-of-year we snapped so it only happens once per day
- id: ev_last_snapshot_doy
type: int
restore_value: no
initial_value: "-1"
#:########################################################################################:#
# SWITCHES
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
# Sonoff 4Ch R2 Relays are GPIO12,05,04,15
#############################################
switch: switch:
# Sonoff 4Ch R2 Relays are GPIO12, GPIO5, GPIO4, GPIO15
- platform: gpio - platform: gpio
id: relay1 id: relay1
name: "${switch_1_name}" name: "${switch_1_name}"
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
pin: GPIO12 pin: GPIO12
icon: "${relay_1_icon}" icon: "${relay_1_icon}"
- platform: gpio - platform: gpio
id: relay2 id: relay2
name: "${switch_2_name}" name: "${switch_2_name}"
restore_mode: RESTORE_DEFAULT_ON restore_mode: RESTORE_DEFAULT_ON
pin: GPIO5 pin: GPIO5
icon: "${relay_2_icon}" icon: "${relay_2_icon}"
- platform: gpio - platform: gpio
id: relay3 id: relay3
name: "${switch_3_name}" name: "${switch_3_name}"
restore_mode: RESTORE_DEFAULT_ON restore_mode: RESTORE_DEFAULT_ON
pin: GPIO4 pin: GPIO4
icon: "${relay_3_icon}" icon: "${relay_3_icon}"
- platform: gpio - platform: gpio
id: relay4 id: relay4
name: "${switch_4_name}" name: "${switch_4_name}"
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
pin: GPIO15 pin: GPIO15
icon: "${relay_4_icon}" icon: "${relay_4_icon}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
# Sonoff 4Ch R2 Buttons are GPIO00,09,10,14
#############################################
binary_sensor: binary_sensor:
# Sonoff 4Ch R2 Buttons are GPIO0, GPIO9, GPIO10, GPIO14
- platform: gpio - platform: gpio
id: button1 id: button1
name: "${button_1_name}" name: "${button_1_name}"
pin: pin:
number: GPIO0 number: GPIO0
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay1 - switch.toggle: relay1
- platform: gpio - platform: gpio
id: button2 id: button2
name: "${button_2_name}" name: "${button_2_name}"
pin: pin:
number: GPIO9 number: GPIO9
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay2 - switch.toggle: relay2
- platform: gpio - platform: gpio
id: button3 id: button3
name: "${button_3_name}" name: "${button_3_name}"
pin: pin:
number: GPIO10 number: GPIO10
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay3 - switch.toggle: relay3
- platform: gpio - platform: gpio
id: button4 id: button4
name: "${button_4_name}" name: "${button_4_name}"
pin: pin:
number: GPIO14 number: GPIO14
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay4 - switch.toggle: relay4
########################################################################################## #:########################################################################################:#
# STATUS LED # SENSORS
# https://esphome.io/components/status_led.html # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
status_led:
pin:
number: GPIO13
inverted: yes
##########################################################################################
# EV CHARGER ENERGY (PULSE INPUT ON GPIO2, 2.0 Wh PER PULSE)
# - Uses pulse_meter for stable pulse rate and total count
# - Derives instantaneous Power (W), 1h average Power, Today kWh, and lifetime kWh
##########################################################################################
sensor: sensor:
# Pulse rate -> Power Now (W) ########################################################################################
# EV CHARGER ENERGY (PULSE INPUT ON GPIO2, 2.0 Wh PER PULSE)
# - Uses pulse_meter for stable pulse rate and total count
# - Derives Power (W), 1h average Power, Today kWh, and lifetime kWh
########################################################################################
- platform: pulse_meter - platform: pulse_meter
id: ev_pulse_pm id: ev_pulse_pm
pin: pin:
@@ -237,17 +309,16 @@ sensor:
mode: INPUT_PULLUP # GPIO2 must be HIGH at boot mode: INPUT_PULLUP # GPIO2 must be HIGH at boot
inverted: false inverted: false
name: "${switch_1_name} Power Now" name: "${switch_1_name} Power Now"
# pulse_meter reports pulses/min; each pulse = 2 Wh => W = pulses/min * 2 * 60 = x120
unit_of_measurement: "W" unit_of_measurement: "W"
device_class: power device_class: power
state_class: measurement state_class: measurement
accuracy_decimals: 0 accuracy_decimals: 0
internal_filter: 10ms # debounce pulses internal_filter: ${ev_pulse_filter}
timeout: 2min # set to 0 W if no pulses for 2 minutes timeout: ${ev_pulse_timeout}
# pulse_meter reports pulses/min; each pulse = 2 Wh => W = pulses/min * 2 * 60 = x120
filters: filters:
- multiply: 120.0 # convert pulses/min to Watts - multiply: 120.0
# Lifetime energy total (monotonic)
total: total:
id: ev_energy_total_kwh id: ev_energy_total_kwh
name: "${switch_1_name} Energy Cumulative Total" name: "${switch_1_name} Energy Cumulative Total"
@@ -256,9 +327,9 @@ sensor:
state_class: total_increasing state_class: total_increasing
accuracy_decimals: 1 accuracy_decimals: 1
filters: filters:
- multiply: 0.002 # kWh per pulse (2.0 Wh = 0.002 kWh) # kWh per pulse (2.0 Wh = 0.002 kWh)
- multiply: 0.002
# 1-hour sliding average of power (W)
- platform: template - platform: template
id: ev_power_avg_1h id: ev_power_avg_1h
name: "${switch_1_name} Power (1h avg)" name: "${switch_1_name} Power (1h avg)"
@@ -274,7 +345,6 @@ sensor:
window_size: 360 # 10 s * 360 ≈ 1 hour window_size: 360 # 10 s * 360 ≈ 1 hour
send_every: 6 # update HA once per minute send_every: 6 # update HA once per minute
# Today's energy (kWh), integrates "Power Now" and resets at local midnight
- platform: total_daily_energy - platform: total_daily_energy
id: ev_energy_today_kwh id: ev_energy_today_kwh
name: "${switch_1_name} Energy Today" name: "${switch_1_name} Energy Today"
@@ -284,9 +354,9 @@ sensor:
state_class: total state_class: total
accuracy_decimals: 1 accuracy_decimals: 1
filters: filters:
- multiply: 0.001 # total_daily_energy outputs Wh; convert to kWh # total_daily_energy outputs Wh; convert to kWh
- multiply: 0.001
# Expose "Energy Yesterday" as a normal sensor
- platform: template - platform: template
id: ev_energy_yesterday_sensor id: ev_energy_yesterday_sensor
name: "${switch_1_name} Energy Yesterday" name: "${switch_1_name} Energy Yesterday"
@@ -296,85 +366,59 @@ sensor:
accuracy_decimals: 1 accuracy_decimals: 1
update_interval: 30s update_interval: 30s
lambda: |- lambda: |-
return id(ev_energy_yesterday_kwh); return id(ev_energy_yesterday_kwh);
########################################################################################## ########################################################################################
# DHT SENSOR # DHT SENSOR (GPIO3)
# https://esphome.io/components/sensor/dht/ # NOTE: GPIO3 is UART RX on ESP8266; logger baud_rate=0 avoids conflicts.
########################################################################################## ########################################################################################
#sensor:
- platform: dht - platform: dht
pin: GPIO3 pin: GPIO3
update_interval: 60s
temperature: temperature:
name: "${friendly_name} Temperature" name: "${friendly_name} Temperature"
humidity: humidity:
name: "${friendly_name} Humidity" name: "${friendly_name} Humidity"
update_interval: 60s
########################################################################################## #:########################################################################################:#
# Tasmota-like teleperiod publish of windowed Wh count every 60 s # INTERVALS
########################################################################################## # https://esphome.io/components/interval.html
# Store the last published total (kWh) #:########################################################################################:#
globals:
- id: ev_last_total_kwh
type: float
restore_value: true
initial_value: "0.0"
- id: ev_energy_yesterday_kwh
type: float
restore_value: true
initial_value: "0.0"
# Track last day-of-year we snapped so it only happens once per day
- id: ev_last_snapshot_doy
type: int
restore_value: no
initial_value: '-1'
# Teleperiod = 60s: publish JSON and advance the window
interval: interval:
# Teleperiod = 60s: publish JSON and advance the window
- interval: 60s - interval: 60s
then: then:
- mqtt.publish: - mqtt.publish:
topic: "stat/tasmo-s4chan-7594-garage-1/EnergyMeterCount" topic: "${ev_tasmota_tele_topic}"
qos: 0 qos: 0
retain: false retain: false
payload: !lambda |- payload: !lambda |-
// Current lifetime kWh from pulse_meter "total"
float current = id(ev_energy_total_kwh).state; float current = id(ev_energy_total_kwh).state;
if (!isfinite(current)) current = id(ev_last_total_kwh); if (!isfinite(current)) current = id(ev_last_total_kwh);
// Delta since last publish (kWh -> Wh)
float delta_kwh = current - id(ev_last_total_kwh); float delta_kwh = current - id(ev_last_total_kwh);
if (delta_kwh < 0.0f || !isfinite(delta_kwh)) delta_kwh = 0.0f; if (delta_kwh < 0.0f || !isfinite(delta_kwh)) delta_kwh = 0.0f;
float delta_wh = delta_kwh * 1000.0f; float delta_wh = delta_kwh * 1000.0f;
// Advance the window (equivalent of "counter1 0")
id(ev_last_total_kwh) = current; id(ev_last_total_kwh) = current;
// Build JSON payload
char buf[64]; char buf[64];
snprintf(buf, sizeof(buf), "{\"EVChargerWhCount\":%.3f}", delta_wh); snprintf(buf, sizeof(buf), "{\"EVChargerWhCount\":%.3f}", delta_wh);
return std::string(buf); return std::string(buf);
# YESTERDAY ENERGY (device-side snapshot of today's total at end-of-day) # YESTERDAY ENERGY snapshot (once per day at 23:59, when time is valid)
# Uses existing time id(sntp_time) from sntp_common.yaml
- interval: 60s - interval: 60s
then: then:
- lambda: |- - lambda: |-
auto now = id(sntp_time).now(); auto now = id(sntp_time).now();
if (!now.is_valid()) return; if (!now.is_valid()) return;
// Snapshot once per day at 23:59 (minute precision)
if (now.hour != 23 || now.minute != 59) return; if (now.hour != 23 || now.minute != 59) return;
// Prevent repeats if this runs multiple times during 23:59
if (id(ev_last_snapshot_doy) == now.day_of_year) return; if (id(ev_last_snapshot_doy) == now.day_of_year) return;
if (isfinite(id(ev_energy_today_kwh).state)) { if (isfinite(id(ev_energy_today_kwh).state)) {
id(ev_energy_yesterday_kwh) = id(ev_energy_today_kwh).state; id(ev_energy_yesterday_kwh) = id(ev_energy_today_kwh).state;
} }
id(ev_last_snapshot_doy) = now.day_of_year; id(ev_last_snapshot_doy) = now.day_of_year;
+158 -127
View File
@@ -1,69 +1,75 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: 6 CHANNEL LOUNGE DMX MAINS DIMMER
# 4 Channel DMX Mains Dimmer # zorruno.com layout v1.0 2026
# This is using an esp8366 (D1 Mini) sending DMX512 Serial to a trio of 2 channel #:########################################################################################:#
# mains lighting contollers (1.2A/Channel) # VERSIONS:
#
# Contoller: https://www.aliexpress.com/item/32838426377.html
# RS-485 TTL converter: https://www.aliexpress.com/item/1005005737922222.html
#
# V1.1 2025-09-13 Extended to 3 modules and installed # V1.1 2025-09-13 Extended to 3 modules and installed
# V1.0 2025-09-06 First Rev (only tested one module, 2 channels at this stage, and incandescent) # V1.0 2025-09-06 First Rev (only tested one module, 2 channels at this stage, and incandescent)
########################################################################################## #:########################################################################################:#
# HARDWARE:
# - ESP8266 D1 Mini Pro
# - 3 x 2-channel DMX mains dimmer modules (1.2 A per channel)
# Contoller: https://www.aliexpress.com/item/32838426377.html
# - RS-485 TTL converter (MAX485 style)
# RS-485 TTL converter: https://www.aliexpress.com/item/1005005737922222.html
# #
# NOTES # MAX485 Module (You could also use a MAX3485 which is 3.3 V)
# ------ # - MAX485 VCC -> ESP +5V
# - Trialling with an incandescent bulb, 10% writes 26. Max value is 255 so this is 10% # - MAX485 GND -> ESP GND
# - With an incandescent, I can't see any light output below about 15% # - MAX485 DE -> ESP +5V
# - Using GPIO2 as the UART TX on an ESP8266 is handy, as the onboard LED flashes with TX # - MAX485 RE -> Pullup so can leave unconnected (or +5V) or a designated enable_pin
# - The dimmer needs to be set to DMX mode, and given an ID of 1-999 (not standalone or dynamic) # - MAX485 DI -> ESP GPIO2 (ESP8266) or GPIO5 (ESP32)
# - there is no reason you can't run many dimmers off one ESP (limit may be in data speed lags?) # - MAX485 A -> XLR 3 (DMX +)
# - The dimmer is pretty smooth, and it remembers values even if no data being transmitted. # - MAX485 B -> XLR 2 (DMX -)
# - On my system, I am restoring all channels to ON. Power is controlled by a (smart) wallswitch # - MAX485 GND -> XLR 1 (DMX GND)
# so if all networks fail, switching the switch will power these on and restore to full brightness. #:########################################################################################:#
# OPERATION NOTES:
# - ESP8266 transmits DMX512 over UART (one-way TX only) via RS-485 adaptor
# - Dimmer modules must be set to DMX mode and assigned a fixed ID (1-999)
# - Incandescent trial notes:
# - 10% writes ~26 (max 255)
# - Very low levels may not visibly output below ~15%
# - Using GPIO2 as UART TX on ESP8266 is handy, as the onboard LED flashes with TX
# - Dimmers are smooth and remember values even if DMX data stops transmitting
# - This design assumes mains power is controlled by a smart wall switch:
# - If networks fail, toggling power restores the dimmer outputs (and this YAML restores channels to ON)
# #
# System Settings on Dimmer: (onboard buttons M and < held for 2 secs) # System Settings on Dimmer: (onboard buttons M and < held for 2 secs)
# ------ # - Set "1 Channel" (d-1) and both channels output the same level, or "2 Channel" (d-2)
# - Set "1 Channel" (d-1) and both channels will output the same levels. Or "2 Channel" (d-2) # - Set reverse phase dimming / trailing edge (C-R) or forward / leading edge (C-F)
# - Set reverse phase dimming/trailing edge (C-R) or Forward/Leading Edge (C-F) # - Set minimum brightness on the dimmer, from b01-b40 (b01 gives ~5% min)
# - Set minimum brightness on the dimmer, from b01-b40. Min is then 5% if b01 # - Set the 3x 8 segment display to automatically turn off (Bon/BoF)
# - Set the 3x 8 Segment display to automatically turn off (Bon/BoF) after a period # - Pull both DE and RE high on the 485 converter to ensure data enabled (or wire enable_pin)
# - pull both DE & RE high on the 485 converter to ensure data enabled (or wire to enable_pin)
#
# MAX485 Module (You could also use a MAX3485 which is 3.3V)
# ------
# MAX485 VCC -> ESP +5V
# MAX485 GND -> ESP GND
# MAX485 DE -> ESP +5V
# MAX485 RE -> Has a pullup so can leave unconnected, (or +5V)or an designated enable_pin
# MAX485 DI -> ESP32 GPIO5 or ESP8266 GPIO2
# MAX485 A -> XLR 3 (DMX +)
# MAX485 B -> XLR 2 (DMX -)
# MAX485 GND -> XLR 1 (DMX GND)
# #
# Other useful references # Other useful references
# ------ # - Arduino DMX Controller: https://www.youtube.com/watch?v=4PjBBBQB2m4
# - Arduino DMX Controller https://www.youtube.com/watch?v=4PjBBBQB2m4 # - ESP32 DMX Contoller with ESPixelstick (errors in his wiring diagram):
# - ESP32 DMX Contoller with ESPixelstick (errors in his wiring diagram) # https://www.youtube.com/watch?v=GWZ63vsKzT8
# https://www.youtube.com/watch?v=GWZ63vsKzT8 # - ESPHome DMX512 Custom component used here:
# - ESPHome DMX512 Custom component used here: https://github.com/andyboeh/esphome-dmx512 # https://github.com/andyboeh/esphome-dmx512
# Includes good examples if you are expanding #:########################################################################################:#
########################################################################################## # MQTT COMMANDS:
########################################################################################## #
#:########################################################################################:#
# OFFLINE NOTES:
# - If Home Assistant is offline, lights can still be controlled locally (device continues DMX output)
# - If Wi-Fi is offline, wall switch power-cycling restores dimmer module output state (modules remember)
#:########################################################################################:#
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-lounge6chdimmer" device_name: "esp-lounge6chdimmer"
friendly_name: "6 Channel Lounge Dimmer" friendly_name: "6 Channel Lounge Dimmer"
description_comment: "Lounge 6 Channel Mains Lighting Dimmer (3 x 2 channel modules) controlled using DMX512 protocol with a D1 Mini Pro" description_comment: "Lounge 6 Channel Mains Lighting Dimmer (3 x 2 channel modules) controlled using DMX512 protocol with a D1 Mini Pro (Layout V1.0)"
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Generic ESP8266.D1 Mini" # Project Details project_name: "Generic ESP8266.D1 Mini" # Project Details
project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets # Passwords & Secrets
@@ -104,12 +110,12 @@ substitutions:
gamma_output_5: "2.2" gamma_output_5: "2.2"
gamma_output_6: "2.2" gamma_output_6: "2.2"
#########################################################################################
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
##########################################################################################
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors # Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -132,23 +138,24 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
#########################################################################################
# ESPHome #:########################################################################################:#
# ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
######################################################################################### #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -168,113 +175,126 @@ esphome:
id(dmx_ch5_sensor).publish_state(0); id(dmx_ch5_sensor).publish_state(0);
id(dmx_ch6_sensor).publish_state(0); id(dmx_ch6_sensor).publish_state(0);
#########################################################################################
# ESP Platform and Framework #:########################################################################################:#
# https://esphome.io/components/esp32.html # ESP PLATFORM AND FRAMEWORK:
######################################################################################### # https://esphome.io/components/esp8266/
#:########################################################################################:#
esp8266: esp8266:
board: d1_mini_pro board: d1_mini_pro
#early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. #early_pin_init: false # Initialise pins early to known values. Recommended false where switches are involved. Defaults to true.
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
restore_from_flash: true # restore some values on reboot restore_from_flash: true # restore some values on reboot
#:########################################################################################:#
# MDNS:
# https://esphome.io/components/mdns.html
#:########################################################################################:#
mdns: mdns:
disabled: false # Disabling will make the build file smaller (and it is still available via static IP) disabled: false # Disabling will make the build file smaller (and it is still available via static IP)
#preferences:
# flash_write_interval: 0s
######################################################################################### #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing 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) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
#########################################################################################
# STATUS LED #:########################################################################################:#
# STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
#status_led: #status_led:
# pin: # pin:
# number: GPIO2 # number: GPIO2
# inverted: yes # inverted: true
#########################################################################################
# UART COMPONENT #:########################################################################################:#
# UART COMPONENT:
# https://esphome.io/components/uart/ # https://esphome.io/components/uart/
######################################################################################### #:########################################################################################:#
uart: uart:
# Needed for the DMX component. # Needed for the DMX component.
# This UART talks to the RS485 adaptor # This UART talks to the RS485 adaptor.
# There is no receiving, it is a one way send # There is no receiving, it is a one-way send.
id: uart_bus id: uart_bus
baud_rate: 250000 baud_rate: 250000
tx_pin: tx_pin:
number: GPIO2 #ESP8266 number: GPIO2 # ESP8266
allow_other_uses: true # For ESPHome >= 2023.12.0 allow_other_uses: true # For ESPHome >= 2023.12.0
stop_bits: 2 stop_bits: 2
##########################################################################################
# LIGHT COMPONENT #:########################################################################################:#
# LIGHT COMPONENT:
# https://esphome.io/components/light/ # https://esphome.io/components/light/
########################################################################################## #:########################################################################################:#
light: light:
- platform: monochromatic - platform: monochromatic
name: ${output_1_name} name: "${output_1_name}"
output: dmx_1 output: dmx_1
id: light_test_1 id: light_test_1
default_transition_length: 10s default_transition_length: 10s
gamma_correct: ${gamma_output_1} gamma_correct: "${gamma_output_1}"
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
- platform: monochromatic - platform: monochromatic
name: ${output_2_name} name: "${output_2_name}"
output: dmx_2 output: dmx_2
id: light_test_2 id: light_test_2
default_transition_length: 10s default_transition_length: 10s
gamma_correct: ${gamma_output_2} gamma_correct: "${gamma_output_2}"
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
- platform: monochromatic - platform: monochromatic
name: ${output_3_name} name: "${output_3_name}"
output: dmx_3 output: dmx_3
id: light_test_3 id: light_test_3
default_transition_length: 10s default_transition_length: 10s
gamma_correct: ${gamma_output_3} gamma_correct: "${gamma_output_3}"
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
- platform: monochromatic - platform: monochromatic
name: ${output_4_name} name: "${output_4_name}"
output: dmx_4 output: dmx_4
id: light_test_4 id: light_test_4
default_transition_length: 10s default_transition_length: 10s
gamma_correct: ${gamma_output_4} gamma_correct: "${gamma_output_4}"
restore_mode: ALWAYS_ON restore_mode: ALWAYS_ON
- platform: monochromatic - platform: monochromatic
name: ${output_5_name} name: "${output_5_name}"
output: dmx_5 output: dmx_5
id: light_test_5 id: light_test_5
default_transition_length: 3s default_transition_length: 3s
gamma_correct: ${gamma_output_5} gamma_correct: "${gamma_output_5}"
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
- platform: monochromatic - platform: monochromatic
name: ${output_6_name} name: "${output_6_name}"
output: dmx_6 output: dmx_6
id: light_test_6 id: light_test_6
default_transition_length: 3s default_transition_length: 3s
gamma_correct: ${gamma_output_6} gamma_correct: "${gamma_output_6}"
restore_mode: RESTORE_DEFAULT_OFF restore_mode: RESTORE_DEFAULT_OFF
##########################################################################################
# SENSOR COMPONENT #:########################################################################################:#
# SENSOR COMPONENT:
# https://esphome.io/components/sensor/ # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
# Expose each DMX channel's current output level as 0..255 integers (post-gamma) # Expose each DMX channel's current output level as 0..255 integers
- platform: template - platform: template
id: dmx_ch1_sensor id: dmx_ch1_sensor
name: ${output_1_name} Output name: "${output_1_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -289,7 +309,7 @@ sensor:
- platform: template - platform: template
id: dmx_ch2_sensor id: dmx_ch2_sensor
name: ${output_2_name} Output name: "${output_2_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -304,7 +324,7 @@ sensor:
- platform: template - platform: template
id: dmx_ch3_sensor id: dmx_ch3_sensor
name: ${output_3_name} Output name: "${output_3_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -319,7 +339,7 @@ sensor:
- platform: template - platform: template
id: dmx_ch4_sensor id: dmx_ch4_sensor
name: ${output_4_name} Output name: "${output_4_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -334,7 +354,7 @@ sensor:
- platform: template - platform: template
id: dmx_ch5_sensor id: dmx_ch5_sensor
name: ${output_5_name} Output name: "${output_5_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -349,7 +369,7 @@ sensor:
- platform: template - platform: template
id: dmx_ch6_sensor id: dmx_ch6_sensor
name: ${output_6_name} Output name: "${output_6_name} Output"
icon: mdi:counter icon: mdi:counter
#entity_category: diagnostic #entity_category: diagnostic
accuracy_decimals: 0 accuracy_decimals: 0
@@ -362,53 +382,65 @@ sensor:
min_value: 0 min_value: 0
max_value: 255 max_value: 255
##########################################################################################
# CUSTOM COMPONENT DMX512 #:########################################################################################:#
# EXTERNAL COMPONENTS:
# https://github.com/andyboeh/esphome-dmx512 # https://github.com/andyboeh/esphome-dmx512
########################################################################################## #:########################################################################################:#
external_components: external_components:
- source: github://andyboeh/esphome-dmx512 - source: github://andyboeh/esphome-dmx512
#:########################################################################################:#
# DMX512 COMPONENT:
# https://github.com/andyboeh/esphome-dmx512
#:########################################################################################:#
dmx512: dmx512:
id: dmx id: dmx
uart_id: uart_bus uart_id: uart_bus
#enable_pin: GPIOXX (Optional, I've wire them to be always active) #enable_pin: GPIOXX (Optional, I have wired them to be always active)
tx_pin: tx_pin:
number: GPIO2 number: GPIO2
allow_other_uses: true # For ESPHome >= 2023.12.0 allow_other_uses: true # For ESPHome >= 2023.12.0
uart_num: 1 uart_num: 1
periodic_update: true # optional. Some dimmers may turn off without regular updates. periodic_update: true # optional. Some dimmers may turn off without regular updates.
#force_full_frames: false # optional. If true the 513 byte is always sent #force_full_frames: false # optional. If true the 513 byte is always sent
#custom_break_len: 92 # optional. Break Length. Default is 92uS #custom_break_len: 92 # optional. Break Length. Default is 92uS
#custom_mab_len: 12 # optional. Mark after Break Length. Default is 12mS #custom_mab_len: 12 # optional. Mark after Break Length. Default is 12mS
#update_interval: 500 # optional. Custom update interval. Default is 500mS #update_interval: 500 # optional. Custom update interval. Default is 500mS
##########################################################################################
# OUTPUT COMPONENT #:########################################################################################:#
# https://esphome.io/components/output/ledc.html # OUTPUT COMPONENT:
########################################################################################## # https://esphome.io/components/output/
#:########################################################################################:#
output: output:
# Raw DMX slots (these are the actual DMX universes/slots) # Raw DMX slots (these are the actual DMX universes/slots)
- platform: dmx512 - platform: dmx512
channel: 1 # The ID we set the device to channel: 1 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
id: dmx_1_raw id: dmx_1_raw
- platform: dmx512 - platform: dmx512
channel: 2 # The ID we set the device to channel: 2 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
id: dmx_2_raw id: dmx_2_raw
- platform: dmx512 - platform: dmx512
channel: 3 # The ID we set the device to channel: 3 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
id: dmx_3_raw id: dmx_3_raw
- platform: dmx512 - platform: dmx512
channel: 4 # The ID we set the device to channel: 4 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
id: dmx_4_raw id: dmx_4_raw
- platform: dmx512 - platform: dmx512
channel: 5 # The ID we set the device to channel: 5 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
id: dmx_5_raw id: dmx_5_raw
- platform: dmx512 - platform: dmx512
channel: 6 # The ID we set the device to channel: 6 # The ID we set the device to
universe: dmx # The ID of the DMX512 Component universe: dmx # The ID of the DMX512 Component
@@ -492,5 +524,4 @@ output:
scaled = state * (1.0f - MIN) + MIN; scaled = state * (1.0f - MIN) + MIN;
} }
id(dmx_ch6_sensor).publish_state(scaled * 255.0f); id(dmx_ch6_sensor).publish_state(scaled * 255.0f);
id(dmx_6_raw).set_level(scaled); id(dmx_6_raw).set_level(scaled);
+31 -14
View File
@@ -1,6 +1,7 @@
########################################################################################## ##########################################################################################
# TITLE: MAIN BATHROOM FAN/HEAT COMBO SWITCH
########################################################################################## ##########################################################################################
# MAIN BATHROOM FAN/HEAT COMBO SWITCH # VERSIONS:
# V1.5 2026-02-23 MQTT numeric timer only applies if fan already ON (does not turn fan ON) # V1.5 2026-02-23 MQTT numeric timer only applies if fan already ON (does not turn fan ON)
# V1.4 2026-02-23 Add mm:ss countdown text sensor (eg 22:12) + per-second countdown engine # V1.4 2026-02-23 Add mm:ss countdown text sensor (eg 22:12) + per-second countdown engine
# V1.3 2026-02-23 Add 60-min cap timer + Remaining Minutes sensor (counts down) # V1.3 2026-02-23 Add 60-min cap timer + Remaining Minutes sensor (counts down)
@@ -8,21 +9,37 @@
# V1.1 2025-08-26 Minor Changes (MQTT) # V1.1 2025-08-26 Minor Changes (MQTT)
# V1.0 2025-06-01 Initial Version # V1.0 2025-06-01 Initial Version
########################################################################################## ##########################################################################################
# HARDWARE:
# Zemismart KS-811 Double Push Button # Zemismart KS-811 Double Push Button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#
# NOTES
# - MQTT Local Usage
# Send ON to ${mqtt_command_main_topic}/${mqtt_local_device_name} and it will turn the fan ON (60 min cap)
# Send OFF to ${mqtt_command_main_topic}/${mqtt_local_device_name} and it will turn the fan OFF
# Send a value from 1 to 60 to ${mqtt_command_main_topic}/${mqtt_local_device_name}
# and it will ONLY start/restart the countdown IF the fan is already ON (in minutes)
#
########################################################################################## ##########################################################################################
# OPERATION NOTES:
# a) MQTT Local Usage
# Send ON to ${mqtt_command_main_topic}/${mqtt_local_device_name} and it will turn the fan ON (60 min cap)
# Send OFF to ${mqtt_command_main_topic}/${mqtt_local_device_name} and it will turn the fan OFF
# Send a value from 1 to 60 to ${mqtt_command_main_topic}/${mqtt_local_device_name}
# and it will ONLY start/restart the countdown IF the fan is already ON (in minutes)
# b) IR Heater Safety
# It is designed so there should be no situation that the Heater can be on without the fan.
# If the fan turns off, so will the IR Heater.
# c) Timing functions
# By default, the fan will be on for 60mins max. Other values can be sent via MQTT/HA
# d) Other device control
# This device can turn on the heated towel rail via MQTT (doubleclick button 2)
##########################################################################################
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - The fan can still be controlled with ON, OFF and given a timer value, via MQTT.
# - The Heated towel rail can also be switched on.
# b) HA/MQTT OFFLINE
# With no automation controllers, fan and heater can be controlled on/off with the switches.
# Auto timers cannot be changed, but the fam will be on for 60mins max.
# c) Internet/Wifi OFFLINE
# No further changes, SNTP not required as timing functions do not rely on accurate clock.
########################################################################################## ##########################################################################################
########################################################################################## ##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SPECIFIC DEVICE VARIABLE SUBSTITUTIONS:
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## ##########################################################################################
substitutions: substitutions:
@@ -61,7 +78,7 @@ substitutions:
# MQTT REMOTE Controls # MQTT REMOTE Controls
mqtt_remote_device1_name: "masterbath-towelrail" mqtt_remote_device1_name: "masterbath-towelrail"
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/operation" mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}"
mqtt_remote_device1_command1: "BOOST" mqtt_remote_device1_command1: "BOOST"
########################################################################################## ##########################################################################################
@@ -103,7 +120,7 @@ packages:
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## ##########################################################################################
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## ##########################################################################################
esphome: esphome:
@@ -140,7 +157,7 @@ esphome:
id(relay2_forced_relay1) = false; id(relay2_forced_relay1) = false;
########################################################################################## ##########################################################################################
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
########################################################################################## ##########################################################################################
esp8266: esp8266:
@@ -149,7 +166,7 @@ esp8266:
board_flash_mode: dout # Default is dout board_flash_mode: dout # Default is dout
########################################################################################## ##########################################################################################
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## ##########################################################################################
logger: logger:
+227 -62
View File
@@ -1,15 +1,30 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: MAIN HOUSE 3 PHASE POWER MONITOR
# MAIN HOUSE 3 PHASE POWER MONITOR # zorruno.com layout v1.1 2026
# Power Monitor using 3x PZEM004 for 3 phase monitoring plus energy monitoring for 32A EV Charger #:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-mainpowermonitor.yaml
#:########################################################################################:#
# VERSIONS:
# v1.3 2026-02-25 Updated yaml to zorruno layout V1.1
# v1.2 2026-02-25 Updated yaml to zorruno layout V1.1. Added EV charging binary sensor
# and EV power rolling average (default 5 min). Clarified EV pulse notes.
# v1.1 2026-02-21 Fix globals array init compile error, reduce flash writes (globals update_interval)
# v1.0 2026-02-21 Initial Version
#:########################################################################################:#
# HARDWARE:
# - Wemos D1 mini (ESP8266)
# - 3x PZEM-004T V3 (Modbus, 9600 baud)
# - DHT11 (GPIO2)
# - EV pulse input (GPIO14)
#:########################################################################################:#
# OPERATION NOTES:
# - Power Monitor using 3x PZEM-004T V3 (Modbus) for 3-phase monitoring
# - Pulse input energy monitoring for 32A EV Charger (2 Wh per pulse)
# - Adds a 5 minute rolling average for EV power to avoid spiky readings at low loads
# - Adds a binary sensor to indicate when the EV charger is operating (threshold configurable)
# #
# Hardware: Wemos D1 mini (ESP8266) + 3x PZEM-004T V3 (Modbus) + DHT11 + EV Pulse Input # NOTES:
#
# V1.1 2026-02-21 Fix globals array init compile error, reduce flash writes (globals update_interval)
# V1.0 2026-02-21 Initial Version
#
# NOTES
# - PZEM-004T V3 uses Modbus over UART at 9600 baud.
# - UART is on GPIO1 (TX) and GPIO3 (RX). Logger UART is disabled (baud_rate: 0). # - UART is on GPIO1 (TX) and GPIO3 (RX). Logger UART is disabled (baud_rate: 0).
# - You will usually need to disconnect PZEM UART wires while flashing via USB. # - You will usually need to disconnect PZEM UART wires while flashing via USB.
# - DHT11 is on GPIO2 (boot-strap pin and D1 mini onboard LED pin). Usually OK, but if you ever # - DHT11 is on GPIO2 (boot-strap pin and D1 mini onboard LED pin). Usually OK, but if you ever
@@ -17,23 +32,35 @@
# - PZEM "energy" from ESPHome pzemac is in Wh, converted to kWh in this YAML. # - PZEM "energy" from ESPHome pzemac is in Wh, converted to kWh in this YAML.
# - Phase mapping requested: Red=0, Yellow=1, Blue=2 (Tasmota-style). In ESPHome pzemac Modbus # - Phase mapping requested: Red=0, Yellow=1, Blue=2 (Tasmota-style). In ESPHome pzemac Modbus
# addresses must be 0x01..0xF7, so this YAML maps to Red=0x01, Yellow=0x02, Blue=0x03. # addresses must be 0x01..0xF7, so this YAML maps to Red=0x01, Yellow=0x02, Blue=0x03.
# - 365-day history array is RAM-only (not restored) to avoid ESP8266 restore limits and flash wear. # - EV pulse power at very low load is inherently "chunky" due to 2 Wh pulses. Energy totals
########################################################################################## # remain accurate. Rolling average reduces spikes but can still read 0 W between infrequent pulses.
########################################################################################## #:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Device continues measuring power, energy, and pulses locally.
# - MQTT/API publishing will fail until HA is back.
# b) WiFi OFFLINE (LAN down), Device powered
# - No SNTP updates, so time may become invalid or drift (depending on last sync).
# - Power and energy totals continue accumulating, but period rollovers (today/month/year)
# will not update unless time is valid.
# c) Entire WiFi/Network OFFLINE
# - Accurate time IS needed for daily/monthly/year rollovers (SNTP required for correct period boundaries).
# - Loss of network will drift the timeclocks; time of day can be reset by powering off then on again at 12pm (midday)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-mainpowermonitor" device_name: "esp-mainpowermonitor"
friendly_name: "Main House 3 Phase Power Monitor" friendly_name: "Main House 3 Phase Power Monitor"
description_comment: "Power Monitor using 3x PZEM004 for 3 phase monitoring plus energy monitoring for 32A EV Charger" description_comment: "Power Monitor using 3x PZEM004 for 3 phase monitoring plus energy monitoring for 32A EV Charger (Layout V1.1)"
device_area: "Data Cupboard" device_area: "Data Cupboard"
# Project Naming # Project Naming
project_name: "Wemos.D1Mini PZEM-004T V3 3-Phase Power Monitor" project_name: "Wemos.D1Mini PZEM-004T V3 3-Phase Power Monitor"
project_version: "v1.1" project_version: "v1.3"
# Passwords # Passwords
api_key: !secret esp-api_key api_key: !secret esp-api_key
@@ -45,10 +72,6 @@ substitutions:
# Don't forget to switch it back when changed. # Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address} current_ip_address: ${static_ip_address}
# MQTT Controls
#mqtt_device_name: "main-house-3phase-power"
#mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}"
# Device Settings # Device Settings
log_level: "ERROR" log_level: "ERROR"
pzem_update_interval: "10s" pzem_update_interval: "10s"
@@ -70,6 +93,20 @@ substitutions:
ev_pulse_filter_ms: "50ms" # Debounce / filter ev_pulse_filter_ms: "50ms" # Debounce / filter
ev_pulse_pin_mode: "INPUT_PULLUP" ev_pulse_pin_mode: "INPUT_PULLUP"
# EV Charging Detection (Averaged power + binary sensor)
# Minimum EV charging power threshold (W) for binary sensor
# NOTE: Pick a value comfortably above idle (idle can be ~0.2 kWh/day = very infrequent pulses).
ev_charging_min_power_w: "300"
# Rolling average window - configuration notes:
# - Substitutions are string replacements, so window samples must be updated manually if you change times.
# - window_samples = (avg_minutes * 60) / sample_interval_seconds
ev_power_avg_window_minutes: "5" # informational
ev_power_avg_sample_interval: "10s"
ev_power_avg_sample_interval_seconds: "10" # must match the value above
ev_power_avg_window_samples: "30" # 5 min @ 10s = 30 samples
ev_power_avg_buffer_size: "180" # ring buffer >= window_samples (180 @ 10s = 30 minutes)
# Names - PZEM (per phase) # Names - PZEM (per phase)
pzem_red_v_name: "Main Power Red Voltage" pzem_red_v_name: "Main Power Red Voltage"
pzem_red_i_name: "Main Power Red Current" pzem_red_i_name: "Main Power Red Current"
@@ -109,6 +146,7 @@ substitutions:
# Names - EV Wallcharger # Names - EV Wallcharger
ev_power_name: "EV Wallcharger Power" ev_power_name: "EV Wallcharger Power"
ev_charging_name: "EV Wallcharger Charging"
ev_total_energy_name: "EV Wallcharger Total Energy" ev_total_energy_name: "EV Wallcharger Total Energy"
ev_today_name: "EV Wallcharger Energy Today" ev_today_name: "EV Wallcharger Energy Today"
ev_yesterday_name: "EV Wallcharger Energy Yesterday" ev_yesterday_name: "EV Wallcharger Energy Yesterday"
@@ -122,9 +160,9 @@ substitutions:
hum_name: "Main Power Monitor Humidity" hum_name: "Main Power Monitor Humidity"
dew_name: "Main Power Monitor Dew Point" dew_name: "Main Power Monitor Dew Point"
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -154,9 +192,10 @@ packages:
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
########################################################################################## # https://esphome.io/components/esphome.html
#:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -172,9 +211,10 @@ esphome:
- delay: 3s - delay: 3s
- script.execute: rollover_check - script.execute: rollover_check
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
########################################################################################## # https://esphome.io/components/esp8266/
#:########################################################################################:#
esp8266: esp8266:
board: d1_mini board: d1_mini
restore_from_flash: true restore_from_flash: true
@@ -185,16 +225,17 @@ preferences:
mdns: mdns:
disabled: false disabled: false
########################################################################################## #:########################################################################################:#
# LOGGING # LOGGING:
########################################################################################## # https://esphome.io/components/logger.html
#:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 baud_rate: 0
########################################################################################## #:########################################################################################:#
# UART + MODBUS (PZEM-004T V3) # UART + MODBUS (PZEM-004T V3):
########################################################################################## #:########################################################################################:#
uart: uart:
id: uart_pzem_bus id: uart_pzem_bus
tx_pin: GPIO1 tx_pin: GPIO1
@@ -205,9 +246,9 @@ modbus:
id: modbus_pzem_bus id: modbus_pzem_bus
send_wait_time: 200ms send_wait_time: 200ms
########################################################################################## #:########################################################################################:#
# GLOBALS (Energy rollovers + 365-day history + temp min/max) # GLOBALS (Energy rollovers + 365-day history + temp min/max):
########################################################################################## #:########################################################################################:#
globals: globals:
# Date tracking for rollovers (restored) # Date tracking for rollovers (restored)
- id: g_last_day - id: g_last_day
@@ -320,6 +361,25 @@ globals:
update_interval: ${globals_save_interval_pulses} update_interval: ${globals_save_interval_pulses}
initial_value: "0" initial_value: "0"
# EV rolling average power (RAM only)
- id: g_ev_power_avg_w
type: float
restore_value: no
initial_value: "0.0"
# EV pulse history ring buffer for rolling average (RAM only)
- id: g_ev_pulses_hist
type: uint32_t[${ev_power_avg_buffer_size}]
restore_value: no
- id: g_ev_pulses_hist_index
type: int
restore_value: no
initial_value: "0"
- id: g_ev_pulses_hist_count
type: int
restore_value: no
initial_value: "0"
# Temperature min/max tracking (RAM ONLY - not restored, gentler on flash) # Temperature min/max tracking (RAM ONLY - not restored, gentler on flash)
- id: g_temp_today_min - id: g_temp_today_min
type: float type: float
@@ -357,18 +417,35 @@ globals:
restore_value: no restore_value: no
initial_value: "-9999.0" initial_value: "-9999.0"
########################################################################################## #:########################################################################################:#
# INTERVAL (periodic rollover checks) # INTERVAL (periodic rollover checks + EV rolling average updates):
# NOTE: common_sntp may define its own interval. That is OK. #:########################################################################################:#
##########################################################################################
interval: interval:
- interval: "${rollover_check_interval}" - interval: "${rollover_check_interval}"
then: then:
- script.execute: rollover_check - script.execute: rollover_check
########################################################################################## - interval: "${ev_power_avg_sample_interval}"
# SENSORS then:
########################################################################################## - script.execute: ev_power_avg_update
#:########################################################################################:#
# BINARY SENSORS:
#:########################################################################################:#
binary_sensor:
- platform: template
name: "${ev_charging_name}"
id: ev_wallcharger_charging
device_class: power
icon: "mdi:ev-station"
lambda: |-
const float p = id(ev_power_avg_w).state;
if (isnan(p)) return false;
return (p >= ${ev_charging_min_power_w});
#:########################################################################################:#
# SENSORS:
#:########################################################################################:#
sensor: sensor:
######################################################################################## ########################################################################################
# PZEM-004T V3 - RED PHASE # PZEM-004T V3 - RED PHASE
@@ -851,23 +928,16 @@ sensor:
######################################################################################## ########################################################################################
# EV WALLCHARGER PULSE ENERGY (GPIO14) # EV WALLCHARGER PULSE ENERGY (GPIO14)
# - pulse_counter reports pulses/minute
# - Power (W) = pulses_per_min * (Wh_per_pulse) * 60
######################################################################################## ########################################################################################
- platform: pulse_counter - platform: pulse_counter
id: ev_pulse_rate_ppm id: ev_pulse_rate_ppm
internal: true
pin: pin:
number: GPIO14 number: GPIO14
mode: ${ev_pulse_pin_mode} mode: ${ev_pulse_pin_mode}
inverted: false inverted: false
update_interval: 10s update_interval: 10s
internal_filter: ${ev_pulse_filter_ms} internal_filter: ${ev_pulse_filter_ms}
name: "${ev_power_name}"
unit_of_measurement: "W"
accuracy_decimals: 0
filters:
- lambda: |-
return x * (${ev_pulse_wh} * 60.0f);
total: total:
id: ev_pulses_raw_total id: ev_pulses_raw_total
internal: true internal: true
@@ -882,6 +952,15 @@ sensor:
id(g_ev_pulses_total_abs) += (raw - last); id(g_ev_pulses_total_abs) += (raw - last);
id(g_ev_pulses_raw_last) = raw; id(g_ev_pulses_raw_last) = raw;
- platform: template
name: "${ev_power_name}"
id: ev_power_avg_w
unit_of_measurement: "W"
accuracy_decimals: 0
update_interval: "${ev_power_avg_sample_interval}"
lambda: |-
return id(g_ev_power_avg_w);
- platform: template - platform: template
name: "${ev_total_energy_name}" name: "${ev_total_energy_name}"
id: ev_total_energy_kwh id: ev_total_energy_kwh
@@ -957,9 +1036,9 @@ sensor:
lambda: |- lambda: |-
return id(g_ev_last_year_kwh); return id(g_ev_last_year_kwh);
########################################################################################## #:########################################################################################:#
# SCRIPTS # SCRIPTS:
########################################################################################## #:########################################################################################:#
script: script:
# Initialize RAM-only history arrays and counters # Initialize RAM-only history arrays and counters
- id: init_history_arrays - id: init_history_arrays
@@ -972,6 +1051,59 @@ script:
id(g_mains_daily_hist_index) = 0; id(g_mains_daily_hist_index) = 0;
id(g_mains_daily_hist_count) = 0; id(g_mains_daily_hist_count) = 0;
// Init EV pulse history buffer so rolling average starts stable after boot
const int ev_buf = ${ev_power_avg_buffer_size};
const uint32_t p0 = id(g_ev_pulses_total_abs);
for (int i = 0; i < ev_buf; i++) {
id(g_ev_pulses_hist)[i] = p0;
}
id(g_ev_pulses_hist_index) = 0;
id(g_ev_pulses_hist_count) = ev_buf;
id(g_ev_power_avg_w) = 0.0f;
# EV rolling average update (based on absolute pulse total)
- id: ev_power_avg_update
mode: queued
then:
- lambda: |-
const int buf = ${ev_power_avg_buffer_size};
int idx = id(g_ev_pulses_hist_index);
if (idx < 0 || idx >= buf) idx = 0;
const uint32_t p_now = id(g_ev_pulses_total_abs);
id(g_ev_pulses_hist)[idx] = p_now;
idx = (idx + 1) % buf;
id(g_ev_pulses_hist_index) = idx;
if (id(g_ev_pulses_hist_count) < buf) id(g_ev_pulses_hist_count)++;
int win = ${ev_power_avg_window_samples};
if (win < 1) win = 1;
if (win > buf) win = buf;
if (id(g_ev_pulses_hist_count) < win) {
return;
}
int old_idx = idx - win;
if (old_idx < 0) old_idx += buf;
const uint32_t p_old = id(g_ev_pulses_hist)[old_idx];
const uint32_t dp = (p_now >= p_old) ? (p_now - p_old) : 0;
const float wh = ((float) dp) * (${ev_pulse_wh});
const float seconds = ((float) win) * (${ev_power_avg_sample_interval_seconds});
if (seconds <= 0.0f) {
id(g_ev_power_avg_w) = 0.0f;
return;
}
// W = Wh * 3600 / seconds
id(g_ev_power_avg_w) = wh * 3600.0f / seconds;
# Period rollover check (day/month/year) for: # Period rollover check (day/month/year) for:
# - Main total energy (sum of 3 PZEM channels) # - Main total energy (sum of 3 PZEM channels)
# - EV total energy (pulse derived) # - EV total energy (pulse derived)
@@ -1117,9 +1249,42 @@ script:
if (t < id(g_temp_month_min)) id(g_temp_month_min) = t; if (t < id(g_temp_month_min)) id(g_temp_month_min) = t;
if (t > id(g_temp_month_max)) id(g_temp_month_max) = t; if (t > id(g_temp_month_max)) id(g_temp_month_max) = t;
########################################################################################## #:########################################################################################:#
# SWITCHES # SWITCHES:
########################################################################################## #:########################################################################################:#
switch: switch:
- platform: restart - platform: restart
name: "Main Power Monitor Restart" name: "Main Power Monitor Restart"
#:########################################################################################:#
# ROLLBACK COPY (v1.1) - EV POWER SECTION (for quick revert)
# NOTE: This is commented out. Remove the new EV blocks and uncomment to restore old behavior.
#:########################################################################################:#
#sensor:
# - platform: pulse_counter
# id: ev_pulse_rate_ppm
# pin:
# number: GPIO14
# mode: ${ev_pulse_pin_mode}
# inverted: false
# update_interval: 10s
# internal_filter: ${ev_pulse_filter_ms}
# name: "${ev_power_name}"
# unit_of_measurement: "W"
# accuracy_decimals: 0
# filters:
# - lambda: |-
# return x * (${ev_pulse_wh} * 60.0f);
# total:
# id: ev_pulses_raw_total
# internal: true
# on_value:
# then:
# - lambda: |-
# uint32_t raw = (uint32_t) x;
# uint32_t last = id(g_ev_pulses_raw_last);
# if (raw < last) {
# last = 0;
# }
# id(g_ev_pulses_total_abs) += (raw - last);
# id(g_ev_pulses_raw_last) = raw;
+78 -58
View File
@@ -1,15 +1,19 @@
############################################# #:########################################################################################:#
############################################# # TITLE: MASTER BATHROOM HEATED TOWEL RAIL
# MASTER BATHROOM HEATED TOWEL RAIL # zorruno.com layout v1.0 2026
# Controlled by a Sonoff Basic #:########################################################################################:#
# # VERSIONS:
# V2.2 2026-01-30 Added Morning/Evening Timer enable switches (gate timer windows) # V2.2 2026-01-30 Added Morning/Evening Timer enable switches (gate timer windows)
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost # V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
# V1.1 2025-04-12 Fixes to timers and offline modes # V1.1 2025-04-12 Fixes to timers and offline modes
# V1.0 2025-02-14 Initial Version # V1.0 2025-02-14 Initial Version
# #:########################################################################################:#
# INSTRUCTIONS # HARDWARE:
# Controlled by a Sonoff Basic
# pinout/schematic: https://devices.esphome.io/devices/sonoff-basic-r4-v1.0/
#:########################################################################################:#
# OPERATION NOTES:
# - It allows the device to work in a standalone timer style operation # - It allows the device to work in a standalone timer style operation
# - The timer has a morning and evening time (but no weekday/weekend settings) # - The timer has a morning and evening time (but no weekday/weekend settings)
# - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot) # - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot)
@@ -23,8 +27,8 @@
# - TIMER mode will always be switched on after BOOST mode is complete # - TIMER mode will always be switched on after BOOST mode is complete
# - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown # - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot) # - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot)
# #:########################################################################################:#
# MQTT Commands # MQTT COMMANDS:
# Values will be set in place on the update_interval time, not immediately # Values will be set in place on the update_interval time, not immediately
# Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting) # Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting)
# mqtt_timer_topic/morning-on/06:00 : Time device will go on # mqtt_timer_topic/morning-on/06:00 : Time device will go on
@@ -42,14 +46,25 @@
# 1 = ON # 1 = ON
# 2 = TIMER # 2 = TIMER
# 3 = BOOST # 3 = BOOST
# #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - The towel rail will stick to its assigned schedule (and should remember on reboot)
# - Shedule times and on/off switching can still occur via MQTT
# - Other switches such as the IR Heater/Fan combo can still command the towel rail
# b) HA/MQTT OFFLINE
# With no automation controllers, the HTR will still remember its timing functions, and will
# turn on once or twice per day. If internet/wifi is still available, timing will be accurate.
# c) Internet/Wifi OFFLINE
# The HTR will still come on once or twice per day (depending on previous settings) however
# timing will likely shift. To make timing more accurate, it can be powered down then up at 12pm.
# Obviously this may drift again over time.
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-masterbathtowelrail" device_name: "esp-masterbathtowelrail"
@@ -66,6 +81,10 @@ substitutions:
ota_pass: !secret esp-masterbathtowelrail_ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-masterbathtowelrail_ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-masterbathtowelrail_ip static_ip_address: !secret esp-masterbathtowelrail_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
relay_icon: "mdi:heating-coil" relay_icon: "mdi:heating-coil"
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
@@ -79,10 +98,10 @@ substitutions:
evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260 evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260
evening_off_default: "1439" # Default in minutes from midnight. Default 23:59 => 1439 => 1440 is midnight evening_off_default: "1439" # Default in minutes from midnight. Default 23:59 => 1439 => 1440 is midnight
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -91,6 +110,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -116,10 +136,10 @@ packages:
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
@@ -175,10 +195,11 @@ esphome:
} }
- script.execute: evaluate_relay_state # Check what the relay should be doing straight away - script.execute: evaluate_relay_state # Check what the relay should be doing straight away
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
############################################# # https://esphome.io/components/esp32/
#:########################################################################################:#
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m # The original sonoff basic
restore_from_flash: true # restore some values on reboot restore_from_flash: true # restore some values on reboot
@@ -189,21 +210,21 @@ preferences:
mdns: mdns:
disabled: true disabled: true
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing 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) baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
#################################################### #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
# Relay Switch (Sonoff Basic Relay on GPIO12) # Relay Switch (Sonoff Basic Relay on GPIO12)
#################################################### #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Towel Rail Power" name: "Towel Rail Power"
@@ -239,12 +260,11 @@ switch:
on_turn_off: on_turn_off:
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
########################################################################################## #:########################################################################################:#
# Global Variables for use in automations etc # GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/guides/automations.html?highlight=globals#global-variables
########################################################################################## #:########################################################################################:#
globals: globals:
# Tracks the time (in seconds from midnight) at the previous boot # Tracks the time (in seconds from midnight) at the previous boot
- id: last_boot_time_s - id: last_boot_time_s
type: int type: int
@@ -309,10 +329,10 @@ globals:
restore_value: false restore_value: false
initial_value: "0" initial_value: "0"
########################################################################################## #:########################################################################################:#
# Text Sensors # TEST SENSORS COMPONENT:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/index.html
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
############################ ############################
@@ -514,10 +534,10 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
########################################################################################## #:########################################################################################:#
# NUMBER COMPONENT # NUMBER COMPONENT:
# https://esphome.io/components/number/index.html # https://esphome.io/components/number/index.html
########################################################################################## #:########################################################################################:#
number: number:
# A value for setting operation mode via HTTP # A value for setting operation mode via HTTP
- platform: template - platform: template
@@ -532,10 +552,10 @@ number:
// x holds the incoming value (0-3) // x holds the incoming value (0-3)
id(operation_mode) = int(x); id(operation_mode) = int(x);
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
@@ -566,10 +586,10 @@ binary_sensor:
lambda: |- lambda: |-
return id(relay).state; return id(relay).state;
########################################################################################## #:########################################################################################:#
# Sensors # SENSORS COMPONENT:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/index.html
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
name: "Timeclock: Boost Duration" name: "Timeclock: Boost Duration"
@@ -616,10 +636,10 @@ sensor:
// never return negative // never return negative
return rem > 0 ? rem : 0; return rem > 0 ? rem : 0;
################################################################################################# #:###############################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:###############################################################################################:#
button: button:
- platform: template - platform: template
name: "Boost now" name: "Boost now"
@@ -654,10 +674,10 @@ button:
- switch.turn_on: evening_timer_enable - switch.turn_on: evening_timer_enable
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:###############################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
################################################################################################# #:###############################################################################################:#
select: select:
- platform: template - platform: template
name: "Operation Mode" name: "Operation Mode"
@@ -690,10 +710,10 @@ select:
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:###############################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
################################################################################################# #:###############################################################################################:#
# Script: evaluate and drive the relay # Script: evaluate and drive the relay
script: script:
- id: evaluate_relay_state - id: evaluate_relay_state
@@ -741,10 +761,10 @@ script:
else id(relay).turn_off(); else id(relay).turn_off();
} }
################################################################################################# #:###############################################################################################:#
# INTERVAL COMPONENT # INTERVAL COMPONENT:
# https://esphome.io/components/interval.html # https://esphome.io/components/interval.html
################################################################################################# #:###############################################################################################:#
# Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state # Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state
interval: interval:
- interval: "1min" - interval: "1min"
+278 -260
View File
@@ -1,46 +1,85 @@
############################################# #:########################################################################################:#
############################################# # TITLE: OFFICE OCCUPANCY AND ENVIRONMENT
# HiLink LD1125H mmWave sensor, with BME280 Temp/Hum/Pres Sensor on an ESP32 # zorruno.com layout v1.1 2026
# https://zorruno.com/2024/mmwave-occupancy-with-esp32-ld1125h/ #:########################################################################################:#
# # REPO:
# https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-occupancyoffice.yaml
# https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/blob/main/LD1125H/ESP32-LD1125H-Complete.yaml #:########################################################################################:#
# VERSIONS:
# v1.0 2026-02-25 Updated yaml to zorruno layout V1.1
#:########################################################################################:#
# HARDWARE:
# - D1 Mini ESP32 (ESP32)
# - HiLink LD1125H mmWave sensor (UART @ 115200)
# - BME280 Temp/Humidity/Pressure sensor (I2C, addr 0x76)
# - Optional: Bluetooth Proxy / BLE tracker enabled
# #
# mth1: 0 to 2.8m sensitive # References:
# mth2: 2.8 to 8m sensitive # - https://zorruno.com/2024/mmwave-occupancy-with-esp32-ld1125h/
# mth3: above 8m sensitive # - https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main
# rmax: max distance # - https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/blob/main/LD1125H/ESP32-LD1125H-Complete.yaml
# Clearance Time: Mov/Occ to Clearance waiting time #:########################################################################################:#
# Movement Time: Mov to Occ waiting time # OPERATION NOTES:
# # - LD1125H tuning parameters:
############################################# # - mth1: 0 to 2.8m sensitive
############################################# # - mth2: 2.8 to 8m sensitive
# - mth3: above 8m sensitive
# - rmax: max distance
# - Clearance Time: Mov/Occ to Clearance waiting time
# - Movement Time: Mov to Occ waiting time
# - On boot, this device pushes mth1/mth2/mth3/rmax values to the LD1125H via UART.
# - Uses the ssieb "serial" external component to read UART lines and parse "mov/occ" lines.
# - Publishes a text occupancy state (Movement/Occupancy/Clearance) and binary sensors for:
# - mmWave Occupancy or Movement (occupancy)
# - mmWave Movement (motion)
# - BLE scanning is started/stopped based on HA API client connection (reduces BLE load when unused).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device continues running mmWave logic and environment sensors.
# - MQTT still functions; HA entities will update again when HA returns.
# b) MQTT OFFLINE (or broker unreachable)
# - Device continues running locally and via HA API (if HA is reachable).
# - MQTT-based integrations/updates will not function until MQTT returns.
# c) Entire WiFi/Network OFFLINE
# - Device continues running locally, but HA/MQTT integration is unavailable.
# - Accurate time is NOT needed (SNTP not needed): logic uses relative time (time since boot),
# but timing resets on reboot.
#:########################################################################################:#
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming
device_name: "esp-occupancyoffice" device_name: "esp-occupancyoffice"
friendly_name: "Office Occupancy & Environment" friendly_name: "Office Occupancy & Environment"
description_comment: "D1 Mini ESP32 with LD1125H mmWave and environment sensors for downstairs office" description_comment: "D1 Mini ESP32 with LD1125H mmWave and environment sensors for downstairs office (Layout V1.1)"
api_key: !secret esp-occupancyoffice_api_key #unfortunately you can't use substitutions inside secrets names device_area: "Office"
ota_pass: !secret esp-occupancyoffice_ota_pass #unfortunately you can't use substitutions inside secrets names
# Project Naming
project_name: "HiLink.LD1125H Office Occupancy"
project_version: "v1.0"
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-occupancyoffice_api_key
ota_pass: !secret esp-occupancyoffice_ota_pass
static_ip_address: !secret esp-occupancyoffice_ip static_ip_address: !secret esp-occupancyoffice_ip
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
############################################# # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# SPECIFIC PROJECT VARIABLE SUBSTITUTIONS # Don't forget to switch it back when changed.
############################################# current_ip_address: ${static_ip_address}
#
#
########################################################################################## # Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # general sensor update interval
#:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -49,416 +88,395 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include
file: common/api_common.yaml
#file: common/api_common_noencryption.yaml
vars:
local_api_key: "${api_key}"
#### MQTT #### #### MQTT ####
common_mqtt: !include common_mqtt: !include
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: ${device_name} name: "${device_name}"
friendly_name: ${friendly_name} friendly_name: "${friendly_name}"
comment: ${description_comment} #appears on the esphome page in HA comment: "${description_comment}"
min_version: 2024.6.0
area: "${device_area}" area: "${device_area}"
min_version: 2024.6.0
project:
name: "${project_name}"
version: "${project_version}"
platformio_options: platformio_options:
build_flags: build_flags:
- "-Os" # optimize for size - "-Os"
- "-Wl,--gc-sections" # drop unused code/data - "-Wl,--gc-sections"
- "-fno-exceptions" # strip C++ exceptions - "-fno-exceptions"
#- "-fno-rtti" # strip C++ RTTI # - "-fno-rtti"
on_boot: on_boot:
- priority: -200 - priority: -200
then: then:
- uart.write: - uart.write:
id: LD1125H_UART_BUS id: ld1125h_uart_bus
data: !lambda |- data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f", id(LD1125H_mth1).state) + "\r\n"; std::string th1st = "mth1=" + str_sprintf("%.0f", id(ld1125h_mth1).state) + "\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end()); return std::vector<uint8_t>(th1st.begin(), th1st.end());
- uart.write: - uart.write:
id: LD1125H_UART_BUS id: ld1125h_uart_bus
data: !lambda |- data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f", id(LD1125H_mth2).state) + "\r\n"; std::string th2st = "mth2=" + str_sprintf("%.0f", id(ld1125h_mth2).state) + "\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end()); return std::vector<uint8_t>(th2st.begin(), th2st.end());
- uart.write: - uart.write:
id: LD1125H_UART_BUS id: ld1125h_uart_bus
data: !lambda |- data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f", id(LD1125H_mth3).state) + "\r\n"; std::string th3st = "mth3=" + str_sprintf("%.0f", id(ld1125h_mth3).state) + "\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end()); return std::vector<uint8_t>(th3st.begin(), th3st.end());
- uart.write: - uart.write:
id: LD1125H_UART_BUS id: ld1125h_uart_bus
data: !lambda |- data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f", id(LD1125H_rmax).state) + "\r\n"; std::string rmaxst = "rmax=" + str_sprintf("%.1f", id(ld1125h_rmax).state) + "\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end()); return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
############################################# #:########################################################################################:#
esp32: esp32:
board: esp32dev board: esp32dev
framework: framework:
#type: arduino # type: arduino
type: esp-idf #Suggest using the ESP-IDF Framework. Changing from arduino to esp-idf needs a cabled download to change partitions type: esp-idf
version: recommended #recommended, latest or dev version: recommended
############################################# #:########################################################################################:#
# ESPHome external or custom components to use # EXTERNAL COMPONENTS
# https://esphome.io/components/external_components.html # https://esphome.io/components/external_components.html
# https://github.com/ssieb/esphome_components/tree/master/components/serial #:########################################################################################:#
#############################################
external_components: external_components:
- source: - source:
type: git type: git
url: https://github.com/ssieb/custom_components #Thanks for @ssieb components. url: https://github.com/ssieb/custom_components
components: [ serial ] #text_sensor that reads lines for a uart. Also, a sensor that reads single binary values from the uart. components: [ serial ]
############################################# #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
############################################# #:########################################################################################:#
# Enable the Home Assistant API # API (Home Assistant)
# https://esphome.io/components/api.html # https://esphome.io/components/api.html
############################################# #:########################################################################################:#
api: api:
encryption: encryption:
key: ${api_key} key: "${api_key}"
#key: "puCd6EGmFp3hU56N8dOo5u17bXwDr0aVRWiDoNdPDoE="
on_client_connected: on_client_connected:
- esp32_ble_tracker.start_scan: - esp32_ble_tracker.start_scan:
continuous: true continuous: true
on_client_disconnected: on_client_disconnected:
- esp32_ble_tracker.stop_scan: - esp32_ble_tracker.stop_scan:
#:########################################################################################:#
# I2C BUS (BME280)
#############################################
# i2c bus
# https://esphome.io/components/i2c.html # https://esphome.io/components/i2c.html
# 10, 50, 100, 200, 800 are possible settings #:########################################################################################:#
# for frequency, 50kHz is default
#############################################
i2c: i2c:
sda: GPIO19 sda: GPIO19
scl: GPIO21 scl: GPIO21
scan: True #look for devices on boot up and report scan: true
frequency: 50kHz frequency: 50kHz
############################################# #:########################################################################################:#
# UART Serial # UART (LD1125H)
# hardware on EPS32, but software, and can be glitchy on ESP8266
# https://esphome.io/components/uart.html # https://esphome.io/components/uart.html
############################################# #:########################################################################################:#
uart: uart:
id: LD1125H_UART_BUS id: ld1125h_uart_bus
rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang rx_pin: GPIO16
tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17
baud_rate: 115200 baud_rate: 115200
data_bits: 8 data_bits: 8
stop_bits: 1 stop_bits: 1
parity: NONE parity: NONE
############################################# #:########################################################################################:#
# Bluetooth # BLUETOOTH PROXY / BLE TRACKER
# https://esphome.io/components/bluetooth_proxy.html # https://esphome.io/components/bluetooth_proxy.html
# https://esphome.io/components/esp32_ble_tracker.html # https://esphome.io/components/esp32_ble_tracker.html
# Remember that this takes a LOT of processing. On the #:########################################################################################:#
# ESP32, enable the IDF framework, and disable the
# Web server component. Changing to the IDF framework
# needs to be via cable not OTA to change the
# partition setup.
#############################################
bluetooth_proxy: bluetooth_proxy:
active: true active: true
cache_services: true cache_services: true
esp32_ble_tracker: esp32_ble_tracker:
scan_parameters: scan_parameters:
continuous: false continuous: false
############################################# #:########################################################################################:#
# Global Variables for use in automations etc # GLOBALS
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/components/globals.html
############################################# #:########################################################################################:#
globals: globals:
- id: LD1125H_Last_Time - id: ld1125h_last_time
type: time_t type: time_t
restore_value: no restore_value: false
#initial_value: time(NULL)
#initial_value: !lambda 'return ::time(nullptr);'
initial_value: "0" initial_value: "0"
- id: LD1125H_Last_Mov_Time
- id: ld1125h_last_mov_time
type: time_t type: time_t
restore_value: no restore_value: false
#initial_value: time(NULL)
#initial_value: !lambda 'return ::time(nullptr);'
initial_value: "0" initial_value: "0"
- id: LD1125H_Clearence_Status
- id: ld1125h_clearance_status
type: bool type: bool
restore_value: no restore_value: false
initial_value: "false" initial_value: "false"
############################################# #:########################################################################################:#
# General esp status LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
############################################# #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 #ESP32 Onboard LED number: GPIO2
ignore_strapping_warning: True #https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins ignore_strapping_warning: true
inverted: false inverted: false
############################################# #:########################################################################################:#
# Interval Automations # INTERVAL (Clearance scan)
# https://esphome.io/guides/automations.html # https://esphome.io/components/interval.html
############################################# #:########################################################################################:#
interval: interval:
- interval: 1s # Clearance Scan Time - interval: 1s
setup_priority: -200 setup_priority: -200
then: then:
- lambda: |- - lambda: |-
// Use the global C time() function (::time(nullptr)) if ((::time(nullptr) - id(ld1125h_last_time)) > id(ld1125h_clear_time).state) {
if ((::time(nullptr) - id(LD1125H_Last_Time)) > id(LD1125H_Clear_Time).state) { if ((id(ld1125h_clearance_status) == false) ||
if ((id(LD1125H_Clearence_Status) == false) || (id(ld1125h_occupancy).state != "Clearance")) {
(id(LD1125H_Occupancy).state != "Clearance")) { id(ld1125h_occupancy).publish_state("Clearance");
id(LD1125H_Occupancy).publish_state("Clearance"); id(ld1125h_clearance_status) = true;
id(LD1125H_Clearence_Status) = true;
} }
if (id(LD1125H_MovOcc_Binary).state == true) { if (id(ld1125h_movocc_binary).state == true) {
id(LD1125H_MovOcc_Binary).publish_state(false); id(ld1125h_movocc_binary).publish_state(false);
} }
if (id(LD1125H_Mov_Binary).state == true) { if (id(ld1125h_mov_binary).state == true) {
id(LD1125H_Mov_Binary).publish_state(false); id(ld1125h_mov_binary).publish_state(false);
} }
// Update the last-seen timestamp id(ld1125h_last_time) = ::time(nullptr);
id(LD1125H_Last_Time) = ::time(nullptr);
} }
############################################# #:########################################################################################:#
# Number Sensors (custom component) # NUMBER (LD1125H controls)
# refer https://github.com/ssieb/esphome_components/tree/master/components/serial # https://esphome.io/components/number/
############################################# #:########################################################################################:#
number: number:
- platform: template - platform: template
name: "0-2.8m Sensitivity" # mth1 is 0~2.8m Sensitivity. name: "0-2.8m Sensitivity"
id: LD1125H_mth1 id: ld1125h_mth1
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "60.0" #Default mth1 Setting initial_value: "60.0"
min_value: 10.0 min_value: 10.0
max_value: 600.0 max_value: 600.0
step: 5.0 step: 5.0
set_action: set_action:
then: - uart.write:
- uart.write: id: ld1125h_uart_bus
id: LD1125H_UART_BUS data: !lambda |-
data: !lambda |- std::string th1st = "mth1=" + str_sprintf("%.0f", x) + "\r\n";
std::string th1st = "mth1=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector<uint8_t>(th1st.begin(), th1st.end());
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- platform: template - platform: template
name: "2.8-8m Sensitivity" # mth2 is 2.8~8m Sensitivity. name: "2.8-8m Sensitivity"
id: LD1125H_mth2 id: ld1125h_mth2
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true # If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "30" # Default mth2 Setting initial_value: "30"
min_value: 5 min_value: 5
max_value: 300 max_value: 300
step: 5 step: 5
set_action: set_action:
then: - uart.write:
- uart.write: id: ld1125h_uart_bus
id: LD1125H_UART_BUS data: !lambda |-
data: !lambda |- std::string th2st = "mth2=" + str_sprintf("%.0f", x) + "\r\n";
std::string th2st = "mth2=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector<uint8_t>(th2st.begin(), th2st.end());
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- platform: template - platform: template
name: "8m+ Sensitivity" # mth3 is above 8m Sensitivity. name: "8m+ Sensitivity"
id: LD1125H_mth3 id: ld1125h_mth3
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true # If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "20" # Default mth3 Setting initial_value: "20"
min_value: 5 min_value: 5
max_value: 200 max_value: 200
step: 5 step: 5
set_action: set_action:
then: - uart.write:
- uart.write: id: ld1125h_uart_bus
id: LD1125H_UART_BUS data: !lambda |-
data: !lambda |- std::string th3st = "mth3=" + str_sprintf("%.0f", x) + "\r\n";
std::string th3st = "mth3=" + str_sprintf("%.0f",x) +"\r\n"; return std::vector<uint8_t>(th3st.begin(), th3st.end());
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- platform: template - platform: template
name: "Max Detection (m)" # rmax is max detection distance. name: "Max Detection (m)"
id: LD1125H_rmax id: ld1125h_rmax
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "8" #Default rmax Setting initial_value: "8"
min_value: 0.4 min_value: 0.4
max_value: 12 max_value: 12
step: 0.1 step: 0.1
set_action: set_action:
then: - uart.write:
- uart.write: id: ld1125h_uart_bus
id: LD1125H_UART_BUS data: !lambda |-
data: !lambda |- std::string rmaxst = "rmax=" + str_sprintf("%.1f", x) + "\r\n";
std::string rmaxst = "rmax=" + str_sprintf("%.1f",x) +"\r\n"; return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
- platform: template - platform: template
name: "Clearence Time (s)" name: "Clearence Time (s)"
id: LD1125H_Clear_Time id: ld1125h_clear_time
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "5" #LD1125H Mov/Occ > Clearence Time Here initial_value: "5"
min_value: 0.5 min_value: 0.5
max_value: 20 max_value: 20
step: 0.5 step: 0.5
- platform: template - platform: template
name: "Movement Time (s)" name: "Movement Time (s)"
id: LD1125H_Mov_Time id: ld1125h_mov_time
icon: "mdi:cogs" icon: "mdi:cogs"
optimistic: true optimistic: true
restore_value: true #If you don't want to store the setting at ESP, set it to false. restore_value: true
initial_value: "1" #LD1125H Mov > Occ Time Here initial_value: "1"
min_value: 0.5 min_value: 0.5
max_value: 10 max_value: 10
step: 0.5 step: 0.5
############################################# #:########################################################################################:#
# General Sensors # SENSOR
# https://esphome.io/components/sensor/index.html # https://esphome.io/components/sensor/
############################################# #:########################################################################################:#
sensor: sensor:
- platform: bme280_i2c - platform: bme280_i2c
temperature: temperature:
name: "Temperature" name: "Temperature"
accuracy_decimals: 1 accuracy_decimals: 1
oversampling: 2x oversampling: 2x
pressure: pressure:
name: "Pressure" name: "Pressure"
oversampling: 2x oversampling: 2x
humidity: humidity:
name: "Humidity" name: "Humidity"
accuracy_decimals: 1 accuracy_decimals: 1
oversampling: 2x oversampling: 2x
address: 0x76 address: 0x76
update_interval: ${update_interval} update_interval: "${update_interval}"
- platform: template - platform: template
name: "mmWave Distance" name: "mmWave Distance"
id: LD1125H_Distance id: ld1125h_distance
icon: "mdi:signal-distance-variant" icon: "mdi:signal-distance-variant"
unit_of_measurement: "m" unit_of_measurement: "m"
accuracy_decimals: 2 accuracy_decimals: 2
filters: # Use Fliter To Debounce filters:
- sliding_window_moving_average: - sliding_window_moving_average:
window_size: 8 window_size: 8
send_every: 2 send_every: 2
- heartbeat: 0.2s - heartbeat: 0.2s
############################################# #:########################################################################################:#
# Text Sensors # TEXT SENSOR
# refer https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/
############################################# #:########################################################################################:#
text_sensor: text_sensor:
- platform: serial - platform: serial
uart_id: LD1125H_UART_BUS uart_id: ld1125h_uart_bus
name: ${friendly_name} LD1125H UART Text name: "${friendly_name} LD1125H UART Text"
id: LD1125H_UART_Text id: ld1125h_uart_text
icon: "mdi:format-text" icon: "mdi:format-text"
internal: True internal: true
on_value: on_value:
lambda: |- lambda: |-
if (id(LD1125H_UART_Text).state.substr(0,3) == "occ") { if (id(ld1125h_uart_text).state.substr(0, 3) == "occ") {
id(LD1125H_Distance).publish_state( id(ld1125h_distance).publish_state(
atof(id(LD1125H_UART_Text).state.substr(9).c_str()) atof(id(ld1125h_uart_text).state.substr(9).c_str())
); );
if ((::time(nullptr) - id(LD1125H_Last_Mov_Time)) > if ((::time(nullptr) - id(ld1125h_last_mov_time)) >
id(LD1125H_Mov_Time).state) { id(ld1125h_mov_time).state) {
id(LD1125H_Occupancy).publish_state("Occupancy"); id(ld1125h_occupancy).publish_state("Occupancy");
if (id(LD1125H_MovOcc_Binary).state == false) { if (id(ld1125h_movocc_binary).state == false) {
id(LD1125H_MovOcc_Binary).publish_state(true); id(ld1125h_movocc_binary).publish_state(true);
} }
if (id(LD1125H_Mov_Binary).state == true) { if (id(ld1125h_mov_binary).state == true) {
id(LD1125H_Mov_Binary).publish_state(false); id(ld1125h_mov_binary).publish_state(false);
} }
} }
if (id(LD1125H_MovOcc_Binary).state == false) { if (id(ld1125h_movocc_binary).state == false) {
id(LD1125H_MovOcc_Binary).publish_state(true); id(ld1125h_movocc_binary).publish_state(true);
} }
// Update both last-movement and last-anything timestamps id(ld1125h_last_time) = ::time(nullptr);
id(LD1125H_Last_Time) = ::time(nullptr); if (id(ld1125h_clearance_status) == true) {
if (id(LD1125H_Clearence_Status) == true) { id(ld1125h_clearance_status) = false;
id(LD1125H_Clearence_Status) = false;
} }
} }
else if (id(LD1125H_UART_Text).state.substr(0,3) == "mov") { else if (id(ld1125h_uart_text).state.substr(0, 3) == "mov") {
id(LD1125H_Distance).publish_state( id(ld1125h_distance).publish_state(
atof(id(LD1125H_UART_Text).state.substr(9).c_str()) atof(id(ld1125h_uart_text).state.substr(9).c_str())
); );
id(LD1125H_Occupancy).publish_state("Movement"); id(ld1125h_occupancy).publish_state("Movement");
if (id(LD1125H_MovOcc_Binary).state == false) { if (id(ld1125h_movocc_binary).state == false) {
id(LD1125H_MovOcc_Binary).publish_state(true); id(ld1125h_movocc_binary).publish_state(true);
} }
if (id(LD1125H_Mov_Binary).state == false) { if (id(ld1125h_mov_binary).state == false) {
id(LD1125H_Mov_Binary).publish_state(true); id(ld1125h_mov_binary).publish_state(true);
} }
// Update both movement-specific and general timestamps id(ld1125h_last_mov_time) = ::time(nullptr);
id(LD1125H_Last_Mov_Time) = ::time(nullptr); id(ld1125h_last_time) = ::time(nullptr);
id(LD1125H_Last_Time) = ::time(nullptr); if (id(ld1125h_clearance_status) == true) {
if (id(LD1125H_Clearence_Status) == true) { id(ld1125h_clearance_status) = false;
id(LD1125H_Clearence_Status) = false;
} }
} }
- platform: template - platform: template
name: "mmWave Occupancy" name: "mmWave Occupancy"
id: LD1125H_Occupancy id: ld1125h_occupancy
icon: "mdi:motion-sensor" icon: "mdi:motion-sensor"
############################################# #:########################################################################################:#
# Binary Sensors # BINARY SENSOR
# https://esphome.io/components/binary_sensor/index.html # https://esphome.io/components/binary_sensor/
############################################# #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: template - platform: template
name: "mmWave Occupancy or Movement" name: "mmWave Occupancy or Movement"
id: LD1125H_MovOcc_Binary id: ld1125h_movocc_binary
device_class: occupancy device_class: occupancy
- platform: template - platform: template
name: "mmWave Movement" name: "mmWave Movement"
id: LD1125H_Mov_Binary id: ld1125h_mov_binary
device_class: motion device_class: motion
+146 -197
View File
@@ -1,58 +1,96 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: STAIR OCCUPANCY AND UNDERHOUSE ENVIRONMENT
# HiLink LD2410 mmWave sensor, with BME280 Temp/Hum/Pres Sensor and PIR on an ESP32 # zorruno.com layout v1.1 2026
# VERSION #:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-occupancystair.yaml
#:########################################################################################:#
# VERSIONS:
# V2.2 2026-02-25 Updated yaml to zorruno layout V1.1
# V2.1 2025-08-25 Added some MQTT to send commands to turn on remote lights # V2.1 2025-08-25 Added some MQTT to send commands to turn on remote lights
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
#:########################################################################################:#
# HARDWARE:
# D1 Mini ESP32 with:
# - HiLink LD2410 mmWave presence sensor (UART)
# - BME280 Temp/Humidity/Pressure sensor (I2C)
# - Generic PIR sensor (GPIO)
# #
# https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main # References:
# https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/blob/main/LD1125H/ESP32-LD1125H-Complete.yaml # - https://esphome.io/components/sensor/ld2410.html
# - https://www.simplysmart.house/blog/presence-detection-ld2410-home-assistant
# - https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main
#:########################################################################################:#
# OPERATION NOTES:
# - Provides mmWave presence (moving/still) plus PIR motion.
# - Provides environment sensors (BME280).
# - When mmWave presence/moving target or PIR triggers, a script publishes MQTT commands to a remote
# light controller (e.g. stair footer lights) for a configurable auto-on duration.
# - Auto control can be enabled/disabled with "Stair Footer Lights Auto".
# - Auto duration is controlled by "Stair Footer Lights Auto Time" (seconds).
# - LD2410 exposes configuration entities (numbers/selects/switches/buttons/text sensors).
#:########################################################################################:#
# MQTT COMMANDS:
# This device publishes MQTT commands to a remote device:
# - Topic: ${mqtt_remote_device1_command_topic}
# - Payloads: ${mqtt_remote_device_command_ON}, ${mqtt_remote_device_command_OFF}
# #
# https://esphome.io/components/sensor/ld2410.html # Example (as configured by substitutions):
# https://www.simplysmart.house/blog/presence-detection-ld2410-home-assistant # - ${mqtt_command_main_topic}/stair-footerlights -> ON, OFF
# #:########################################################################################:#
# The B and C versions of this device can use Bluetooth, but we are not using it here. # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
########################################################################################## # - mmWave/PIR and BME280 sensing continues locally.
# - Remote light control via MQTT publish continues (auto script still publishes).
# - HA entities are unavailable until HA returns.
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Sensing continues and HA API entities remain available.
# - Remote light control will NOT work (MQTT publishes fail while MQTT is down).
# c) Entire WiFi/Network OFFLINE
# - Sensing continues locally, but no HA API and no MQTT remote control.
# - SNTP is not needed (no timeclocks used).
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-occupancystair" device_name: "esp-occupancystair"
friendly_name: "Stair Occupancy and Underhouse Environment" friendly_name: "Stair Occupancy and Underhouse Environment"
description_comment: "D1 Mini ESP32 with LD2410 mmWave for internal stairwell and environment sensors for under house" description_comment: "D1 Mini ESP32 with LD2410 mmWave for internal stairwell and environment sensors for under house (Layout V1.1)"
device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Generic.ESP32" # Project Details project_name: "Generic.ESP32"
project_version: "v2.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v2.2" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names) # Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-occupancystair_ip static_ip_address: !secret esp-occupancystair_ip
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
#relay_icon: "mdi:lightbulb-group" log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE update_interval: "60s" # update time for general sensors etc
update_interval: "60s" # update time for for general sensors etc
# MQTT REMOTE Controls # MQTT REMOTE Controls
mqtt_remote_device1_name: "stair-footerlights" mqtt_remote_device1_name: "stair-footerlights"
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}" mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}"
#mqtt_remote_device1_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device1_name}/state"
mqtt_remote_device_command_ON: "ON" mqtt_remote_device_command_ON: "ON"
mqtt_remote_device_command_OFF: "OFF" mqtt_remote_device_command_OFF: "OFF"
######################################################################################### #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -61,6 +99,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -74,163 +113,102 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome CORE CONFIGURATION # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # appears on the esphome page in HA comment: "${description_comment}" # appears on the esphome page in HA
area: "${device_area}"
min_version: 2024.6.0 min_version: 2024.6.0
area: "${device_area}"
#on_boot: # Initial Setting, will remember previous values (if set)
#priority: -200
#then:
########################################################################################## #:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp8266.html
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32.html
########################################################################################## #:########################################################################################:#
esp32: esp32:
board: esp32dev board: esp32dev
framework: framework:
type: esp-idf # "esp-idf" OR "arduino". Suggested ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang. type: esp-idf # "esp-idf" OR "arduino"
version: recommended # recommended, latest or dev version: recommended
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES:
# https://esphome.io/components/globals.html # https://esphome.io/components/globals.html
########################################################################################## #:########################################################################################:#
globals: globals:
- id: stair_footer_auto_default_s - id: stair_footer_auto_default_s
type: int type: int
restore_value: yes restore_value: true
initial_value: '20' initial_value: "20"
########################################################################################## #:########################################################################################:#
# i2c BUS COMPONENT # I2C BUS:
# https://esphome.io/components/i2c.html # https://esphome.io/components/i2c.html
########################################################################################## #:########################################################################################:#
i2c: i2c:
sda: GPIO19 sda: GPIO19
scl: GPIO21 scl: GPIO21
scan: True scan: true
frequency: 100kHz #10, 50, 100, 200, 800 are possible settings, 100kHz was reliable for me frequency: 100kHz
########################################################################################## #:########################################################################################:#
# LOGGER COMPONENT # LOGGING:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
# Logs all log messages through the serial port and through MQTT topics. #:########################################################################################:#
##########################################################################################
logger: logger:
level: INFO # INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# BLUETOOTH # UART:
# Proxy https://esphome.io/components/bluetooth_proxy.html
# BLE https://esphome.io/components/esp32_ble_tracker.html
# Remember that this takes a LOT of processing. On the
# ESP32, enable the IDF framework, and disable the
# Web server component. Changing to the IDF framework
# needs to be via cable not OTA to change the
# partition setup.
##########################################################################################
#bluetooth_proxy:
#esp32_ble_tracker:
##########################################################################################
# UART BUS
# hardware on EPS32, but software (and can be glitchy) on ESP8266
# https://esphome.io/components/uart.html # https://esphome.io/components/uart.html
########################################################################################## #:########################################################################################:#
uart: uart:
id: ld2410_uart id: ld2410_uart
rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang rx_pin: GPIO16
tx_pin: GPIO17 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang tx_pin: GPIO17
baud_rate: 256000 # default for LD2410 is 25600, 8, 0, NONE baud_rate: 256000
data_bits: 8 data_bits: 8
stop_bits: 1 stop_bits: 1
parity: NONE parity: NONE
######################################################################################### #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
######################################################################################### #:########################################################################################:#
# ESP32 D1 Mini Board: Onboard Status LED on GPIO2, active-low
#########################################################################################
status_led: status_led:
pin: pin:
number: GPIO2 # ESP32 Onboard LED number: GPIO2
ignore_strapping_warning: True #https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins ignore_strapping_warning: true
inverted: false inverted: false
########################################################################################## #:########################################################################################:#
# LD2410 Sensors # LD2410:
# https://esphome.io/components/sensor/ld2410.html # https://esphome.io/components/sensor/ld2410.html
# https://www.hlktech.net/index.php?id=988 #:########################################################################################:#
##########################################################################################
ld2410: ld2410:
uart_id: ld2410_uart uart_id: ld2410_uart
#uart_id (Optional, ID): Manually specify the ID of the UART Component if you want to use multiple UART buses.
#throttle (Optional, int): Time in milliseconds to control the rate of data updates. Defaults to 1000ms.
#id (Optional, ID): Manually specify the ID for this LD2410 Sensor component if you need multiple components.
# light (Optional, int): When in engineering mode, indicates the light sensitivity, otherwise unknown. Value between 0 and 255 inclusive. Though it seems that the value 85 is the lowest value at complete darkness. All options from Sensor. #:########################################################################################:#
# moving_distance (Optional, int): Distance in cm of detected moving target. All options from Sensor. # NUMBER COMPONENT:
# still_distance (Optional, int): Distance in cm of detected still target. All options from Sensor.
# moving_energy (Optional, int): Energy for moving target. Value between 0 and 100 inclusive. All options from Sensor.
# still_energy (Optional, int): Energy for still target. Value between 0 and 100 inclusive. All options from Sensor.
# detection_distance (Optional, int): Distance in cm of target. All options from Sensor.
# gX (Optional): Energies for the Xth gate (X => 0 to 8).
# move_energy (Optional, int): When in engineering mode, the move energy of the gate, otherwise unknown. Value between 0 and 100 inclusive. All options from Sensor.
#still_energy (Optional, int): When in engineering mode, the still energy of the gate, otherwise unknown. Value between 0 and 100 inclusive. All options from Sensor.
#ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component if you are using multiple components.
##########################################################################################
# NUMBER COMPONENT
# https://esphome.io/components/number/ # https://esphome.io/components/number/
########################################################################################## #:########################################################################################:#
#The ld2410 number values for setting thresholds
# timeout: 5s
# max_move_distance: 2.25m
# max_still_distance: 2.25m
# g0_move_threshold: 40 # 0m / 0'
# g0_still_threshold: 10 # 0m / 0'
# g1_move_threshold: 40 # 0 - 0.75m / 0 - 2.46'
# g1_still_threshold: 10 # 0 - 0.75m / 0 - 2.46'
# g2_move_threshold: 40 # 0.75 - 1.5m / 2.46' - 4.92'
# g2_still_threshold: 10 # 0.75 - 1.5m / 2.46' - 4.92'
# g3_move_threshold: 40 # 1.5 - 2.25m / 4.92' - 7.38'
# g3_still_threshold: 10 # 1.5 - 2.25m / 4.92' - 7.38'
# g4_move_threshold: 40 # 2.25 - 3m' / 7.38' - 9.84'
# g4_still_threshold: 40 # 2.25 - 3m' / 7.38' - 9.84'
# g5_move_threshold: 40 # 3 - 3.75 / 9.84' - 12.30'
# g5_still_threshold: 40 # 3 - 3.75 / 9.84' - 12.30'
# g6_move_threshold: 30 # 3.75 - 4.5m / 12.30' - 14.76'
# g6_still_threshold: 15 # 3.75 - 4.5m / 12.30' - 14.76'
# g7_move_threshold: 30 # 4.5 - 5.25m / 14.76' - 17.22'
# g7_still_threshold: 15 # 4.5 - 5.25m / 14.76' - 17.22'
# g8_move_threshold: 30 # 5.25 - 6m / 17.22' - 19.68'
# g8_still_threshold: 15 # 5.25 - 6m / 17.22' - 19.68'
number: number:
- platform: ld2410 - platform: ld2410
timeout: timeout:
@@ -290,7 +268,7 @@ number:
- platform: template - platform: template
id: stair_footer_auto_time_s id: stair_footer_auto_time_s
name: "Stair Footer Lights Auto Time" name: "Stair Footer Lights Auto Time"
unit_of_measurement: s unit_of_measurement: "s"
min_value: 10 min_value: 10
max_value: 300 max_value: 300
step: 1 step: 1
@@ -298,26 +276,13 @@ number:
restore_value: true restore_value: true
initial_value: 20 initial_value: 20
######################################################################################### #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
######################################################################################### #:########################################################################################:#
# LD2410 SELECT
# distance_resolution (Optional): Control the gates distance resolution. Can be 0.75m or 0.2m.
# Defaults to 0.75m. All options from Select.
# baud_rate (Optional): Control the serial port baud rate. Defaults to 256000. Once changed,
# all sensors will stop working until a fresh install with an updated UART Component
# configuration. All options from Select.
# light_function (Optional): If set, will affect the OUT pin value, based on light
# threshold. Can be off, low or above. Defaults to off. All options from Select.
# out_pin_level (Optional): Control OUT pin away value. Can be low or high. Defaults
# to low. All options from Select.
# ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component
# if you are using multiple components.
#########################################################################################
select: select:
- platform: ld2410 - platform: ld2410
distance_resolution: distance_resolution:
name: "${friendly_name} LD2140 Distance Resolution" name: "${friendly_name} LD2140 Distance Resolution"
baud_rate: baud_rate:
name: "${friendly_name} LD2140 Baud Rate" name: "${friendly_name} LD2140 Baud Rate"
@@ -326,28 +291,26 @@ select:
out_pin_level: out_pin_level:
name: "${friendly_name} LD2140 Out Pin Level" name: "${friendly_name} LD2140 Out Pin Level"
########################################################################################## #:########################################################################################:#
# SENSOR COMPONENT # SENSOR COMPONENT:
# https://esphome.io/components/sensor/ # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: bme280_i2c - platform: bme280_i2c
temperature: temperature:
name: "Temperature" name: "Temperature"
accuracy_decimals: 1 accuracy_decimals: 1
oversampling: 2x oversampling: 2x
pressure: pressure:
name: "Pressure" name: "Pressure"
oversampling: 2x oversampling: 2x
humidity: humidity:
name: "Humidity" name: "Humidity"
accuracy_decimals: 1 accuracy_decimals: 1
oversampling: 2x oversampling: 2x
address: 0x76 address: 0x76
update_interval: "${update_interval}" update_interval: "${update_interval}"
# The ld2410 sensor values
# https://esphome.io/components/sensor/ld2410/#sensor
- platform: ld2410 - platform: ld2410
light: light:
name: "Light" name: "Light"
@@ -407,20 +370,16 @@ sensor:
still_energy: still_energy:
name: "g8 still energy" name: "g8 still energy"
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
# The ld2410 switch allows you to control your LD2410 Sensor.
# Bluetooth switch is only useful of you have a B or C model
##########################################################################################
switch: switch:
# https://esphome.io/components/sensor/ld2410/#switch
- platform: ld2410 - platform: ld2410
engineering_mode: engineering_mode:
name: "${friendly_name} LD2140 Engineering Mode" name: "${friendly_name} LD2140 Engineering Mode"
#bluetooth: #bluetooth:
#name: "${friendly_name} LD2140 Control Bluetooth" # name: "${friendly_name} LD2140 Control Bluetooth"
- platform: template - platform: template
id: stair_footer_auto_enabled id: stair_footer_auto_enabled
@@ -428,13 +387,11 @@ switch:
optimistic: true optimistic: true
restore_mode: RESTORE_DEFAULT_ON restore_mode: RESTORE_DEFAULT_ON
######################################################################################### #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
######################################################################################### #:########################################################################################:#
binary_sensor: binary_sensor:
# The ld2410 binary sensors to get presence notification
# https://esphome.io/components/sensor/ld2410/#binary-sensor
- platform: ld2410 - platform: ld2410
has_target: has_target:
name: "mmWave Presence" name: "mmWave Presence"
@@ -458,8 +415,7 @@ binary_sensor:
name: "LD2140 Out Pin Presence Status" name: "LD2140 Out Pin Presence Status"
entity_category: diagnostic entity_category: diagnostic
# Generic PIR Sensor # Generic PIR Sensor (GPIO13)
# https://devices.esphome.io/devices/Generic-PIR
- platform: gpio - platform: gpio
pin: pin:
number: GPIO13 number: GPIO13
@@ -478,12 +434,10 @@ binary_sensor:
then: then:
- script.execute: stair_footer_auto_script - script.execute: stair_footer_auto_script
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
# The ld2410 button allows resetting
#################################################################################################
button: button:
- platform: ld2410 - platform: ld2410
factory_reset: factory_reset:
@@ -493,27 +447,22 @@ button:
query_params: query_params:
name: "Query Parameters" name: "Query Parameters"
################################################################################################# #:########################################################################################:#
# TEXT SENSOR COMPONENT # TEXT SENSOR COMPONENT:
# https://esphome.io/components/text_sensor/ # https://esphome.io/components/text_sensor/
################################################################################################# #:########################################################################################:#
text_sensor: text_sensor:
# The ld2410 text sensor allows you to get information about your LD2410 Sensor.
# Bluetooth sensor is only useful of you have a B or C model
# https://esphome.io/components/sensor/ld2410/#text-sensor
- platform: ld2410 - platform: ld2410
version: version:
name: "${friendly_name} LD2140 Firmware Version" name: "${friendly_name} LD2140 Firmware Version"
#mac_address: #mac_address:
#name: "${friendly_name} LD2140 BT MAC Address" # name: "${friendly_name} LD2140 BT MAC Address"
########################################################################################## #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call. #:########################################################################################:#
##########################################################################################
script: script:
# Sends commands to turn on and off a remote light
- id: stair_footer_auto_script - id: stair_footer_auto_script
mode: restart mode: restart
then: then:
@@ -524,10 +473,10 @@ script:
retain: false retain: false
# Wait for the HA-adjustable timeout # Wait for the HA-adjustable timeout
- delay: !lambda 'return (uint32_t)(id(stair_footer_auto_time_s).state) * 1000;' - delay: !lambda "return (uint32_t)(id(stair_footer_auto_time_s).state) * 1000;"
# Turn lights back off # Turn lights back off
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_remote_device1_command_topic}" topic: "${mqtt_remote_device1_command_topic}"
payload: "${mqtt_remote_device_command_OFF}" payload: "${mqtt_remote_device_command_OFF}"
retain: false retain: false
+108 -79
View File
@@ -1,51 +1,78 @@
############################################# #:########################################################################################:#
############################################# # TITLE: OFFICE MAIN LIGHTSWITCH
# OFFICE MAIN LIGHTSWITCH # zorruno.com layout v1.1 2026
# V2.0 2025-06-05 YAML Tidyups #:########################################################################################:#
# V1.0 2025-05-31 Initial Version # REPO:
############################################# # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-officelights.yaml
# Zemismart KS-811 Triple push button #:########################################################################################:#
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/ # VERSIONS:
# v2.1 2026-02-25 Updated yaml to zorruno layout V1.1
# v2.0 2025-06-05 YAML Tidyups
# v1.0 2025-05-31 Initial Version
#:########################################################################################:#
# HARDWARE:
# - Zemismart KS-811 Triple push button (ESP8266)
# - Pinout/Schematic: https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# - Office 3-gang KS-811 (Triple) wall switch.
# - Button 1 toggles Relay 1 (Nighttime Lights) - only relay actually wired to a load.
# - Button 2 toggles Relay 2 (Daytime Lights) - virtual only (no physical load connected).
# - Button 3 toggles Relay 3 (Spare) - virtual only (no physical load connected).
# - GPIO16 does not support interrupts; polling is used for Button 1.
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, WiFi OK
# - Physical buttons still control relays locally.
# - MQTT is optional; device operates as a normal switch without HA.
# #
# NOTES # b) MQTT OFFLINE (or broker unreachable)
# - # - Physical buttons still control relays locally.
# - HA/API control (if available) still works, but no MQTT command/status.
# #
############################################# # c) Entire WiFi/Network OFFLINE
############################################# # - Physical buttons still control relays locally.
# - Accurate time is NOT needed (SNTP not needed).
#:########################################################################################:#
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS #:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
############################################# #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-officelights" device_name: "esp-officelights"
friendly_name: "Office Main Lightswitch (3)" friendly_name: "Office Main Lightswitch (3)"
description_comment: "Office Main Lightswitch using a Zemismart KS-811 Triple Push Button. Bunker Light A (1), Spare A (2), Spare B (3)" description_comment: "Office Main Lightswitch using a Zemismart KS-811 Triple Push Button. Bunker Light A (1), Spare A (2), Spare B (3) (Layout V1.1)"
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Office"
# Project Naming
project_name: "Zemismart Technologies.KS-811 Triple" # Project Details
project_version: "v2.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Project Naming
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names project_name: "Zemismart Technologies.KS-811 Triple"
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names project_version: "v2.1"
# Passwords & Secrets
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-officelights_ip static_ip_address: !secret esp-officelights_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "INFO"
update_interval: "60s" # update time for for general sensors etc update_interval: "60s"
# Switch Naming # Switch Naming
switch_1_name: "Nighttime Lights" # Only one light (Bunker Light) actually connected to this relay switch_1_name: "Nighttime Lights" # Only one light (Bunker Light) actually connected to this relay
switch_2_name: "Daytime Lights" # This is virtual only, no power connected to 2nd relay switch_2_name: "Daytime Lights" # Virtual only, no power connected to 2nd relay
switch_3_name: "Spare" # This is virtual only, no power connected to 3rd relay switch_3_name: "Spare" # Virtual only, no power connected to 3rd relay
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -54,6 +81,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -67,111 +95,112 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" 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 #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
############################################# #:########################################################################################:#
# ESPHome # ESPHOME
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
############################################# #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}"
area: "${device_area}" area: "${device_area}"
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
# on_boot: #on_boot:
# priority: 200 # priority: 200
# then: # then:
# - switch.turn_on: Relay_3 # - switch.turn_on: relay_3
############################################# #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
############################################# #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True. early_pin_init: false
board_flash_mode: dout # Default is dout board_flash_mode: dout
############################################# #:########################################################################################:#
# ESPHome Logging Enable # LOGGING
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
############################################# #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) #baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
id: logger_id id: logger_id
############################################# #:########################################################################################:#
# STATUS LED # STATUS LED
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
############################################# #:########################################################################################:#
status_led: status_led:
pin: pin:
number: GPIO2 number: GPIO2
inverted: yes inverted: true
############################################# #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
############################################# #:########################################################################################:#
binary_sensor: binary_sensor:
# Button 1 (GPIO16) - polling (GPIO16 has no interrupts)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO16 number: GPIO16
mode: INPUT mode: INPUT
inverted: True inverted: true
use_interrupt: False # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning. use_interrupt: false
name: "Button 1: ${switch_1_name}" name: "Button 1: ${switch_1_name}"
on_press: on_press:
- switch.toggle: Relay_1 - switch.toggle: relay_1
# Button 2 (GPIO05)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO05 number: GPIO05
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 2: ${switch_2_name}" name: "Button 2: ${switch_2_name}"
on_press: on_press:
- switch.toggle: Relay_2 - switch.toggle: relay_2
# Button 3 (GPIO4)
- platform: gpio - platform: gpio
pin: pin:
number: GPIO4 number: GPIO4
mode: INPUT mode: INPUT
inverted: True inverted: true
name: "Button 3: ${switch_3_name}" name: "Button 3: ${switch_3_name}"
on_press: on_press:
- switch.toggle: Relay_3 - switch.toggle: relay_3
############################################# #:########################################################################################:#
# SWITCH COMPONENT # SWITCH
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
############################################# #:########################################################################################:#
switch: switch:
# Relay 1 (GPIO13)
- platform: gpio - platform: gpio
name: "Relay 1: ${switch_1_name}" name: "Relay 1: ${switch_1_name}"
pin: GPIO13 pin: GPIO13
id: Relay_1 id: relay_1
# Relay 2 (GPIO12)
- platform: gpio - platform: gpio
name: "Relay 2: ${switch_2_name}" name: "Relay 2: ${switch_2_name}"
pin: GPIO12 pin: GPIO12
id: Relay_2 id: relay_2
# Relay 3 (GPIO14)
- platform: gpio - platform: gpio
name: "Relay 3: ${switch_3_name}" name: "Relay 3: ${switch_3_name}"
pin: GPIO14 pin: GPIO14
id: Relay_3 id: relay_3
+125 -94
View File
@@ -1,52 +1,90 @@
############################################# #:########################################################################################:#
############################################# # TITLE: OFFICE USB HUB POWER
# OFFICE USB HUB POWER # zorruno.com layout v1.1 2026
# Controlled by a Sonoff Basic R1 #:########################################################################################:#
# # REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-officeusbhubpower.yaml
#:########################################################################################:#
# VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 2025-06-14 Initial Version # V1.0 2025-06-14 Initial Version
#:########################################################################################:#
# HARDWARE:
# Sonoff Basic R1 (ESP8266)
# - Relay: GPIO12
# - Button: GPIO03
# - Status LED: GPIO13 (active-low on many Sonoff variants)
#:########################################################################################:#
# OPERATION NOTES:
# - Simple power control for an office USB hub power supply.
# - Local button toggles the relay.
# - MQTT control is supported for ON/OFF.
#:########################################################################################:#
# MQTT COMMANDS:
# Command (set relay):
# - ${mqtt_command_topic}/relay1/set -> ON, OFF
# #
########################################################################################## # Status (published from template sensor):
########################################################################################## # - ${mqtt_status_topic}/relay1/state -> ON, OFF
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device remains controllable via MQTT command topic
# - Status publishes still occur via MQTT
# - HA entities unavailable until HA returns
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable from Home Assistant via API (relay/button entities)
# - MQTT commands and status publishes will not work while MQTT is down
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available
# - Local button control continues to work
# - Accurate time is NOT needed (SNTP not needed)
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-officeusbhubpower" device_name: "esp-officeusbhubpower"
friendly_name: "Office USB Hub Power" friendly_name: "Office USB Hub Power"
description_comment: "Office USB Hub Power Supply control in the Office (On wall) :: Sonoff Basic" description_comment: "Office USB Hub Power Supply control in the Office (On wall) :: Sonoff Basic (Layout V1.1)"
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Office"
# Project Naming # Project Naming
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details project_name: "Sonoff Technologies.Sonoff Basic V1"
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.1"
# Passwords # Passwords & Secrets (Unfortunately, you cannot use substitutions inside secret names)
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-officeusbhubpower_ip static_ip_address: !secret esp-officeusbhubpower_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# MQTT Topics
mqtt_command_main_topic: !secret mqtt_command_main_topic mqtt_command_main_topic: !secret mqtt_command_main_topic
mqtt_status_main_topic: !secret mqtt_status_main_topic mqtt_status_main_topic: !secret mqtt_status_main_topic
mqtt_device_name: "office-usbhub-power"
mqtt_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}"
mqtt_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}"
# Device Settings # Device Settings
relay_icon: "mdi:generator-portable" relay_icon: "mdi:generator-portable"
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR"
update_interval: "60s" # update time for for general sensors etc update_interval: "60s"
# Device Naming # Entity Naming
relay_1_name: "USB Hub Power Supply" relay_1_name: "USB Hub Power Supply"
button_1_name: "Power Button" button_1_name: "Power Button"
# MQTT Controls #:########################################################################################:#
mqtt_device_name: "office-usbhub-power"
mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA
##########################################################################################
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -55,6 +93,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -68,80 +107,73 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}"
area: "${device_area}" area: "${device_area}"
# platformio_options: project:
# build_flags: name: "${project_name}"
# - "-Os" # optimize for size version: "${project_version}"
# - "-Wl,--gc-sections" # drop unused code/data
# - "-fno-exceptions" # strip C++ exceptions
# - "-fno-rtti" # strip C++ RTTI
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m
restore_from_flash: True # restore some values on reboot restore_from_flash: true
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
mdns: mdns:
disabled: False disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH:
# https://esphome.io/components/switch/ # Sonoff Basic R1 Relay Switch is GPIO12
########################################################################################## # https://esphome.io/components/switch/gpio.html
# Sonoff Basic R1 Relay Switch is GPIO12 #:########################################################################################:#
#############################################
switch: switch:
- platform: gpio - platform: gpio
name: "${relay_1_name}" name: "${relay_1_name}"
pin: GPIO12 pin: GPIO12
id: relay1 id: relay1
restore_mode: RESTORE_DEFAULT_ON restore_mode: RESTORE_DEFAULT_ON
icon: "${relay_icon}" icon: "${relay_icon}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/
##########################################################################################
# Sonoff Basic R1 Button is GPIO03 # Sonoff Basic R1 Button is GPIO03
############################################# # https://esphome.io/components/binary_sensor/gpio.html
#:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
number: GPIO03 number: GPIO03
@@ -157,51 +189,50 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay1).state) { if (id(relay1).state) {
// Relay is ON: turn it OFF
id(relay1).turn_off(); id(relay1).turn_off();
} else { } else {
// Relay is OFF: turn it ON
id(relay1).turn_on(); id(relay1).turn_on();
} }
# Mimics actual relay status (but not controllable) # Mimics actual relay status (not directly controllable)
- platform: template - platform: template
name: "${relay_1_name} Status" name: "${relay_1_name} Status"
lambda: |- lambda: |-
return id(relay1).state; return id(relay1).state;
on_press: on_press:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_topic}/relay1/state" topic: "${mqtt_status_topic}/relay1/state"
payload: "ON" payload: "ON"
retain: false
on_release: on_release:
- mqtt.publish: - mqtt.publish:
topic: "${mqtt_topic}/relay1/state" topic: "${mqtt_status_topic}/relay1/state"
payload: "OFF" payload: "OFF"
retain: false
##########################################################################################
# STATUS LED #:########################################################################################:#
# STATUS LED:
# Sonoff Basic R1 LED is GPIO13
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
########################################################################################## #:########################################################################################:#
# Sonoff Basic R1 LED is GPIO13
#############################################
status_led: status_led:
pin: pin:
number: GPIO13 number: GPIO13
inverted: yes inverted: true
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # Device-specific MQTT command triggers (in addition to common MQTT config)
########################################################################################## # https://esphome.io/components/mqtt.html
#:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Relay 1 control - topic: "${mqtt_command_topic}/relay1/set"
- topic: "${mqtt_main_topic}/relay1/set"
payload: "ON" payload: "ON"
then: then:
- switch.turn_on: relay1 - switch.turn_on: relay1
- topic: "${mqtt_main_topic}/relay1/set"
- topic: "${mqtt_command_topic}/relay1/set"
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay1 - switch.turn_off: relay1
+111 -105
View File
@@ -1,9 +1,13 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: POOL LIGHT POWER AND TIMER 2
# POOL LIGHT POWER AND TIMER 2 # zorruno.com layout v1.1 2026
# Controlled by a Athom Smart Plug V2 #:########################################################################################:#
# # REPO:
# v4.0 2026-01-31 Added Morning/Evening Timer Enable switches (gate timer windows) # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-poollightpower2.yaml
#:########################################################################################:#
# VERSIONS:
# V4.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V4.0 2026-01-31 Added Morning/Evening Timer Enable switches (gate timer windows)
# V3.0 2025-09-02 Pool Light mode controller fixes; Mode select forces Operation=ON; # V3.0 2025-09-02 Pool Light mode controller fixes; Mode select forces Operation=ON;
# added Mode 0=OFF; select shows OFF when relay off; enforce 7s min OFF window # added Mode 0=OFF; select shows OFF when relay off; enforce 7s min OFF window
# V2.4 2025-06-15 Changed back to an Athom V1 (esp8266) # V2.4 2025-06-15 Changed back to an Athom V1 (esp8266)
@@ -11,74 +15,73 @@
# V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable # V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost # V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
# #:########################################################################################:#
# INSTRUCTIONS # HARDWARE:
# - It allows the device to work in a standalone timer style operation # Athom Smart Plug V2 (ESP8285) - used as pool light power controller
# - The timer has a morning and evening time (but no weekday/weekend settings) #:########################################################################################:#
# - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot) # OPERATION NOTES:
# - Pool Light Mode can be set via the "Pool Light Mode" dropdown; selecting a mode forces Operation Mode = ON, and selecting "0=OFF" turns the relay OFF and returns Operation Mode to TIMER # - Standalone timer style operation with morning/evening windows (no weekday/weekend settings)
# - Default values are set, but changed values are remembered in flash # - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored)
# - It uses SNTP for time setting (but obviously only if wifi & networking are working) # - Uses SNTP for accurate time when available; falls back to an internal timer if offline
# - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon) # - To reset internal timer when offline, reboot the device at 12pm (midday)
# - If on a network and there is a MQTT server, you can set the on/off times via MQTT (See below commands) # - Pool Light Mode can be set via the "Pool Light Mode" dropdown:
# - You can set 4 modes ON/OFF/TIMER/BOOST via MQTT. Setting BOOST gives you a oneshot operation # - Selecting a mode forces Operation Mode = ON
# - Any new timer times set via MQTT will be remembered though a reboot # - Selecting "0=OFF" turns relay OFF and returns Operation Mode to TIMER
# - On startup, or a reboot, the device will always turn on for the BOOST Duration (BOOST mode, default 2 hours) # - If on a network and MQTT is available, on/off times and modes can be set via MQTT (see MQTT COMMANDS)
# - TIMER mode will always be switched on after BOOST mode is complete #:########################################################################################:#
# - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown # MQTT COMMANDS:
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot) # Values are applied on update_interval (not immediately). Use HH:MM (24h).
# # - ${mqtt_timer_topic}/morning-on payload "06:00"
# MQTT Commands # - ${mqtt_timer_topic}/morning-off payload "08:00"
# Values will be set in place on the update_interval time, not immediately # - ${mqtt_timer_topic}/evening-on payload "21:00"
# Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting) # - ${mqtt_timer_topic}/evening-off payload "00:00"
# mqtt_timer_topic/morning-on/06:00 : Time device will go on # - ${mqtt_timer_topic}/boost-time payload "0000" (minutes 1-1439)
# mqtt_timer_topic/morning-off/08:00 : Time device will go off # - ${mqtt_timer_topic}/operation payload "ON","OFF","TIMER","BOOST"
# mqtt_timer_topic/evening-on/09:00 : Time device will go on #:########################################################################################:#
# mqtt_timer_topic/evening-off/00:00 : Time device will go off # OFFLINE NOTES:
# mqtt_timer_topic/boost-time/0000 : Time in minutes device will temporarily go on for (1-1439) # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# mqtt_timer_topic/operation/ON : Device permanently on # - Device remains controllable via MQTT (timeclock updates and operation mode)
# mqtt_timer_topic/operation/OFF : Device permanently off # - Device continues running timer/mode logic locally
# mqtt_timer_topic/operation/TIMER : Device will obey timer settings # b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# mqtt_timer_topic/operation/BOOST : Turn on for (boost_duration) minutes then BOOST (also on startup) # - Device remains controllable from Home Assistant via API (selects/buttons/switches)
# # - MQTT timeclock updates and mode commands will not work while MQTT is down
# operation_mode: # c) Entire WiFi/Network OFFLINE
# 0 = OFF # - No HA API and no MQTT control available
# 1 = ON # - Device continues operating using last saved settings
# 2 = TIMER # - Loss of network will drift the timeclocks; time of day can be reset by powering off then on again at 12pm (midday)
# 3 = BOOST #:########################################################################################:#
#
##########################################################################################
##########################################################################################
#:########################################################################################:#
# SUBSTITUTIONS: Specific device variable substitutions
##########################################################################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-poollightpower2" device_name: "esp-poollightpower2"
friendly_name: "Pool Light Power" friendly_name: "Pool Light Power"
description_comment: "Pool Light Power :: Athom Smart Plug Power V2" description_comment: "Pool Light Power :: Athom Smart Plug Power V2 (Layout V1.1)"
device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Athom Technology.Smart Plug V2" # Project Details project_name: "Athom Technology.Smart Plug V2" # Project Details
project_version: "v3.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v4.1" # Project version denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Passwords
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-poollightpower2_ip static_ip_address: !secret esp-poollightpower2_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "DEBUG" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "DEBUG" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for for general sensors etc
# Device Settings # Device Settings
relay_icon: "mdi:power-socket-au" relay_icon: "mdi:power-socket-au"
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
mqtt_timer_topic: "viewroad-commands/poollight-timer" # Topics you will use to change stuff mqtt_timer_topic: "viewroad-commands/poollight-timer" # Topics you will use to change stuff
boost_duration_default: "180" # Minutes to stay ON in BOOST mode before reverting to TIMER boost_duration_default: "180" # Minutes to stay ON in BOOST mode before reverting to TIMER
morning_on_default: "450" # Default in minutes from midnight. Default 07:30 => 450 morning_on_default: "450" # Default in minutes from midnight. Default 07:30 => 450
@@ -98,10 +101,10 @@ substitutions:
# Ignored modes bitmask: bit (mode_index-1). For 4 and 5 ignored -> (1<<3)|(1<<4) = 24. # Ignored modes bitmask: bit (mode_index-1). For 4 and 5 ignored -> (1<<3)|(1<<4) = 24.
ignored_modes_mask: "8288" # Ignore 6(32), 7(64), 14(8192) :: 32 + 64 + 8192 = 8288 ignored_modes_mask: "8288" # Ignore 6(32), 7(64), 14(8192) :: 32 + 64 + 8192 = 8288
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
################################################## ##################################################
# MANDATORY packages (won't compile without them!) # MANDATORY packages (won't compile without them!)
@@ -114,6 +117,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
################################################## ##################################################
# OPTIONAL packages (comment if you don't want them) # OPTIONAL packages (comment if you don't want them)
@@ -164,16 +168,16 @@ packages:
relay_restore_mode: "RESTORE_DEFAULT_OFF" # matches what you already use relay_restore_mode: "RESTORE_DEFAULT_OFF" # matches what you already use
power_plug_type: "${relay_icon}" # e.g. "mdi:power-socket-au" power_plug_type: "${relay_icon}" # e.g. "mdi:power-socket-au"
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" #Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
name_add_mac_suffix: False name_add_mac_suffix: false
min_version: 2024.6.0 min_version: 2024.6.0
project: project:
name: "${project_name}" name: "${project_name}"
@@ -189,10 +193,10 @@ esphome:
# - -fno-exceptions # - -fno-exceptions
# - -fno-rtti # - -fno-rtti
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266.html
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
@@ -203,22 +207,22 @@ preferences:
flash_write_interval: 10min flash_write_interval: 10min
mdns: mdns:
disabled: False # binary size saving disabled: false # binary size saving
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing 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) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false #esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64 #tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## #:########################################################################################:#
switch: switch:
#################################################### ####################################################
# Timer Enable Switches # Timer Enable Switches
@@ -247,12 +251,11 @@ switch:
on_turn_off: on_turn_off:
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
########################################################################################## #:########################################################################################:#
# Global Variables for use in automations etc # GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/components/globals.html
########################################################################################## #:########################################################################################:#
globals: globals:
# Tracks the time (in seconds from midnight) at the previous boot # Tracks the time (in seconds from midnight) at the previous boot
- id: last_boot_time_s - id: last_boot_time_s
type: int type: int
@@ -355,7 +358,7 @@ globals:
restore_value: false restore_value: false
initial_value: "1" initial_value: "1"
# Bitmask of ignored modes (1..max_modes). Example: ignore 4 & 5 -> 24. # Bitmask of ignored modes (1..max_modes). Example: ignore 4 and 5 -> 24.
- id: ignored_mask - id: ignored_mask
type: int type: int
restore_value: false restore_value: false
@@ -367,15 +370,14 @@ globals:
restore_value: false restore_value: false
initial_value: "false" initial_value: "false"
########################################################################################## #:########################################################################################:#
# Text Sensors # TEXT SENSOR COMPONENT:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/index.html
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
############################
############################ # MQTT Subscriptions
# MQTT Subscriptions ############################
############################
#################################################### ####################################################
# Subscribe to the Morning On time, format "HH:MM" # Subscribe to the Morning On time, format "HH:MM"
#################################################### ####################################################
@@ -396,6 +398,7 @@ text_sensor:
} else { } else {
ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str());
} }
#################################################### ####################################################
# Morning Off time => "HH:MM" # Morning Off time => "HH:MM"
#################################################### ####################################################
@@ -415,6 +418,7 @@ text_sensor:
} else { } else {
ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str());
} }
#################################################### ####################################################
# Evening On time => "HH:MM" # Evening On time => "HH:MM"
#################################################### ####################################################
@@ -434,6 +438,7 @@ text_sensor:
} else { } else {
ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str());
} }
#################################################### ####################################################
# Evening Off time => "HH:MM" # Evening Off time => "HH:MM"
#################################################### ####################################################
@@ -453,6 +458,7 @@ text_sensor:
} else { } else {
ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str());
} }
#################################################### ####################################################
# Boost duration => 1 - 1439 # Boost duration => 1 - 1439
#################################################### ####################################################
@@ -577,10 +583,10 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: template - platform: template
id: relay_status id: relay_status
@@ -613,10 +619,10 @@ binary_sensor:
id(last_off_ms) = millis(); id(last_off_ms) = millis();
if (!id(mode_changing)) id(current_mode) = 0; if (!id(mode_changing)) id(current_mode) = 0;
########################################################################################## #:########################################################################################:#
# Sensors # SENSOR COMPONENT:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
name: "Timeclock: Boost Duration" name: "Timeclock: Boost Duration"
@@ -663,10 +669,10 @@ sensor:
// never return negative // never return negative
return rem > 0 ? rem : 0; return rem > 0 ? rem : 0;
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
button: button:
- platform: template - platform: template
name: "Boost now" name: "Boost now"
@@ -701,10 +707,10 @@ button:
- switch.turn_on: evening_timer_enable - switch.turn_on: evening_timer_enable
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
################################################################################################# #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Operation Mode" name: "Operation Mode"
@@ -725,7 +731,7 @@ select:
default: return std::string("OFF"); default: return std::string("OFF");
} }
# when changed in HA, set mode & re-evaluate # when changed in HA, set mode and re-evaluate
set_action: set_action:
- lambda: |- - lambda: |-
if (x == "OFF") { id(operation_mode) = 0; } if (x == "OFF") { id(operation_mode) = 0; }
@@ -859,10 +865,10 @@ select:
else: else:
- script.execute: change_to_desired_mode - script.execute: change_to_desired_mode
################################################################################################# #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
################################################################################################# #:########################################################################################:#
script: script:
# Core: evaluate and drive the relay (with enforced min OFF window) # Core: evaluate and drive the relay (with enforced min OFF window)
- id: evaluate_relay_state - id: evaluate_relay_state
@@ -1013,10 +1019,10 @@ script:
- lambda: |- - lambda: |-
id(mode_changing) = false; id(mode_changing) = false;
################################################################################################# #:########################################################################################:#
# INTERVAL COMPONENT # INTERVAL COMPONENT:
# https://esphome.io/components/interval.html # https://esphome.io/components/interval.html
################################################################################################# #:########################################################################################:#
# Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state # Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state
interval: interval:
- interval: "1min" - interval: "1min"
@@ -1039,4 +1045,4 @@ interval:
//id(mqtt_client).publish("${mqtt_timer_topic}/operation", "TIMER"); //id(mqtt_client).publish("${mqtt_timer_topic}/operation", "TIMER");
} }
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
+171 -235
View File
@@ -1,92 +1,102 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: POOL PUMP POWER AND TIMER
# POOL PUMP POWER AND TIMER # zorruno.com layout v1.1 2026
# Controlled by a Athom Smart Plug V3 #:########################################################################################:#
# # REPO:
# dashboard_import: # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-poolpumppower.yaml
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml #:########################################################################################:#
# # VERSIONS:
# V2.5 2026-02-25 Updated yaml to zorruno layout V1.1
# V2.4 2026-01-31 Added Morning/Evening Timer Enable switches (gate timer windows) # V2.4 2026-01-31 Added Morning/Evening Timer Enable switches (gate timer windows)
# V2.3 2025-06-19 Minor changes to remember mode in reboot and to ensure offline functionality # V2.3 2025-06-19 Minor changes to remember mode in reboot and to ensure offline functionality
# V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable # V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost # V2.1 2025-06-12 Added select and button to chose modes, added countdown and startup to boost
# V2.0 2025-06-05 YAML Tidyups # V2.0 2025-06-05 YAML Tidyups
# #:########################################################################################:#
# INSTRUCTIONS # HARDWARE:
# - It allows the device to work in a standalone timer style operation # - Athom Smart Plug V3 (ESP32-C3) controlling pool pump relay + power monitoring
# - The timer has a morning and evening time (but no weekday/weekend settings) # - dashboard_import: github://athom-tech/esp32-configs/athom-smart-plug.yaml
# - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot) #:########################################################################################:#
# - Default values are set, but changed values are remembered in flash # OPERATION NOTES:
# - It uses SNTP for time setting (but obviously only if wifi & networking are working) # - Standalone timer style operation (morning and evening windows, no weekday/weekend).
# - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon) # - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON).
# - If on a network and there is a MQTT server, you can set the on/off times via MQTT (See below commands) # - Default values are set, but changed values are remembered in flash.
# - You can set 4 modes ON/OFF/TIMER/BOOST via MQTT. Setting BOOST gives you a oneshot operation # - Uses SNTP for accurate time when WiFi/networking is available.
# - Any new timer times set via MQTT will be remembered though a reboot # - If on a network and MQTT is available, you can set on/off times and operation mode via MQTT.
# - On startup, or a reboot, the device will always turn on for the BOOST Duration (BOOST mode, default 2 hours) # - Operation modes: OFF / ON / TIMER / BOOST. BOOST is a oneshot that reverts back to TIMER.
# - TIMER mode will always be switched on after BOOST mode is complete # - On startup or reboot, the device enters BOOST for the configured BOOST duration, then returns to TIMER.
# - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown #:########################################################################################:#
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot) # MQTT COMMANDS:
# # Values are applied on the update_interval, not instantly.
# MQTT Commands # Use 00:00 in 24hr format for time settings.
# Values will be set in place on the update_interval time, not immediately # ${mqtt_timer_topic}/morning-on payload "HH:MM"
# Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting) # ${mqtt_timer_topic}/morning-off payload "HH:MM"
# mqtt_timer_topic/morning-on/06:00 : Time device will go on # ${mqtt_timer_topic}/evening-on payload "HH:MM"
# mqtt_timer_topic/morning-off/08:00 : Time device will go off # ${mqtt_timer_topic}/evening-off payload "HH:MM"
# mqtt_timer_topic/evening-on/09:00 : Time device will go on # ${mqtt_timer_topic}/boost-time payload "0".."1439" (minutes)
# mqtt_timer_topic/evening-off/00:00 : Time device will go off # ${mqtt_timer_topic}/operation payload "ON","OFF","TIMER","BOOST"
# mqtt_timer_topic/boost-time/0000 : Time in minutes device will temporarily go on for (1-1439)
# mqtt_timer_topic/operation/ON : Device permanently on
# mqtt_timer_topic/operation/OFF : Device permanently off
# mqtt_timer_topic/operation/TIMER : Device will obey timer settings
# mqtt_timer_topic/operation/BOOST : Turn on for (boost_duration) minutes then BOOST (also on startup)
# #
# operation_mode: # operation_mode:
# 0 = OFF # 0 = OFF
# 1 = ON # 1 = ON
# 2 = TIMER # 2 = TIMER
# 3 = BOOST # 3 = BOOST
# #:########################################################################################:#
########################################################################################## # OFFLINE NOTES:
########################################################################################## # a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Timer logic continues to run on the device.
# - MQTT commands for schedule/mode updates still work.
# b) MQTT OFFLINE (or HA/MQTT OFFLINE)
# - If HA API is available, device can still be controlled from HA.
# - Without MQTT, schedule/mode changes via MQTT will not work.
# c) Entire WiFi/Network OFFLINE
# - No HA API and no MQTT control available.
# - Timer mode continues using the fallback clock.
# - Loss of network will drift the timeclocks; time of day can be reset by powering off then on again at 12pm (midday).
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-poolpumppower" device_name: "esp-poolpumppower"
friendly_name: "Pool Pump Power" friendly_name: "Pool Pump Power"
description_comment: "Pool Pump Power :: Athom Smart Plug Power V3" description_comment: "Pool Pump Power :: Athom Smart Plug Power V3 (Layout V1.1)"
device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Athom Technology.Smart Plug V3" # Project Details project_name: "Athom Technology.Smart Plug V3"
project_version: "v2.4" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v2.5" # Updated yaml to zorruno layout V1.1
# Passwords # Passwords
api_key: !secret esp-poolpumppower_api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-poolpumppower_api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-poolpumppower_ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-poolpumppower_ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-poolpumppower_ip static_ip_address: !secret esp-poolpumppower_ip
# Device Settings # If we are changing IP addresses, you must update the current IP address here, otherwise it remains
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE # Don't forget to switch it back when changed.
update_interval: "20s" # update time for for general sensors etc current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "INFO" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "20s" # update time for general sensors etc
# Timer Settings
relay_icon: "mdi:pool" relay_icon: "mdi:pool"
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. current_limit: "10" # Current limit in amps. AU plug = 10. IL, BR, EU, UK, US plug = 16.
mqtt_timer_topic: "viewroad-commands/poolpump-timer" # Topics you will use to change stuff mqtt_timer_topic: "viewroad-commands/poolpump-timer"
boost_duration_default: "60" # Minutes to stay ON in STARTUP mode before reverting to TIMER boost_duration_default: "60" # minutes to stay ON in BOOST mode before reverting to TIMER
morning_on_default: "450" # Default in minutes from midnight. Default 07:30 => 450 morning_on_default: "450" # 07:30 => 450
morning_off_default: "450" # Default in minutes from midnight. Default 07:30 => 450 (same as ON as no need for morning schedule) morning_off_default: "450" # 07:30 => 450 (same as ON, no morning schedule)
evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260 evening_on_default: "1260" # 21:00 => 1260
evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight evening_off_default: "1350" # 22:30 => 1350
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -95,6 +105,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -111,6 +122,7 @@ packages:
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
@@ -120,20 +132,20 @@ packages:
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
diag_resetcount: !include common/include_resetcount_diag_sensors.yaml diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
# Device Specific included packages #### Device Specific included packages ####
common_athompowermonV3: !include common_athompowermonV3: !include
file: common/athompowermonv3_common.yaml file: common/athompowermonv3_common.yaml
vars: vars:
local_current_limit: "${current_limit}" local_current_limit: "${current_limit}"
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
name_add_mac_suffix: false name_add_mac_suffix: false
min_version: 2024.6.0 min_version: 2024.6.0
@@ -148,17 +160,17 @@ esphome:
then: then:
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp32/
########################################################################################## #:########################################################################################:#
esp32: esp32:
board: esp32-c3-devkitm-1 board: esp32-c3-devkitm-1
flash_size: 4MB flash_size: 4MB
variant: ESP32C3 variant: ESP32C3
framework: framework:
type: esp-idf # "esp-idf" OR "arduino". Suggested ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang. type: esp-idf
version: recommended # recommended, latest or dev version: recommended
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
@@ -166,22 +178,19 @@ preferences:
esp32_improv: esp32_improv:
authorizer: none authorizer: none
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# Global Variables for use in automations etc # GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/guides/automations.html#global-variables
########################################################################################## #:########################################################################################:#
globals: globals:
# Tracks the time (in seconds from midnight) at the previous boot # Tracks the time (in seconds from midnight) at the previous boot
- id: last_boot_time_s - id: last_boot_time_s
type: int type: int
@@ -194,31 +203,31 @@ globals:
restore_value: true restore_value: true
initial_value: "0" initial_value: "0"
# Morning On time (minutes from midnight), # Morning On time (minutes from midnight)
- id: morning_on - id: morning_on
type: int type: int
restore_value: true restore_value: true
initial_value: "${morning_on_default}" initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight), # Morning Off time (minutes from midnight)
- id: morning_off - id: morning_off
type: int type: int
restore_value: true restore_value: true
initial_value: "${morning_off_default}" initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight), # Evening On time (minutes from midnight)
- id: evening_on - id: evening_on
type: int type: int
restore_value: true restore_value: true
initial_value: "${evening_on_default}" initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight), # Evening Off time (minutes from midnight)
- id: evening_off - id: evening_off
type: int type: int
restore_value: true restore_value: true
initial_value: "${evening_off_default}" initial_value: "${evening_off_default}"
# Boost Duration (minutes), # Boost Duration (minutes)
- id: boost_duration - id: boost_duration
type: int type: int
restore_value: true restore_value: true
@@ -226,10 +235,10 @@ globals:
#################################################### ####################################################
# operation_mode: # operation_mode:
# 0 = OFF # 0 = OFF
# 1 = ON # 1 = ON
# 2 = TIMER # 2 = TIMER
# 3 = BOOST # 3 = BOOST
#################################################### ####################################################
- id: operation_mode - id: operation_mode
type: int type: int
@@ -245,52 +254,41 @@ globals:
restore_value: true restore_value: true
initial_value: "0" initial_value: "0"
########################################################################################## #:########################################################################################:#
# Text Sensors # TEXT SENSOR:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/text_sensor/index.html
########################################################################################## #:########################################################################################:#
text_sensor: text_sensor:
############################
############################ # MQTT Subscriptions
# MQTT Subscriptions ############################
############################
####################################################
# Subscribe to the Morning On time, format "HH:MM"
# We check x.size() == 5 and x[2] == ':',
# then parse x.substr(0,2) and x.substr(3,2)
# std::string uses 'substr', not 'substring'.
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Morning On Time Setting" name: "Morning On Time Setting"
id: morning_on_topic id: morning_on_topic
topic: "${mqtt_timer_topic}/morning-on" # Stored in the format HH:MM topic: "${mqtt_timer_topic}/morning-on"
internal: true internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
// Expect "HH:MM" => total length = 5, with ':'
if (x.size() == 5 && x[2] == ':') { if (x.size() == 5 && x[2] == ':') {
int hour = atoi(x.substr(0, 2).c_str()); // "HH" int hour = atoi(x.substr(0, 2).c_str());
int minute = atoi(x.substr(3, 2).c_str()); // "MM" int minute = atoi(x.substr(3, 2).c_str());
id(morning_on) = hour * 60 + minute; id(morning_on) = hour * 60 + minute;
ESP_LOGI("timer","Received new Morning On: %02d:%02d", hour, minute); ESP_LOGI("timer","Received new Morning On: %02d:%02d", hour, minute);
} else { } else {
ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str());
} }
####################################################
# Morning Off time => "HH:MM"
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Morning Off Time Setting" name: "Morning Off Time Setting"
id: morning_off_topic id: morning_off_topic
topic: "${mqtt_timer_topic}/morning-off" # Stored in the format HH:MM topic: "${mqtt_timer_topic}/morning-off"
internal: true # No need to show this in Home Assistant as there is a sensor that shows the set value internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
if (x.size() == 5 && x[2] == ':') { if (x.size() == 5 && x[2] == ':') {
int hour = atoi(x.substr(0, 2).c_str()); int hour = atoi(x.substr(0, 2).c_str());
int minute = atoi(x.substr(3, 2).c_str()); int minute = atoi(x.substr(3, 2).c_str());
id(morning_off) = hour * 60 + minute; id(morning_off) = hour * 60 + minute;
ESP_LOGI("timer","Received new Morning Off: %02d:%02d", hour, minute); ESP_LOGI("timer","Received new Morning Off: %02d:%02d", hour, minute);
@@ -298,19 +296,16 @@ text_sensor:
ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str());
} }
####################################################
# Evening On time => "HH:MM"
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Evening On Time Setting" name: "Evening On Time Setting"
id: evening_on_topic id: evening_on_topic
topic: "${mqtt_timer_topic}/evening-on" # Stored in the format HH:MM topic: "${mqtt_timer_topic}/evening-on"
internal: true # No need to show this in Home Assistant as there is a sensor that shows the set value internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
if (x.size() == 5 && x[2] == ':') { if (x.size() == 5 && x[2] == ':') {
int hour = atoi(x.substr(0, 2).c_str()); int hour = atoi(x.substr(0, 2).c_str());
int minute = atoi(x.substr(3, 2).c_str()); int minute = atoi(x.substr(3, 2).c_str());
id(evening_on) = hour * 60 + minute; id(evening_on) = hour * 60 + minute;
ESP_LOGI("timer","Received new Evening On: %02d:%02d", hour, minute); ESP_LOGI("timer","Received new Evening On: %02d:%02d", hour, minute);
@@ -318,19 +313,16 @@ text_sensor:
ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str());
} }
####################################################
# Evening Off time => "HH:MM"
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Evening Off Time Setting" name: "Evening Off Time Setting"
id: evening_off_topic id: evening_off_topic
topic: "${mqtt_timer_topic}/evening-off" # Stored in the format HH:MM topic: "${mqtt_timer_topic}/evening-off"
internal: true # No need to show this in Home Assistant as there is a sensor that shows the set value internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
if (x.size() == 5 && x[2] == ':') { if (x.size() == 5 && x[2] == ':') {
int hour = atoi(x.substr(0, 2).c_str()); int hour = atoi(x.substr(0, 2).c_str());
int minute = atoi(x.substr(3, 2).c_str()); int minute = atoi(x.substr(3, 2).c_str());
id(evening_off) = hour * 60 + minute; id(evening_off) = hour * 60 + minute;
ESP_LOGI("timer","Received new Evening Off: %02d:%02d", hour, minute); ESP_LOGI("timer","Received new Evening Off: %02d:%02d", hour, minute);
@@ -338,37 +330,26 @@ text_sensor:
ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str()); ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str());
} }
####################################################
# Boost duration => 1 - 1439
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
name: "Boost Duration" name: "Boost Duration"
id: boost_time_topic id: boost_time_topic
topic: "${mqtt_timer_topic}/boost-time" # Stored as an integer from 1-1439 topic: "${mqtt_timer_topic}/boost-time"
internal: true # No need to show this in Home Assistant as there is a sensor that shows the set value internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
// parse as integer
char *endptr; char *endptr;
long v = strtol(x.c_str(), &endptr, 10); long v = strtol(x.c_str(), &endptr, 10);
// invalid if nothing parsed, trailing chars, or out of 0-1439
if (endptr == x.c_str() || *endptr != '\0' || v < 0 || v > 1439) { if (endptr == x.c_str() || *endptr != '\0' || v < 0 || v > 1439) {
ESP_LOGE("boost_time", "Invalid boost_time '%s'", x.c_str()); ESP_LOGE("boost_time", "Invalid boost_time '%s'", x.c_str());
} else { } else {
id(boost_duration) = static_cast<int>(v); id(boost_duration) = (int) v;
} }
####################################################
# Subscribe to operation mode:
# OFF, ON, TIMER, BOOST
# We do case-insensitive compare using strcasecmp
####################################################
- platform: mqtt_subscribe - platform: mqtt_subscribe
id: timer_operation_mode_topic id: timer_operation_mode_topic
topic: "${mqtt_timer_topic}/operation" topic: "${mqtt_timer_topic}/operation"
internal: true # No need to show this in Home Assistant as there is a sensor that shows the set value internal: true
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
@@ -390,13 +371,9 @@ text_sensor:
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
######################################################
# Expose the current operation mode (OFF, ON, TIMER, BOOST)
######################################################
- platform: template - platform: template
name: "Operation Mode State" name: "Operation Mode State"
lambda: |- lambda: |-
// 0=OFF, 1=ON, 2=TIMER, 3=BOOST
switch (id(operation_mode)) { switch (id(operation_mode)) {
case 0: return {"OFF"}; case 0: return {"OFF"};
case 1: return {"ON"}; case 1: return {"ON"};
@@ -406,9 +383,6 @@ text_sensor:
} }
update_interval: 5s update_interval: 5s
######################################################
# Expose the "Morning On" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Morning On Time" name: "Timeclock: Morning On Time"
lambda: |- lambda: |-
@@ -419,9 +393,6 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Morning Off" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Morning Off Time" name: "Timeclock: Morning Off Time"
lambda: |- lambda: |-
@@ -432,9 +403,6 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Evening On" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Evening On Time" name: "Timeclock: Evening On Time"
lambda: |- lambda: |-
@@ -445,9 +413,6 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
######################################################
# Expose the "Evening Off" time as a text (HH:MM)
######################################################
- platform: template - platform: template
name: "Timeclock: Evening Off Time" name: "Timeclock: Evening Off Time"
lambda: |- lambda: |-
@@ -458,10 +423,10 @@ text_sensor:
return { std::string(buff) }; return { std::string(buff) };
update_interval: "${update_interval}" update_interval: "${update_interval}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## #:########################################################################################:#
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
pin: pin:
@@ -478,11 +443,9 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay).state) { if (id(relay).state) {
// Relay is ON: turn it OFF and set mode to 2 (TIMER)
id(relay).turn_off(); id(relay).turn_off();
id(operation_mode) = 2; id(operation_mode) = 2;
} else { } else {
// Relay is OFF: turn it ON and set mode to 3 (BOOST)
id(relay).turn_on(); id(relay).turn_on();
id(operation_mode) = 3; id(operation_mode) = 3;
} }
@@ -492,16 +455,16 @@ binary_sensor:
lambda: |- lambda: |-
return id(relay).state; return id(relay).state;
########################################################################################## #:########################################################################################:#
# Sensors # SENSORS:
# https://esphome.io/components/text_sensor/index.html # https://esphome.io/components/sensor/
########################################################################################## #:########################################################################################:#
sensor: sensor:
- platform: template - platform: template
name: "Timeclock: Boost Duration" name: "Timeclock: Boost Duration"
id: boost_duration_time id: boost_duration_time
unit_of_measurement: "mins" unit_of_measurement: "mins"
accuracy_decimals: "0" accuracy_decimals: 0
update_interval: "${update_interval}" update_interval: "${update_interval}"
lambda: |- lambda: |-
return id(boost_duration); return id(boost_duration);
@@ -510,30 +473,24 @@ sensor:
name: "Mins from Midnight" name: "Mins from Midnight"
id: mins_from_midnight id: mins_from_midnight
unit_of_measurement: "mins" unit_of_measurement: "mins"
accuracy_decimals: "0" accuracy_decimals: 0
update_interval: "${update_interval}" update_interval: "${update_interval}"
internal: true # No need to show this in Home Assistant internal: true
lambda: |- lambda: |-
return id(current_mins); return id(current_mins);
# A value in mins if a timer is running showing how many mins left
- platform: template - platform: template
name: "Timer Minutes Remaining" name: "Timer Minutes Remaining"
id: timer_minutes_remaining id: timer_minutes_remaining
unit_of_measurement: "Mins" unit_of_measurement: "mins"
update_interval: 5s update_interval: 5s
accuracy_decimals: "0" accuracy_decimals: 0
lambda: |- lambda: |-
// always zero if relay is off if (!id(relay).state) return 0;
if (!id(relay).state) {
return 0;
}
int rem = 0; int rem = 0;
// only calculate for mode 2 (scheduled) or mode 3 (BOOST)
if (id(operation_mode) == 2) { if (id(operation_mode) == 2) {
// Only report remaining time for the currently-active enabled window
if (id(morning_timer_enable).state && if (id(morning_timer_enable).state &&
id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) { id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) {
rem = id(morning_off) - id(current_mins); rem = id(morning_off) - id(current_mins);
@@ -547,26 +504,21 @@ sensor:
rem = id(boost_duration) - id(boost_timer); rem = id(boost_duration) - id(boost_timer);
} }
// never return negative
return rem > 0 ? rem : 0; return rem > 0 ? rem : 0;
################################################################################################# #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
################################################################################################# #:########################################################################################:#
switch: switch:
- platform: gpio - platform: gpio
name: "Power Output" name: "Power Output"
pin: GPIO5 pin: GPIO5
id: relay id: relay
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot restore_mode: RESTORE_DEFAULT_OFF
#internal: true # Hides the switch from Home Assistant
icon: "${relay_icon}" icon: "${relay_icon}"
################################################################################################# # Timer Enable Switches (gate schedule windows)
# TIMER ENABLE SWITCHES (gate the schedule windows)
# These default ON, and restore as ON at reboot (unless changed).
#################################################################################################
- platform: template - platform: template
name: "Morning Timer Enable" name: "Morning Timer Enable"
id: morning_timer_enable id: morning_timer_enable
@@ -591,21 +543,19 @@ switch:
on_turn_off: on_turn_off:
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# BUTTON COMPONENT # BUTTON COMPONENT:
# https://esphome.io/components/button/index.html # https://esphome.io/components/button/index.html
################################################################################################# #:########################################################################################:#
button: button:
- platform: template - platform: template
name: "Boost now" name: "Boost now"
id: boost_button id: boost_button
icon: "mdi:play-circle-outline" icon: "mdi:play-circle-outline"
on_press: on_press:
# 1) reset BOOST timer and set mode
- lambda: |- - lambda: |-
id(boost_timer) = 0; id(boost_timer) = 0;
id(operation_mode) = 3; id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
- platform: template - platform: template
@@ -614,23 +564,23 @@ button:
icon: "mdi:restore" icon: "mdi:restore"
on_press: on_press:
- lambda: |- - lambda: |-
// Restore all timing globals to their YAML defaults
id(morning_on) = ${morning_on_default}; id(morning_on) = ${morning_on_default};
id(morning_off) = ${morning_off_default}; id(morning_off) = ${morning_off_default};
id(evening_on) = ${evening_on_default}; id(evening_on) = ${evening_on_default};
id(evening_off) = ${evening_off_default}; id(evening_off) = ${evening_off_default};
id(boost_duration) = ${boost_duration_default}; id(boost_duration) = ${boost_duration_default};
// Reset mode to TIMER and clear any running boost
id(operation_mode) = 2; id(operation_mode) = 2;
id(boost_timer) = 0; id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied"); ESP_LOGI("timer","Default timer settings applied");
- switch.turn_on: morning_timer_enable
- switch.turn_on: evening_timer_enable
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
################################################################################################# #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Operation Mode" name: "Operation Mode"
@@ -641,8 +591,6 @@ select:
- "ON" - "ON"
- "TIMER" - "TIMER"
- "BOOST" - "BOOST"
# show the current mode
lambda: |- lambda: |-
switch (id(operation_mode)) { switch (id(operation_mode)) {
case 1: return std::string("ON"); case 1: return std::string("ON");
@@ -650,80 +598,69 @@ select:
case 3: return std::string("BOOST"); case 3: return std::string("BOOST");
default: return std::string("OFF"); default: return std::string("OFF");
} }
# when changed in HA, set mode & re-evaluate
set_action: set_action:
- lambda: |- - lambda: |-
if (x == "OFF") { id(operation_mode) = 0; } if (x == "OFF") { id(operation_mode) = 0; }
else if (x == "ON") { id(operation_mode) = 1; } else if (x == "ON") { id(operation_mode) = 1; }
else if (x == "TIMER") { id(operation_mode) = 2; } else if (x == "TIMER") { id(operation_mode) = 2; }
else { // BOOST else {
id(boost_timer) = 0; id(boost_timer) = 0;
id(operation_mode) = 3; id(operation_mode) = 3;
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
################################################################################################# #:########################################################################################:#
# SCRIPT COMPONENT # SCRIPT COMPONENT:
# https://esphome.io/components/script.html # https://esphome.io/components/script.html
################################################################################################# #:########################################################################################:#
# Script: evaluate and drive the relay
script: script:
- id: evaluate_relay_state - id: evaluate_relay_state
then: then:
- lambda: |- - lambda: |-
int mode = id(operation_mode); int mode = id(operation_mode);
// BOOST just forces the relay on
if (mode == 3) { if (mode == 3) {
id(relay).turn_on(); id(relay).turn_on();
return; return;
} }
// OFF -> always off
if (mode == 0) { if (mode == 0) {
id(relay).turn_off(); id(relay).turn_off();
return; return;
} }
// ON -> always on
if (mode == 1) { if (mode == 1) {
id(relay).turn_on(); id(relay).turn_on();
return; return;
} }
// TIMER -> follow schedule windows (gated by enable switches) // TIMER -> follow schedule windows (gated by enable switches)
{ bool should_on = false;
bool should_on = false;
// Morning window only applies if Morning Timer Enable is ON if (id(morning_timer_enable).state) {
if (id(morning_timer_enable).state) { if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) {
if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) { should_on = true;
should_on = true;
}
} }
// Evening window only applies if Evening Timer Enable is ON
if (id(evening_timer_enable).state) {
if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off)) {
should_on = true;
}
}
if (should_on) id(relay).turn_on();
else id(relay).turn_off();
} }
################################################################################################# if (id(evening_timer_enable).state) {
# INTERVAL COMPONENT if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off)) {
should_on = true;
}
}
if (should_on) id(relay).turn_on();
else id(relay).turn_off();
#:########################################################################################:#
# INTERVAL COMPONENT:
# https://esphome.io/components/interval.html # https://esphome.io/components/interval.html
################################################################################################# #:########################################################################################:#
# Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state
interval: interval:
- interval: "1min" - interval: "1min"
then: then:
- lambda: |- - lambda: |-
// - update current_mins via SNTP or fallback // update current_mins via SNTP or fallback
if (!id(sntp_time).now().is_valid()) { if (!id(sntp_time).now().is_valid()) {
id(current_mins)++; id(current_mins)++;
if (id(current_mins) >= 1440) id(current_mins) = 0; if (id(current_mins) >= 1440) id(current_mins) = 0;
@@ -732,12 +669,11 @@ interval:
id(current_mins) = now.hour * 60 + now.minute; id(current_mins) = now.hour * 60 + now.minute;
} }
// - if in BOOST, advance boost_timer and expire when done // BOOST timer handling
if (id(operation_mode) == 3) { if (id(operation_mode) == 3) {
id(boost_timer)++; id(boost_timer)++;
if (id(boost_timer) >= id(boost_duration)) { if (id(boost_timer) >= id(boost_duration)) {
id(operation_mode) = 2; id(operation_mode) = 2;
//id(mqtt_client).publish("${mqtt_timer_topic}/operation", "TIMER");
} }
} }
- script.execute: evaluate_relay_state - script.execute: evaluate_relay_state
+112 -86
View File
@@ -1,55 +1,82 @@
########################################################################################## #:########################################################################################:#
########################################################################################## # TITLE: ROCK TUMBLER POWER MONITOR
# ROCK TUMBLER POWER MONITOR # zorruno.com layout v1.1 2026
# #:########################################################################################:#
# Controlled by a Athom Smart Plug V1 # REPO:
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-rocktumbler.yaml
# #:########################################################################################:#
# VERSIONS:
# V1.4 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.3 2025-08-27 Changed to Athom V2 # V1.3 2025-08-27 Changed to Athom V2
# V1.2 2025-06-15 Changed to Athom V1 # V1.2 2025-06-15 Changed to Athom V1
# V1.1 2025-06-12 Tidyups and packages added # V1.1 2025-06-12 Tidyups and packages added
# #:########################################################################################:#
########################################################################################## # HARDWARE:
########################################################################################## # - Athom Smart Plug V2 (ESP8285) with power monitoring + relay
# - Reference config: github://athom-tech/athom-configs/athom-smart-plug.yaml
#:########################################################################################:#
# OPERATION NOTES:
# - This device provides power monitoring (via common Athom V2 package) and a controllable relay.
# - "Power On State" select controls what the relay does after reboot:
# - Always Off
# - Always On
# - Restore Previous State
# - Power monitoring sensor update interval is set via substitutions.
#:########################################################################################:#
# MQTT COMMANDS:
# - None device-specific in this YAML (uses common_mqtt package for standard device MQTT support).
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device continues operating and can be controlled via MQTT (if your common_mqtt exposes it).
# - Power monitoring continues locally and publishes via MQTT if configured.
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable via Home Assistant API.
# - MQTT publishing/commands will fail while MQTT is down.
# c) Entire WiFi/Network OFFLINE
# - Device continues operating locally (relay + power monitoring).
# - SNTP is not needed (no timeclocks used in this YAML).
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-rocktumbler" device_name: "esp-rocktumbler"
friendly_name: "Rock Tumbler Power" friendly_name: "Rock Tumbler Power"
description_comment: "Rock Tumbler Power :: Athom Smart Plug Power V2" description_comment: "Rock Tumbler Power :: Athom Smart Plug Power V2 (Layout V1.1)"
device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Athom Technology.Smart Plug V2" # Project Details
project_version: "v1.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords (unfortunately you can't use substitutions inside secrets names) # Project Naming
project_name: "Athom Technology.Smart Plug V2"
project_version: "v1.4" # Updated yaml to zorruno layout V1.1
# Passwords (unfortunately you cannot use substitutions inside secrets names)
api_key: !secret esp-api_key api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-rocktumbler_ip static_ip_address: !secret esp-rocktumbler_ip
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device General Settings # Device General Settings
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for for general sensors etc
# Device Specific Settings # Device Specific Settings (Athom Power Monitor Plug V2)
# Athom Power Monitor Plug V2 relay_icon: "mdi:power-socket-au"
relay_icon: "mdi:power-socket-au"
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16. current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
sensor_update_interval: "10s" sensor_update_interval: "10s"
relay_restore_mode: RESTORE_DEFAULT_ON relay_restore_mode: RESTORE_DEFAULT_ON
hide_energy_sensor: "true" hide_energy_sensor: "true"
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -58,6 +85,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -71,21 +99,20 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml #diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
# Device Specific included packages #### Device Specific included packages: Athom Power Monitor Plug V2 ####
# Athom Power Monitor Plug
common_athompowermonV2: !include common_athompowermonV2: !include
file: common/athompowermonv2_common.yaml file: common/athompowermonv2_common.yaml
vars: vars:
@@ -96,47 +123,46 @@ packages:
power_plug_type: "${relay_icon}" power_plug_type: "${relay_icon}"
hide_energy_sensor: "${hide_energy_sensor}" hide_energy_sensor: "${hide_energy_sensor}"
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" #Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
name_add_mac_suffix: false name_add_mac_suffix: false
min_version: 2024.6.0 min_version: 2024.6.0
project: project:
name: "${project_name}" name: "${project_name}"
version: "${project_version}" version: "${project_version}"
on_boot: on_boot:
- priority: 600 priority: 600
then: then:
- select.set_index: - select.set_index:
id: power_mode id: power_mode
index: !lambda |- index: !lambda |-
return id(restore_mode)-1; return id(restore_mode) - 1;
- lambda: |- - lambda: |-
switch(id(restore_mode)) switch (id(restore_mode)) {
{ case 1: {
case 1:{ id(relay).turn_off();
id(relay).turn_off(); break;
break; }
} case 2: {
case 2:{ id(relay).turn_on();
id(relay).turn_on(); break;
break; }
} default: {
default:{ break;
break; }
} }
}
########################################################################################## #:########################################################################################:#
# ESP Platform and Framework # ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html # https://esphome.io/components/esp8266/
########################################################################################## #:########################################################################################:#
esp8266: esp8266:
board: esp8285 board: esp8285
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
@@ -148,40 +174,40 @@ preferences:
mdns: mdns:
disabled: false disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome LOGGING # LOGGING: ESPHome Logging Enable
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" level: "${log_level}"
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
########################################################################################## #:########################################################################################:#
# GLOBAL VARIABLES # GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables # https://esphome.io/guides/automations.html#global-variables
########################################################################################## #:########################################################################################:#
globals: globals:
# 0 = Always_Off. 1 = Restore_Power_Off. 2 = Always_On. # 0 = Always_Off, 1 = Restore_Power_Off, 2 = Always_On
- id: restore_mode - id: restore_mode
type: int type: int
restore_value: yes restore_value: yes
initial_value: "2" initial_value: "2"
########################################################################################## #:########################################################################################:#
# SELECT COMPONENT # SELECT COMPONENT:
# https://esphome.io/components/select/index.html # https://esphome.io/components/select/index.html
########################################################################################## #:########################################################################################:#
select: select:
- platform: template - platform: template
name: "Power On State" name: "Power On State"
id: "power_mode" id: power_mode
optimistic: true optimistic: true
icon: mdi:electric-switch icon: mdi:electric-switch
options: options:
- Always Off - "Always Off"
- Always On - "Always On"
- Restore Previous State - "Restore Previous State"
on_value: on_value:
then: then:
- lambda: |- - lambda: |-
id(restore_mode)=i+1; id(restore_mode) = i + 1;
+137 -98
View File
@@ -1,29 +1,66 @@
############################################# #:########################################################################################:#
############################################# # TITLE: UNDERHOUSE LIGHTS
# UNDERHOUSE LIGHTS # zorruno.com layout v1.1 2026
# Controlled by a Sonoff 4Ch R2 #:########################################################################################:#
# https://github.com/jvyoralek/homeassistant-config/blob/master/esphome/sonoff-4ch.yaml # REPO:
# # https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-underhouselights.yaml
#:########################################################################################:#
# VERSIONS:
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
# V1.0 2025-06-18 Initial Version # V1.0 2025-06-18 Initial Version
#:########################################################################################:#
# HARDWARE:
# Controlled by a Sonoff 4Ch R2
# Reference YAML: https://github.com/jvyoralek/homeassistant-config/blob/master/esphome/sonoff-4ch.yaml
# #
########################################################################################## # GPIO (Sonoff 4Ch R2):
########################################################################################## # - Relays: GPIO12, GPIO05, GPIO04, GPIO15
# - Buttons: GPIO00, GPIO09, GPIO10, GPIO14
# - Status LED: GPIO13
# - Extra "Remote Switch" inputs used here: GPIO03, GPIO02
#:########################################################################################:#
# OPERATION NOTES:
# - 4-channel relay controller for underhouse lighting circuits.
# - Local buttons toggle each relay (button1..button4).
# - Two extra GPIO inputs act as "remote switches" that toggle relay1 and relay2.
# - MQTT local command topics allow ON/OFF control per relay (see MQTT COMMANDS).
#:########################################################################################:#
# MQTT COMMANDS:
# Relay control (local MQTT):
# - ${mqtt_local_command_topic}/relay1/set -> ON, OFF
# - ${mqtt_local_command_topic}/relay2/set -> ON, OFF
# - ${mqtt_local_command_topic}/relay3/set -> ON, OFF
# - ${mqtt_local_command_topic}/relay4/set -> ON, OFF
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - Device remains controllable via MQTT local command topics.
# - Local buttons and remote switch inputs continue to toggle relays.
# b) MQTT OFFLINE (but WiFi/Network and HA API ONLINE)
# - Device remains controllable via Home Assistant API.
# - MQTT local commands will not work while MQTT is down.
# - Local buttons and remote switch inputs continue to toggle relays.
# c) Entire WiFi/Network OFFLINE
# - Local buttons and remote switch inputs continue to toggle relays.
# - No HA API or MQTT control available.
# - SNTP is not needed (no timeclocks used).
#:########################################################################################:#
########################################################################################## #:########################################################################################:#
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS # SUBSTITUTIONS: Specific device variable substitutions
# If NOT using a secrets file, just replace these with the passwords etc (in quotes) # If NOT using a secrets file, just replace these with the passwords etc (in quotes)
########################################################################################## #:########################################################################################:#
substitutions: substitutions:
# Device Naming # Device Naming
device_name: "esp-underhouselights" device_name: "esp-underhouselights"
friendly_name: "Underhouse Lights" friendly_name: "Underhouse Lights"
description_comment: "Underhouse Lights Control :: Sonoff 4Ch R2" description_comment: "Underhouse Lights Control :: Sonoff 4Ch R2 (Layout V1.1)"
device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant. device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming # Project Naming
project_name: "Sonoff Technologies.Sonoff 4Ch R2" # Project Details project_name: "Sonoff Technologies.Sonoff 4Ch R2" # Project Details
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords # Passwords
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
@@ -31,9 +68,13 @@ substitutions:
mqtt_local_command_main_topic: !secret mqtt_command_main_topic mqtt_local_command_main_topic: !secret mqtt_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_status_main_topic mqtt_local_status_main_topic: !secret mqtt_status_main_topic
# If we are changing IP addresses, you must update the current IP address here, otherwise it remains
# Don't forget to switch it back when changed.
current_ip_address: ${static_ip_address}
# Device Settings # Device Settings
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE log_level: "ERROR" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc update_interval: "60s" # update time for general sensors etc
# MQTT Controls # MQTT Controls
mqtt_device_name: "underhouse-lights-control" mqtt_device_name: "underhouse-lights-control"
@@ -43,21 +84,24 @@ substitutions:
# Switch Naming # Switch Naming
switch_1_name: "Underhouse Entrance Lights" switch_1_name: "Underhouse Entrance Lights"
button_1_name: "Button 1" button_1_name: "Button 1"
relay_1_icon: "mdi:lightbulb" relay_1_icon: "mdi:lightbulb"
switch_2_name: "Underhouse Storage Lights" switch_2_name: "Underhouse Storage Lights"
button_2_name: "Button 2" button_2_name: "Button 2"
relay_2_icon: "mdi:lightbulb" relay_2_icon: "mdi:lightbulb"
switch_3_name: "Spare 3" switch_3_name: "Spare 3"
button_3_name: "Button 3" button_3_name: "Button 3"
relay_3_icon: "mdi:lightbulb" relay_3_icon: "mdi:lightbulb"
switch_4_name: "Spare 4" switch_4_name: "Spare 4"
button_4_name: "Button 4" button_4_name: "Button 4"
relay_4_icon: "mdi:lightbulb" relay_4_icon: "mdi:lightbulb"
########################################################################################## #:########################################################################################:#
# PACKAGES: Included Common Packages # PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html # https://esphome.io/components/packages.html
########################################################################################## #:########################################################################################:#
packages: packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode #### #### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include common_wifi: !include
@@ -66,6 +110,7 @@ packages:
local_device_name: "${device_name}" local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}" local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}" local_ota_pass: "${ota_pass}"
local_current_ip_address: "${current_ip_address}"
#### HOME ASSISTANT API (choose encryption or no encryption options) #### #### HOME ASSISTANT API (choose encryption or no encryption options) ####
common_api: !include common_api: !include
@@ -79,93 +124,86 @@ packages:
file: common/mqtt_common.yaml file: common/mqtt_common.yaml
vars: vars:
local_device_name: "${device_name}" local_device_name: "${device_name}"
#### WEB PORTAL #### #### WEB PORTAL ####
#common_webportal: !include common/webportal_common.yaml #common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) #### #### SNTP (Only use if you want/need accurate timeclocks) ####
#common_sntp: !include common/sntp_common.yaml #common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors #### #### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml #diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
########################################################################################## #:########################################################################################:#
# ESPHome # ESPHOME:
# https://esphome.io/components/esphome.html # https://esphome.io/components/esphome.html
########################################################################################## #:########################################################################################:#
esphome: esphome:
name: "${device_name}" name: "${device_name}"
friendly_name: "${friendly_name}" friendly_name: "${friendly_name}"
comment: "${description_comment}" # Appears on the esphome page in HA comment: "${description_comment}" # Appears on the esphome page in HA
area: "${device_area}" area: "${device_area}"
# platformio_options:
# build_flags:
# - "-Os" # optimize for size
# - "-Wl,--gc-sections" # drop unused code/data
# - "-fno-exceptions" # strip C++ exceptions
# - "-fno-rtti" # strip C++ RTTI
#:########################################################################################:#
########################################################################################## # ESP PLATFORM AND FRAMEWORK:
# ESP Platform and Framework # https://esphome.io/components/esp8266/
# https://esphome.io/components/esp32.html #:########################################################################################:#
##########################################################################################
esp8266: esp8266:
board: esp01_1m # The original sonoff basic board: esp01_1m
restore_from_flash: True # restore some values on reboot restore_from_flash: true
preferences: preferences:
flash_write_interval: 5min flash_write_interval: 5min
mdns: mdns:
disabled: False disabled: false
########################################################################################## #:########################################################################################:#
# ESPHome Logging Enable # LOGGING:
# https://esphome.io/components/logger.html # https://esphome.io/components/logger.html
########################################################################################## #:########################################################################################:#
logger: logger:
level: "${log_level}" #INFO Level suggested, or DEBUG for testing level: "${log_level}"
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM) baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
########################################################################################## #:########################################################################################:#
# SWITCH COMPONENT # SWITCH COMPONENT:
# https://esphome.io/components/switch/ # https://esphome.io/components/switch/
########################################################################################## # Sonoff 4Ch R2 Relays are GPIO12, GPIO05, GPIO04, GPIO15
# Sonoff 4Ch R2 Relays are GPIO12,05,04,15 #:########################################################################################:#
#############################################
switch: switch:
- platform: gpio - platform: gpio
id: relay1 id: relay1
name: "${switch_1_name}" name: "${switch_1_name}"
pin: GPIO12 pin: GPIO12
icon: "${relay_1_icon}" icon: "${relay_1_icon}"
- platform: gpio - platform: gpio
id: relay2 id: relay2
name: "${switch_2_name}" name: "${switch_2_name}"
pin: GPIO5 pin: GPIO5
icon: "${relay_2_icon}" icon: "${relay_2_icon}"
- platform: gpio - platform: gpio
id: relay3 id: relay3
name: "${switch_3_name}" name: "${switch_3_name}"
pin: GPIO4 pin: GPIO4
icon: "${relay_3_icon}" icon: "${relay_3_icon}"
- platform: gpio - platform: gpio
id: relay4 id: relay4
name: "${switch_4_name}" name: "${switch_4_name}"
pin: GPIO15 pin: GPIO15
icon: "${relay_4_icon}" icon: "${relay_4_icon}"
########################################################################################## #:########################################################################################:#
# BINARY SENSORS # BINARY SENSORS:
# https://esphome.io/components/binary_sensor/ # https://esphome.io/components/binary_sensor/
########################################################################################## # Sonoff 4Ch R2 Buttons are GPIO00, GPIO09, GPIO10, GPIO14
# Sonoff 4Ch R2 Buttons are GPIO00,09,10,14 #:########################################################################################:#
#############################################
binary_sensor: binary_sensor:
- platform: gpio - platform: gpio
id: button1 id: button1
@@ -173,40 +211,44 @@ binary_sensor:
pin: pin:
number: GPIO0 number: GPIO0
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay1 - switch.toggle: relay1
- platform: gpio - platform: gpio
id: button2 id: button2
name: "${button_2_name}" name: "${button_2_name}"
pin: pin:
number: GPIO9 number: GPIO9
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay2 - switch.toggle: relay2
- platform: gpio - platform: gpio
id: button3 id: button3
name: "${button_3_name}" name: "${button_3_name}"
pin: pin:
number: GPIO10 number: GPIO10
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay3 - switch.toggle: relay3
- platform: gpio - platform: gpio
id: button4 id: button4
name: "${button_4_name}" name: "${button_4_name}"
pin: pin:
number: GPIO14 number: GPIO14
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: True inverted: true
on_press: on_press:
- switch.toggle: relay4 - switch.toggle: relay4
# Extra remote switch input -> toggles relay 1
- platform: gpio - platform: gpio
pin: pin:
number: GPIO03 number: GPIO3
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: true inverted: true
name: "${switch_1_name} Remote Switch" name: "${switch_1_name} Remote Switch"
@@ -219,15 +261,15 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay1).state) { if (id(relay1).state) {
// Relay is ON: turn it OFF
id(relay1).turn_off(); id(relay1).turn_off();
} else { } else {
// Relay is OFF: turn it ON
id(relay1).turn_on(); id(relay1).turn_on();
} }
# Extra remote switch input -> toggles relay 2
- platform: gpio - platform: gpio
pin: pin:
number: GPIO02 number: GPIO2
mode: INPUT_PULLUP mode: INPUT_PULLUP
inverted: true inverted: true
name: "${switch_2_name} Remote Switch" name: "${switch_2_name} Remote Switch"
@@ -240,28 +282,24 @@ binary_sensor:
then: then:
- lambda: |- - lambda: |-
if (id(relay2).state) { if (id(relay2).state) {
// Relay is ON: turn it OFF
id(relay2).turn_off(); id(relay2).turn_off();
} else { } else {
// Relay is OFF: turn it ON
id(relay2).turn_on(); id(relay2).turn_on();
} }
########################################################################################## #:########################################################################################:#
# STATUS LED # STATUS LED:
# https://esphome.io/components/status_led.html # https://esphome.io/components/status_led.html
########################################################################################## #:########################################################################################:#
# Sonoff Basic R1 LED is GPIO13
#############################################
status_led: status_led:
pin: pin:
number: GPIO13 number: GPIO13
inverted: yes inverted: true
########################################################################################## #:########################################################################################:#
# MQTT COMMANDS # MQTT:
# This adds device-specific MQTT command triggers to the common MQTT configuration. # This adds device-specific MQTT command triggers to the common MQTT configuration.
########################################################################################## #:########################################################################################:#
mqtt: mqtt:
on_message: on_message:
# Relay 1 control # Relay 1 control
@@ -273,6 +311,7 @@ mqtt:
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay1 - switch.turn_off: relay1
# Relay 2 control # Relay 2 control
- topic: "${mqtt_local_command_topic}/relay2/set" - topic: "${mqtt_local_command_topic}/relay2/set"
payload: "ON" payload: "ON"
@@ -282,6 +321,7 @@ mqtt:
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay2 - switch.turn_off: relay2
# Relay 3 control # Relay 3 control
- topic: "${mqtt_local_command_topic}/relay3/set" - topic: "${mqtt_local_command_topic}/relay3/set"
payload: "ON" payload: "ON"
@@ -290,8 +330,9 @@ mqtt:
- topic: "${mqtt_local_command_topic}/relay3/set" - topic: "${mqtt_local_command_topic}/relay3/set"
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay3 - switch.turn_off: relay3
# Relay 4 control
# Relay 4 control
- topic: "${mqtt_local_command_topic}/relay4/set" - topic: "${mqtt_local_command_topic}/relay4/set"
payload: "ON" payload: "ON"
then: then:
@@ -299,6 +340,4 @@ mqtt:
- topic: "${mqtt_local_command_topic}/relay4/set" - topic: "${mqtt_local_command_topic}/relay4/set"
payload: "OFF" payload: "OFF"
then: then:
- switch.turn_off: relay4 - switch.turn_off: relay4