yaml layout updates to v1.x
This commit is contained in:
+118
-84
@@ -1,35 +1,67 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# 3D PRINTER POWER AND SWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: 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
|
||||
#############################################
|
||||
# Sonoff POW R1
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# Sonoff POW R1 (ESP8266)
|
||||
# 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)
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-3dprinterpow"
|
||||
friendly_name: "3D Printer Power"
|
||||
description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1."
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1. (Layout V1.1)"
|
||||
device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
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_name: "Sonoff Technologies.POW R1" # Project Details
|
||||
project_version: "v1.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords & Secrets
|
||||
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
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
@@ -42,16 +74,16 @@ substitutions:
|
||||
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_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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -74,23 +106,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -104,80 +136,74 @@ esphome:
|
||||
then:
|
||||
- script.execute: publish_state_burst
|
||||
|
||||
#############################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
#############################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: ${log_level} #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#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.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Switch control from MQTT
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay
|
||||
- light.turn_on: led
|
||||
- switch.turn_on: relay
|
||||
- light.turn_on: led
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay
|
||||
- light.turn_off: led
|
||||
- switch.turn_off: relay
|
||||
- light.turn_off: led
|
||||
|
||||
#############################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#############################################
|
||||
#status_led:
|
||||
# pin:
|
||||
# number: GPIO2
|
||||
# inverted: yes
|
||||
|
||||
#############################################
|
||||
# SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO00
|
||||
number: GPIO0
|
||||
mode: INPUT_PULLUP
|
||||
inverted: True
|
||||
name: Button
|
||||
inverted: true
|
||||
name: "Button"
|
||||
on_press:
|
||||
- switch.toggle: virtual_button
|
||||
|
||||
- platform: template
|
||||
name: ${entity_prefix} Running
|
||||
name: "${entity_prefix} Running"
|
||||
filters:
|
||||
- delayed_off: 15s
|
||||
lambda: |-
|
||||
if (isnan(id(power).state)) {
|
||||
return {};
|
||||
} else if (id(power).state > 4) {
|
||||
// Running
|
||||
return true;
|
||||
} else {
|
||||
// Not running
|
||||
return false;
|
||||
}
|
||||
|
||||
#:########################################################################################:#
|
||||
# SENSORS COMPONENT:
|
||||
# https://esphome.io/components/sensor/
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
- platform: hlw8012
|
||||
sel_pin: 5
|
||||
@@ -185,20 +211,17 @@ sensor:
|
||||
cf1_pin: 13
|
||||
update_interval: 2s
|
||||
current:
|
||||
name: ${entity_prefix} Current
|
||||
name: "${entity_prefix} Current"
|
||||
voltage:
|
||||
name: ${entity_prefix} Voltage
|
||||
name: "${entity_prefix} Voltage"
|
||||
power:
|
||||
name: ${entity_prefix} Power
|
||||
name: "${entity_prefix} 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:
|
||||
- platform: template
|
||||
name: "Relay"
|
||||
@@ -215,7 +238,6 @@ switch:
|
||||
id: relay
|
||||
pin: GPIO12
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
# restore_mode: ALWAYS_ON # Or RESTORE_DEFAULT_ON/RESTORE_DEFAULT_OFF
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
@@ -227,19 +249,31 @@ switch:
|
||||
payload: "OFF"
|
||||
retain: false
|
||||
|
||||
#:########################################################################################:#
|
||||
# OUTPUT COMPONENT:
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: pow_blue_led
|
||||
pin:
|
||||
number: GPIO15
|
||||
inverted: True
|
||||
inverted: true
|
||||
|
||||
#:########################################################################################:#
|
||||
# LIGHT COMPONENT:
|
||||
# https://esphome.io/components/light/
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: monochromatic
|
||||
name: Status LED
|
||||
name: "Status LED"
|
||||
output: pow_blue_led
|
||||
id: led
|
||||
|
||||
#:########################################################################################:#
|
||||
# SCRIPT COMPONENT:
|
||||
# https://esphome.io/components/script.html
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
- id: publish_state_burst
|
||||
mode: restart
|
||||
|
||||
@@ -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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-arcademachine1"
|
||||
friendly_name: "Arcade Cabinet 1"
|
||||
description_comment: "MAME Arcade 1 (Defender) machine power :: Athom Smart Plug Power V1"
|
||||
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
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.
|
||||
|
||||
# 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
|
||||
|
||||
# Passwords
|
||||
@@ -34,13 +51,14 @@ substitutions:
|
||||
update_interval: "10s" # update time for for general sensors etc
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:power-socket-au"
|
||||
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
||||
|
||||
##########################################################################################
|
||||
relay_icon: "mdi:power-socket-au"
|
||||
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
||||
|
||||
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
##################################################
|
||||
# MANDATORY packages (won't compile without them!)
|
||||
@@ -57,7 +75,7 @@ packages:
|
||||
|
||||
##################################################
|
||||
# OPTIONAL packages (comment if you don't want them)
|
||||
##################################################
|
||||
##################################################
|
||||
|
||||
#### HOME ASSISTANT API (choose encryption or no encryption options) ####
|
||||
common_api: !include
|
||||
@@ -65,7 +83,7 @@ packages:
|
||||
#file: common/api_common_noencryption.yaml
|
||||
vars:
|
||||
local_api_key: "${api_key}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
common_webportal: !include
|
||||
file: common/webportal_common.yaml
|
||||
@@ -75,7 +93,7 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include
|
||||
file: common/sntp_common.yaml
|
||||
@@ -100,56 +118,69 @@ packages:
|
||||
local_friendly_name: "${friendly_name}"
|
||||
local_current_limit: "${current_limit}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
|
||||
#:########################################################################################:#
|
||||
# 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}"
|
||||
name_add_mac_suffix: False
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
name_add_mac_suffix: false
|
||||
min_version: 2024.6.0
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp8285
|
||||
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
|
||||
#framework:
|
||||
# version: 2.7.4
|
||||
|
||||
|
||||
#:########################################################################################:#
|
||||
# PREFERENCES:
|
||||
# https://esphome.io/components/preferences.html
|
||||
#:########################################################################################:#
|
||||
preferences:
|
||||
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
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO03
|
||||
number: GPIO3
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "Power Button"
|
||||
@@ -162,28 +193,28 @@ binary_sensor:
|
||||
then:
|
||||
- lambda: |-
|
||||
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();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON and set mode to 3 (BOOST)
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay).turn_on();
|
||||
}
|
||||
|
||||
|
||||
- platform: template
|
||||
name: "Relay Status"
|
||||
lambda: |-
|
||||
return id(relay).state;
|
||||
|
||||
#################################################################################################
|
||||
# SWITCH COMPONENT
|
||||
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#################################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Power Output"
|
||||
pin: GPIO14
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
icon: "${relay_icon}"
|
||||
|
||||
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
icon: "${relay_icon}"
|
||||
@@ -1,39 +1,62 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# MASTER BEDROOM BEDSIDE LAMP BULB
|
||||
# File: esp-bedrm1arlecbulb.yaml
|
||||
#
|
||||
# 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)
|
||||
#
|
||||
# Hardware: Arlec Grid Connect Smart LED Globe RGB (GLD120HA) - B22
|
||||
# RGB + Warm White + Cold White (RGBWW, 5x PWM channels)
|
||||
#
|
||||
# NOTES
|
||||
# - This keeps the "preferred control" ramping / min-max / watchdog / restore logic.
|
||||
#:########################################################################################:#
|
||||
# TITLE: MASTER BEDROOM BEDSIDE LAMP BULB
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-bedrm1arlecbulb.yaml
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# v1.2 2026-02-25 Updated yaml to zorruno layout V1.1
|
||||
# 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)
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
# (so everyday dimming uses the Warm White channel only, not mixed CT).
|
||||
# - You can still control full RGB and CT from HA using the normal light entity.
|
||||
# (everyday dimming uses Warm White channel only, not mixed CT).
|
||||
# - 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).
|
||||
# - Jump Fade switch behavior:
|
||||
# - 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).
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# 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:
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm1arlecbulb" # yaml file should be device_name.yaml
|
||||
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"
|
||||
|
||||
# Project Naming
|
||||
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)
|
||||
# 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"
|
||||
|
||||
# Device Specific Settings
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "20s"
|
||||
led_gamma: "2.8"
|
||||
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
|
||||
maximum_led_output: "80" # % Hard cap
|
||||
max_on_default_hours: "24" # 0 = no automatic turn-off
|
||||
pwm_frequency: "1000" # Hz
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "20s"
|
||||
led_gamma: "2.8"
|
||||
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
|
||||
maximum_led_output: "80" # % Hard cap
|
||||
max_on_default_hours: "24" # 0 = no automatic turn-off
|
||||
pwm_frequency: "1000" # Hz
|
||||
|
||||
# Warm/cold endpoints (reported range around 3000K-5700K)
|
||||
bulb_warm_kelvin: "3000 K"
|
||||
bulb_cold_kelvin: "5700 K"
|
||||
bulb_warm_kelvin: "3000 K"
|
||||
bulb_cold_kelvin: "5700 K"
|
||||
|
||||
# Arlec GLD120HA GPIO mapping (PWM)
|
||||
bulb_red_pin: GPIO4
|
||||
bulb_green_pin: GPIO12
|
||||
bulb_blue_pin: GPIO14
|
||||
bulb_warm_white_pin: GPIO13
|
||||
bulb_cold_white_pin: GPIO5
|
||||
bulb_red_pin: GPIO4
|
||||
bulb_green_pin: GPIO12
|
||||
bulb_blue_pin: GPIO14
|
||||
bulb_warm_white_pin: GPIO13
|
||||
bulb_cold_white_pin: GPIO5
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/packages.html
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -100,13 +124,14 @@ packages:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
#### 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_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
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome CORE CONFIGURATION
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESPHOME CORE CONFIGURATION
|
||||
# https://esphome.io/components/esphome.html
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -158,9 +183,10 @@ esphome:
|
||||
# Boot complete: allow OFF handlers again
|
||||
- lambda: 'id(booting) = false;'
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/esp8266.html
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
restore_from_flash: true
|
||||
@@ -171,9 +197,10 @@ mdns:
|
||||
preferences:
|
||||
flash_write_interval: 1min
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# GLOBAL VARIABLES
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/globals.html
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
- id: min_brightness_pct
|
||||
type: int
|
||||
@@ -255,22 +282,23 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: "false"
|
||||
|
||||
# Jump Fade percentage (default 25%)
|
||||
# Jump Fade percentage
|
||||
- id: jump_fade_pct
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "15"
|
||||
|
||||
##########################################################################################
|
||||
# LOGGER
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LOGGING
|
||||
# https://esphome.io/components/logger.html
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}"
|
||||
baud_rate: 0
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT COMMANDS (adds device-specific triggers to common MQTT)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
- topic: "${mqtt_local_command_topic}/light/set"
|
||||
@@ -283,9 +311,10 @@ mqtt:
|
||||
then:
|
||||
- switch.turn_off: bulb_ramp_switch
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SWITCH
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/switch/
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: template
|
||||
id: bulb_ramp_switch
|
||||
@@ -319,9 +348,10 @@ switch:
|
||||
id(ramp_switch_target_on) = false;
|
||||
- script.execute: jump_ramp_off_script
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# BUTTON
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/button/index.html
|
||||
#:########################################################################################:#
|
||||
button:
|
||||
- platform: template
|
||||
id: fade_up_button
|
||||
@@ -370,9 +400,10 @@ button:
|
||||
id(last_brightness_pct) = pct;
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SELECT
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/select/index.html
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
id: restart_action
|
||||
@@ -394,9 +425,10 @@ select:
|
||||
id(restart_mode) = 2;
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SENSORS
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/sensor/
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
- platform: template
|
||||
id: bulb_output_pct
|
||||
@@ -445,9 +477,10 @@ sensor:
|
||||
if (pwm > 1.0f) pwm = 1.0f;
|
||||
return pwm * 100.0f;
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# OUTPUTS: 5 x PWM channels for the Arlec GLD120HA RGBWW bulb
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: output_red
|
||||
@@ -474,9 +507,10 @@ output:
|
||||
pin: ${bulb_cold_white_pin}
|
||||
frequency: ${pwm_frequency}
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LIGHT: RGBWW (correct for this bulb)
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/light/
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: rgbww
|
||||
id: bulb_light
|
||||
@@ -492,10 +526,9 @@ light:
|
||||
warm_white_color_temperature: ${bulb_warm_kelvin}
|
||||
cold_white_color_temperature: ${bulb_cold_kelvin}
|
||||
|
||||
# Safety: do not allow RGB and whites simultaneously
|
||||
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
|
||||
|
||||
default_transition_length: 2s
|
||||
@@ -533,7 +566,6 @@ light:
|
||||
id(last_set_pos) = 0;
|
||||
id(led_output_set_pct).publish_state(0);
|
||||
|
||||
# Cap brightness to max_brightness_pct without a visible step
|
||||
on_state:
|
||||
- lambda: |-
|
||||
const float cap = id(max_brightness_pct) / 100.0f;
|
||||
@@ -548,9 +580,10 @@ light:
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# NUMBER
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/number/
|
||||
#:########################################################################################:#
|
||||
number:
|
||||
- platform: template
|
||||
id: cfg_ramp_up_s
|
||||
@@ -612,7 +645,6 @@ number:
|
||||
id(jump_fade_pct) = v;
|
||||
id(cfg_jump_fade_pct).publish_state((float) v);
|
||||
|
||||
# This is the preferred everyday dimmer slider (FORCES Warm endpoint)
|
||||
- platform: template
|
||||
id: led_output_set_pct
|
||||
name: "${friendly_name} Output Set (0-100)"
|
||||
@@ -713,9 +745,10 @@ number:
|
||||
then:
|
||||
- script.execute: max_on_watchdog
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SCRIPTS
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/script.html
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
- id: ramp_on_script
|
||||
mode: restart
|
||||
@@ -930,7 +963,6 @@ script:
|
||||
then:
|
||||
- script.stop: ramp_off_script
|
||||
|
||||
# Jump UP to (jump_pct% of max cap), only if we are below it.
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
@@ -971,7 +1003,6 @@ script:
|
||||
return target_pct / 100.0f;
|
||||
transition_length: 0s
|
||||
|
||||
# Then fade up to full using your normal fade logic
|
||||
- script.execute: ramp_on_script
|
||||
|
||||
# Jump Fade: OFF = jump down to (current - current*jump%) then normal fade down to OFF
|
||||
@@ -980,12 +1011,10 @@ script:
|
||||
then:
|
||||
- script.stop: ramp_on_script
|
||||
|
||||
# If the light is off already, do nothing fancy (avoids a flash from ramp_off_script).
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(bulb_light).current_values.is_on();'
|
||||
then:
|
||||
# Jump DOWN to (100 - jump)% of current brightness (25 -> 75%), clamp to min.
|
||||
- light.turn_on:
|
||||
id: bulb_light
|
||||
color_temperature: "${bulb_warm_kelvin}"
|
||||
@@ -997,7 +1026,7 @@ script:
|
||||
if (jp < 0.0f) jp = 0.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 minp = (float) id(min_brightness_pct);
|
||||
@@ -1010,7 +1039,6 @@ script:
|
||||
return target_pct / 100.0f;
|
||||
transition_length: 0s
|
||||
|
||||
# Then fade down to off using your normal fade logic
|
||||
- script.execute: ramp_off_script
|
||||
else:
|
||||
- light.turn_off:
|
||||
|
||||
+162
-133
@@ -1,70 +1,88 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CEILING FAN - BEDROOM 2
|
||||
# - 3 speed fan using Sonoff IFan02
|
||||
# - Also, single Light Output
|
||||
#:########################################################################################:#
|
||||
# TITLE: CEILING FAN - BEDROOM 2
|
||||
# zorruno.com layout v1.0 2026
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
#
|
||||
# V1.0 - 2025-07-21 First Setup (and replacement of Tasmota)
|
||||
#
|
||||
# NOTES:
|
||||
# Command the fan with MQTT
|
||||
# ${mqtt_local_command_full_topic}/speed/set 1,2,3,0,+,-
|
||||
# ${mqtt_local_command_full_topic}/light/set ON,OFF
|
||||
# Status of the fan is in MQTT
|
||||
# ${mqtt_local_command_full_topic}/speed/state 1,2,3,0
|
||||
# ${mqtt_local_command_full_topic}/light/state ON,OFF
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Fan speed status:
|
||||
# ${mqtt_local_status_topic}/speed/state -> 0,1,2,3
|
||||
# Fan light status:
|
||||
# ${mqtt_local_status_topic}/light/state -> ON,OFF
|
||||
#:########################################################################################:#
|
||||
# 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 (speed and light state)
|
||||
# - HA entities (fan/light/select) will be unavailable until HA returns
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm2ceilingfan"
|
||||
friendly_name: "Bedroom 2 Ceiling Fan"
|
||||
description_comment: "3 Speed Overhead Ceiling Fan Bedroom 2 :: Sonoff ifan02"
|
||||
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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
|
||||
|
||||
# Passwords & Secrets
|
||||
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
|
||||
|
||||
# Passwords and Secrets
|
||||
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
|
||||
mqtt_local_command_main_topic: !secret mqtt_command_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
|
||||
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-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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic used to command this 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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -73,6 +91,7 @@ packages:
|
||||
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
|
||||
@@ -86,102 +105,99 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# 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}"
|
||||
on_boot: # This weird toggle thing makes sure the states get restored on reboot
|
||||
priority : -100
|
||||
on_boot: # Publish restored speed on boot so other systems can sync
|
||||
priority: -100
|
||||
then:
|
||||
- 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:
|
||||
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
|
||||
# - "-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
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m # The original sonoff basic
|
||||
restore_from_flash: True # restore some values on reboot
|
||||
board: esp01_1m # Sonoff iFan02
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min
|
||||
|
||||
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:
|
||||
- id: speed_value
|
||||
type: int
|
||||
restore_value: yes
|
||||
initial_value: '0'
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
level: "${log_level}" # INFO suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART (UART0 used for fan MCU sniffing)
|
||||
|
||||
##########################################################################################
|
||||
# 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)
|
||||
# - 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
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
uart:
|
||||
id: ifan_uart
|
||||
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)
|
||||
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)
|
||||
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
|
||||
# NOTE: If no frames appear at either 9600 or 19200, try moving rx_pin to GPIO13 and reflash:
|
||||
# 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
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
interval:
|
||||
- interval: 50ms
|
||||
then:
|
||||
@@ -206,20 +222,20 @@ interval:
|
||||
frame.clear();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# TEXT SENSORS: RF/MCU debug output (last frame seen)
|
||||
# - Shows the last raw hex bytes received from the fan MCU when you press the RF remote
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# TEXT SENSORS COMPONENT:
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
#:########################################################################################:#
|
||||
text_sensor:
|
||||
- platform: template
|
||||
id: ifan_last_rf
|
||||
name: "iFan02 Remote Last Frame"
|
||||
update_interval: never
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control
|
||||
@@ -227,12 +243,13 @@ mqtt:
|
||||
payload: "ON"
|
||||
then:
|
||||
- light.turn_on: ifan02_light
|
||||
|
||||
- topic: "${mqtt_local_command_topic}/light/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- light.turn_off: ifan02_light
|
||||
|
||||
# Fan speed control (0–3) + ramp up/down (+ / -)
|
||||
# Fan speed control (0-3) plus ramp up/down (+ / -)
|
||||
- topic: "${mqtt_local_command_topic}/speed/set"
|
||||
then:
|
||||
# 1) Compute new speed_value based on payload
|
||||
@@ -257,21 +274,21 @@ mqtt:
|
||||
# 2) Drive the fan based on the new value
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(speed_value) == 0;'
|
||||
lambda: "return id(speed_value) == 0;"
|
||||
then:
|
||||
- fan.turn_off: ifan02_fan
|
||||
else:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: !lambda 'return id(speed_value);'
|
||||
speed: !lambda "return id(speed_value);"
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff ifan02 has relays, but they don't need to be shown in HA because
|
||||
# the speed of the fan is the important part (and combinations of the relays give that)
|
||||
##########################################################################################
|
||||
#
|
||||
# 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)
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "${switch_3_name}"
|
||||
@@ -279,12 +296,14 @@ switch:
|
||||
id: fan3sw
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
- platform: gpio
|
||||
name: "${switch_2_name}"
|
||||
pin: GPIO5
|
||||
id: fan2sw
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
- platform: gpio
|
||||
name: "${switch_4_name}"
|
||||
pin: GPIO15
|
||||
@@ -292,10 +311,10 @@ switch:
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
##########################################################################################
|
||||
# SELECT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SELECT COMPONENT:
|
||||
# https://esphome.io/components/select/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
name: "Bedroom 2 Fan Speed"
|
||||
@@ -322,6 +341,7 @@ select:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- fan.turn_off: ifan02_fan
|
||||
|
||||
# LOW (1)
|
||||
- if:
|
||||
condition:
|
||||
@@ -332,6 +352,7 @@ select:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: 1
|
||||
|
||||
# MEDIUM (2)
|
||||
- if:
|
||||
condition:
|
||||
@@ -342,6 +363,7 @@ select:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: 2
|
||||
|
||||
# HIGH (3)
|
||||
- if:
|
||||
condition:
|
||||
@@ -353,13 +375,17 @@ select:
|
||||
id: ifan02_fan
|
||||
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:
|
||||
- platform: gpio
|
||||
pin: GPIO12
|
||||
id: lightrelay
|
||||
|
||||
- platform: template
|
||||
type: float
|
||||
id: fan_decode
|
||||
@@ -386,17 +412,17 @@ output:
|
||||
id(fan4sw).turn_on();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LIGHT COMPONENT:
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: binary
|
||||
name: "${light_1_name}"
|
||||
output: lightrelay
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
id: ifan02_light
|
||||
# publish status updates when the light turns on/off:
|
||||
# Publish status updates when the light turns on/off
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
@@ -406,10 +432,10 @@ light:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
payload: "OFF"
|
||||
|
||||
##########################################################################################
|
||||
# FAN COMPONENT
|
||||
#:########################################################################################:#
|
||||
# FAN COMPONENT:
|
||||
# https://esphome.io/components/fan/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
fan:
|
||||
- platform: speed
|
||||
output: fan_decode
|
||||
@@ -417,28 +443,31 @@ fan:
|
||||
id: ifan02_fan
|
||||
speed_count: 3
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
# whenever you explicitly set a speed (1–3):
|
||||
|
||||
# Whenever you explicitly set a speed (1-3)
|
||||
on_speed_set:
|
||||
- lambda: |-
|
||||
id(speed_value) = x;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
# whenever the fan goes fully off:
|
||||
payload: !lambda "return to_string(id(speed_value));"
|
||||
|
||||
# Whenever the fan goes fully off
|
||||
on_turn_off:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: "0"
|
||||
# whenever the fan goes off→on (e.g. via HA’s Fan switch):
|
||||
|
||||
# Whenever the fan goes off->on (eg via HA fan switch)
|
||||
on_turn_on:
|
||||
- lambda: |-
|
||||
// bump 0->1 if we were off
|
||||
// Bump 0->1 if we were off
|
||||
if (id(speed_value) == 0) id(speed_value) = 1;
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: !lambda 'return id(speed_value);'
|
||||
speed: !lambda "return id(speed_value);"
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
payload: !lambda "return to_string(id(speed_value));"
|
||||
@@ -1,36 +1,61 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 2 FAN SWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: BEDROOM 2 FAN SWITCH (WALL 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
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# V1.0 - 2025-07-23 First Setup (and replacement of Tasmota)
|
||||
#
|
||||
# NOTES
|
||||
# - Switch for Ceiling Fan
|
||||
# - 3 Switches, Up, Down and Off
|
||||
# - Remote commands to the fan ${mqtt_remote_command_full_topic}/speed/set 1,2,3,0,+,-
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Subscribed speed state topic (drives relay indicators):
|
||||
# ${mqtt_local_status_topic} -> 0,1,2,3
|
||||
#:########################################################################################:#
|
||||
# OFFLINE NOTES:
|
||||
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
|
||||
# - Buttons still publish MQTT commands directly to the fan
|
||||
# - Relay indicator sync still works (subscribed MQTT state updates)
|
||||
# - HA entities for this switch device are unavailable until HA returns
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm2fanswitch"
|
||||
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)"
|
||||
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
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.
|
||||
|
||||
# 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.
|
||||
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
|
||||
|
||||
# Passwords
|
||||
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
|
||||
mqtt_command_main_topic: !secret mqtt_command_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
|
||||
#mqtt_device_name: "bedroom2-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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# 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
|
||||
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_device_name: "bedroom2-ceilingfan"
|
||||
mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/speed/set"
|
||||
mqtt_remote_device_command1: "+"
|
||||
mqtt_remote_device_command2: "-"
|
||||
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
|
||||
|
||||
# Button Naming & Icons
|
||||
|
||||
# Fan speed status topic (used to sync relay indicators)
|
||||
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/speed/state"
|
||||
|
||||
# Switch/Relay Naming & Icons
|
||||
#relay_icon: "mdi:heating-coil"
|
||||
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_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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -77,6 +99,7 @@ packages:
|
||||
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
|
||||
@@ -90,85 +113,80 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# 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}
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
# 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
|
||||
# on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_3
|
||||
# - "-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
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
level: "${log_level}" # INFO suggested, or DEBUG for testing
|
||||
#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
|
||||
#tx_buffer_size: 64
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Status LED for KS-811 is GPIO02
|
||||
##########################################################################################
|
||||
# Status LED for KS-811 is GPIO2
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO02
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04
|
||||
##########################################################################################
|
||||
# Buttons for KS-811-3 are GPIO16, GPIO5, GPIO4
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # This pin does not support interrupts so use polling (suppresses warning).
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
@@ -179,7 +197,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
@@ -190,33 +208,38 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO4
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 3: ${switch_3_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic}"
|
||||
payload: "${mqtt_remote_device_command3}"
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Relays for KS-811-3 are GPIO13, GPIO12, GPIO14
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 3: ${switch_3_name}"
|
||||
pin: GPIO14
|
||||
id: Relay_3
|
||||
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# Subscribe to fan speed state and mirror it to relay indicator pattern
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
- topic: "${mqtt_local_status_topic}"
|
||||
|
||||
@@ -1,60 +1,73 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 2 LIGHTSWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: BEDROOM 2 LIGHTSWITCH
|
||||
# zorruno.com layout v1.0 2026
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# V3.5 2025-07-24 YAML tidyups
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# NOTES
|
||||
# -
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# 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:
|
||||
# - 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm2lights"
|
||||
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)"
|
||||
device_area: "Bedroom 2" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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_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
|
||||
|
||||
# Passwords & Secrets
|
||||
# Passwords and Secrets
|
||||
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
|
||||
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
|
||||
#relay_icon: "mdi:lightbulb-group"
|
||||
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
|
||||
#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
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Main Lights"
|
||||
switch_2_name: "Desk Lights"
|
||||
#switch_3_name: "Nil"
|
||||
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -63,6 +76,7 @@ packages:
|
||||
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
|
||||
@@ -76,23 +90,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -101,50 +115,52 @@ esphome:
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
#on_boot:
|
||||
#on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
#########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
level: "${log_level}" # INFO suggested, or DEBUG for testing
|
||||
#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
|
||||
#tx_buffer_size: 64
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
# Buttons for KS-811-2 are GPIO16, GPIO5
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_1
|
||||
@@ -153,7 +169,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_2
|
||||
@@ -163,15 +179,16 @@ binary_sensor:
|
||||
# pin:
|
||||
# number: GPIO4
|
||||
# mode: INPUT
|
||||
# inverted: True
|
||||
# inverted: true
|
||||
# name: "Button 3: ${switch_3_name}"
|
||||
# on_press:
|
||||
# - switch.toggle: Relay_3
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
# Relays for KS-811-2 are GPIO13, GPIO12
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
@@ -187,6 +204,4 @@ switch:
|
||||
# - platform: gpio
|
||||
# name: "Relay 3: ${switch_3_name}"
|
||||
# pin: GPIO14
|
||||
# id: Relay_3
|
||||
|
||||
|
||||
# id: Relay_3
|
||||
+145
-119
@@ -1,72 +1,88 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CEILING FAN - BEDROOM 3
|
||||
# - 3 speed fan using Sonoff IFan02
|
||||
# - Also, single Light Output
|
||||
#:########################################################################################:#
|
||||
# TITLE: CEILING FAN - BEDROOM 3
|
||||
# zorruno.com layout v1.0 2026
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
#
|
||||
# V1.0 - 2025-07-21 First Setup (and replacement of Tasmota)
|
||||
#
|
||||
# NOTES:
|
||||
# Command the fan with MQTT
|
||||
# ${mqtt_local_command_full_topic}/speed/set 1,2,3,0,+,-
|
||||
# ${mqtt_local_command_full_topic}/light/set ON,OFF
|
||||
# Status of the fan is in MQTT
|
||||
# ${mqtt_local_command_full_topic}/speed/state 1,2,3,0
|
||||
# ${mqtt_local_command_full_topic}/light/state ON,OFF
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Fan speed status:
|
||||
# ${mqtt_local_status_topic}/speed/state -> 0,1,2,3
|
||||
# Fan light status:
|
||||
# ${mqtt_local_status_topic}/light/state -> ON,OFF
|
||||
#:########################################################################################:#
|
||||
# OFFLINE NOTES:
|
||||
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
|
||||
# - Fan and light remain controllable via MQTT local command topics
|
||||
# - Status publishes to MQTT still occur (speed and light state)
|
||||
# - HA entities are unavailable until HA returns
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm3ceilingfan"
|
||||
friendly_name: "Bedroom 3 Ceiling Fan"
|
||||
description_comment: "3 Speed Overhead Ceiling Fan Bedroom 3 :: Sonoff ifan02"
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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
|
||||
|
||||
# Passwords & Secrets
|
||||
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
|
||||
|
||||
# Passwords and Secrets
|
||||
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
|
||||
mqtt_local_command_main_topic: !secret mqtt_command_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
|
||||
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: "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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
|
||||
# Button Naming & Icons
|
||||
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 used to view status locally without HA
|
||||
|
||||
# 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"
|
||||
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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -75,6 +91,7 @@ packages:
|
||||
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
|
||||
@@ -88,80 +105,76 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# 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}"
|
||||
on_boot: # This weird toggle thing makes sure the states get restored on reboot
|
||||
priority : -100
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
on_boot: # Publish restored speed on boot so other systems can sync
|
||||
priority: -100
|
||||
then:
|
||||
- delay: 200ms
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
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
|
||||
payload: !lambda "return to_string(id(speed_value));"
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m # The original sonoff basic
|
||||
restore_from_flash: True # restore some values on reboot
|
||||
board: esp01_1m # Sonoff iFan02
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min
|
||||
|
||||
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:
|
||||
- id: speed_value
|
||||
type: int
|
||||
restore_value: yes
|
||||
initial_value: '0'
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
level: "${log_level}" # 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
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control
|
||||
@@ -169,12 +182,13 @@ mqtt:
|
||||
payload: "ON"
|
||||
then:
|
||||
- light.turn_on: ifan02_light
|
||||
|
||||
- topic: "${mqtt_local_command_topic}/light/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- light.turn_off: ifan02_light
|
||||
|
||||
# Fan speed control (0–3) + ramp up/down (+ / -)
|
||||
# Fan speed control (0-3) plus ramp up/down (+ / -)
|
||||
- topic: "${mqtt_local_command_topic}/speed/set"
|
||||
then:
|
||||
# 1) Compute new speed_value based on payload
|
||||
@@ -199,21 +213,21 @@ mqtt:
|
||||
# 2) Drive the fan based on the new value
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(speed_value) == 0;'
|
||||
lambda: "return id(speed_value) == 0;"
|
||||
then:
|
||||
- fan.turn_off: ifan02_fan
|
||||
else:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: !lambda 'return id(speed_value);'
|
||||
speed: !lambda "return id(speed_value);"
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff ifan02 has relays, but they don't need to be shown in HA because
|
||||
# the speed of the fan is the important part (and combinations of the relays give that)
|
||||
##########################################################################################
|
||||
#
|
||||
# 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)
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "${switch_3_name}"
|
||||
@@ -221,12 +235,14 @@ switch:
|
||||
id: fan3sw
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
- platform: gpio
|
||||
name: "${switch_2_name}"
|
||||
pin: GPIO5
|
||||
id: fan2sw
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
- platform: gpio
|
||||
name: "${switch_4_name}"
|
||||
pin: GPIO15
|
||||
@@ -234,14 +250,14 @@ switch:
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
internal: true
|
||||
|
||||
##########################################################################################
|
||||
# SELECT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SELECT COMPONENT:
|
||||
# https://esphome.io/components/select/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
name: "Bedroom 2 Fan Speed"
|
||||
id: bedroom2_fan_speed_select
|
||||
name: "Bedroom 3 Fan Speed"
|
||||
id: bedroom3_fan_speed_select
|
||||
options:
|
||||
- "Off"
|
||||
- "Low"
|
||||
@@ -264,6 +280,7 @@ select:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- fan.turn_off: ifan02_fan
|
||||
|
||||
# LOW (1)
|
||||
- if:
|
||||
condition:
|
||||
@@ -274,6 +291,7 @@ select:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: 1
|
||||
|
||||
# MEDIUM (2)
|
||||
- if:
|
||||
condition:
|
||||
@@ -284,6 +302,7 @@ select:
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: 2
|
||||
|
||||
# HIGH (3)
|
||||
- if:
|
||||
condition:
|
||||
@@ -295,13 +314,17 @@ select:
|
||||
id: ifan02_fan
|
||||
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:
|
||||
- platform: gpio
|
||||
pin: GPIO12
|
||||
id: lightrelay
|
||||
|
||||
- platform: template
|
||||
type: float
|
||||
id: fan_decode
|
||||
@@ -328,17 +351,17 @@ output:
|
||||
id(fan4sw).turn_on();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LIGHT COMPONENT:
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: binary
|
||||
name: "${light_1_name}"
|
||||
output: lightrelay
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
id: ifan02_light
|
||||
# publish status updates when the light turns on/off:
|
||||
# Publish status updates when the light turns on/off
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
@@ -348,10 +371,10 @@ light:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
payload: "OFF"
|
||||
|
||||
##########################################################################################
|
||||
# FAN COMPONENT
|
||||
#:########################################################################################:#
|
||||
# FAN COMPONENT:
|
||||
# https://esphome.io/components/fan/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
fan:
|
||||
- platform: speed
|
||||
output: fan_decode
|
||||
@@ -359,28 +382,31 @@ fan:
|
||||
id: ifan02_fan
|
||||
speed_count: 3
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
# whenever you explicitly set a speed (1–3):
|
||||
|
||||
# Whenever you explicitly set a speed (1-3)
|
||||
on_speed_set:
|
||||
- lambda: |-
|
||||
id(speed_value) = x;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
# whenever the fan goes fully off:
|
||||
payload: !lambda "return to_string(id(speed_value));"
|
||||
|
||||
# Whenever the fan goes fully off
|
||||
on_turn_off:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: "0"
|
||||
# whenever the fan goes off→on (e.g. via HA’s Fan switch):
|
||||
|
||||
# Whenever the fan goes off->on (eg via HA fan switch)
|
||||
on_turn_on:
|
||||
- lambda: |-
|
||||
// bump 0→1 if we were off
|
||||
// bump 0->1 if we were off
|
||||
if (id(speed_value) == 0) id(speed_value) = 1;
|
||||
- fan.turn_on:
|
||||
id: ifan02_fan
|
||||
speed: !lambda 'return id(speed_value);'
|
||||
speed: !lambda "return id(speed_value);"
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
payload: !lambda "return to_string(id(speed_value));"
|
||||
@@ -1,76 +1,103 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 3 FAN SWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: BEDROOM 3 FAN SWITCH (WALL 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
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# V1.0 - 2025-07-23 First Setup (and replacement of Tasmota)
|
||||
#
|
||||
# NOTES
|
||||
# - Switch for Ceiling Fan
|
||||
# - 3 Switches, Up, Down and Off
|
||||
# - Remote commands to the fan ${mqtt_remote_command_full_topic}/speed/set 1,2,3,0,+,-
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Subscribed speed state topic (drives relay indicators):
|
||||
# ${mqtt_local_status_topic} -> 0,1,2,3
|
||||
#:########################################################################################:#
|
||||
# OFFLINE NOTES:
|
||||
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
|
||||
# - Buttons still publish MQTT commands directly to the fan
|
||||
# - Relay indicator sync still works (subscribed MQTT state updates)
|
||||
# - HA entities for this switch device are unavailable until HA returns
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm3fanswitch"
|
||||
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)"
|
||||
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.
|
||||
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.
|
||||
|
||||
# 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
|
||||
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
|
||||
static_ip_address: !secret esp-bedrm3fanswitch_ip
|
||||
mqtt_local_command_main_topic: !secret mqtt_command_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
|
||||
#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
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# MQTT LOCAL Controls
|
||||
#mqtt_device_name: "bedroom2-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_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
#mqtt_device_name: "bedroom3-ceilingfan-switch"
|
||||
#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 used to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
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_command1: "+"
|
||||
mqtt_remote_device_command2: "-"
|
||||
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
|
||||
#relay_icon: "mdi:heating-coil"
|
||||
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
|
||||
# Fan speed status topic (used to sync relay indicators)
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state"
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -79,6 +106,7 @@ packages:
|
||||
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
|
||||
@@ -92,85 +120,84 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# 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}
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" # Appears on the ESPHome page in HA
|
||||
area: "${device_area}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
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
|
||||
# on_boot:
|
||||
- "-Os" # optimize for size
|
||||
- "-Wl,--gc-sections" # drop unused code/data
|
||||
#- "-fno-exceptions" # strip C++ exceptions
|
||||
#- "-fno-rtti" # strip C++ RTTI
|
||||
# on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_3
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
level: "${log_level}" # INFO suggested, or DEBUG for testing
|
||||
#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
|
||||
#tx_buffer_size: 64
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Status LED for KS-811 is GPIO02
|
||||
##########################################################################################
|
||||
# Status LED for KS-811 is GPIO2
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO02
|
||||
inverted: yes
|
||||
number: GPIO2
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04
|
||||
##########################################################################################
|
||||
# Buttons for KS-811-3 are GPIO16, GPIO5, GPIO4
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # GPO16 pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
@@ -181,7 +208,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
@@ -192,33 +219,38 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO4
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 3: ${switch_3_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic}"
|
||||
payload: "${mqtt_remote_device_command3}"
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Relays for KS-811-3 are GPIO13, GPIO12, GPIO14
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 3: ${switch_3_name}"
|
||||
pin: GPIO14
|
||||
id: Relay_3
|
||||
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# Subscribe to fan speed state and mirror it to relay indicator pattern
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
- topic: "${mqtt_local_status_topic}"
|
||||
|
||||
+124
-92
@@ -1,73 +1,99 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 3 LIGHTSWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: BEDROOM 3 LIGHTSWITCH
|
||||
# zorruno.com layout v1.0 2026
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# V3.5 2025-07-24 YAML tidyups
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
# Device Naming
|
||||
device_name: "esp-bedrm3lights"
|
||||
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)"
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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_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
|
||||
|
||||
# Passwords & Secrets
|
||||
# Passwords and Secrets
|
||||
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
|
||||
static_ip_address: !secret esp-bedrm3lights_ip
|
||||
mqtt_local_command_main_topic: !secret mqtt_command_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
|
||||
#relay_icon: "mdi:lightbulb-group"
|
||||
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_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"
|
||||
|
||||
# Remote Light
|
||||
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_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_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
|
||||
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -76,6 +102,7 @@ packages:
|
||||
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
|
||||
@@ -89,76 +116,80 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
comment: "${description_comment}" # Appears on the ESPHome page in HA
|
||||
area: "${device_area}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
#on_boot:
|
||||
#on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
#########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
level: "${log_level}" # INFO suggested, or DEBUG for testing
|
||||
#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
|
||||
#tx_buffer_size: 64
|
||||
|
||||
#GLobals
|
||||
|
||||
#:########################################################################################:#
|
||||
# GLOBAL VARIABLES:
|
||||
# https://esphome.io/guides/automations.html#global-variables
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
- id: btn1_last_ms
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
initial_value: '0'
|
||||
restore_value: false
|
||||
initial_value: "0"
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
# Buttons for KS-811-2 are GPIO16, GPIO5
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: button_1
|
||||
@@ -166,15 +197,15 @@ binary_sensor:
|
||||
number: GPIO16
|
||||
mode:
|
||||
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
|
||||
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}"
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
on_press:
|
||||
# cooldown: 250 ms between publishes
|
||||
# Cooldown: 250ms between publishes
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
@@ -202,25 +233,26 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.turn_off: Relay_2
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
qos: 0
|
||||
retain: false
|
||||
topic: "${mqtt_remote_device_command_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
qos: 0
|
||||
retain: false
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic2}"
|
||||
payload: "${mqtt_remote_device_command_0}"
|
||||
qos: 0
|
||||
retain: false
|
||||
topic: "${mqtt_remote_device_command_topic2}"
|
||||
payload: "${mqtt_remote_device_command_0}"
|
||||
qos: 0
|
||||
retain: false
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
# Relays for KS-811-2 are GPIO13, GPIO12 (no load connected; used as indicators)
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
@@ -232,19 +264,19 @@ switch:
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
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}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
|
||||
- topic: "${mqtt_remote_status_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
||||
- switch.turn_off: Relay_1
|
||||
+206
-188
@@ -1,19 +1,28 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Title: BREAKFAST BAR LEDS (Lounge)
|
||||
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-loungebookshelfleds.yaml
|
||||
#
|
||||
# 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)
|
||||
#:########################################################################################:#
|
||||
# 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-breakfastbarleds.yaml
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
#
|
||||
# ------------------------------------------
|
||||
# OPERATION (as of v2.0)
|
||||
# ------------------------------------------
|
||||
# 1. General-purpose LED controller.
|
||||
# DEVICE GPIO (Magichome ESP8266)
|
||||
# - GPIO02 Blue LED (used for ESPHome status) - I think... can't see the board
|
||||
# - GPIO12 MOSFET output (0 V when switched)
|
||||
#:########################################################################################:#
|
||||
# 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.
|
||||
# 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
|
||||
# 3. (SUBSTITUTIONS) setting for MAX % output to extend LED life (e.g. ensure it is only ever 95%)
|
||||
# 4. (SUBSTITUTIONS) Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
|
||||
# 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).
|
||||
# 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.
|
||||
@@ -32,42 +41,57 @@
|
||||
# - Normal On/Off switch (quick ramp up/down, up to the level of previous brightness)
|
||||
# - 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.
|
||||
# - 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: 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)
|
||||
# ------------------------------------------
|
||||
# GPIO02 Blue LED (used for ESPHome status) - I think... can't see the board
|
||||
# GPIO12 MOSFET output (0 V when switched)
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT COMMANDS:
|
||||
# Local MQTT light control:
|
||||
# - ${mqtt_local_command_topic}/light/set -> ON,OFF
|
||||
#
|
||||
# Local MQTT light status:
|
||||
# - ${mqtt_local_status_topic}/light/state -> ON,OFF
|
||||
#:########################################################################################:#
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-breakfastbarleds" # yaml file should be device_name.yaml
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Magichome Single Colour V1.1 LED Controller.Generic ESP8266" # 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_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
|
||||
|
||||
# Passwords & Secrets (Unfortunately, you can't use substitutions inside secret names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-breakfastbarleds_ip # CHANGE THIS
|
||||
|
||||
# MQTT LOCAL Controls (This is just my local method of controlling via MQTT, I also use the built in method)
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-breakfastbarleds_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 (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_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_local_status_main_topic: !secret mqtt_status_main_topic
|
||||
@@ -77,24 +101,24 @@ substitutions:
|
||||
mqtt_local_device_command_OFF: "OFF"
|
||||
|
||||
# Device Specific Settings
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
|
||||
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
|
||||
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
|
||||
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
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
# Device Specific GPIO (so we can easily update for other devices)
|
||||
device_status_led: GPIO02
|
||||
device_status_led: GPIO02
|
||||
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_fading_led: GPIO13 # if no LED, 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
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -103,6 +127,7 @@ packages:
|
||||
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
|
||||
@@ -116,22 +141,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
#common_sntp: !include common/sntp_common.yaml
|
||||
#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
|
||||
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 CORE CONFIGURATION
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -179,25 +205,11 @@ esphome:
|
||||
# Boot complete: allow OFF handlers again
|
||||
- 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/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
@@ -208,118 +220,128 @@ mdns:
|
||||
preferences:
|
||||
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
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
# Minimum Brightness % for LEDs (will switch off if <=)
|
||||
- id: min_brightness_pct
|
||||
type: int
|
||||
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)
|
||||
- id: max_brightness_pct
|
||||
type: int
|
||||
restore_value: false
|
||||
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
|
||||
initial_value: "${maximum_led_output}"
|
||||
|
||||
# The maximum time the lights will stay on, in hours. 0 = forever
|
||||
- id: max_on_hours
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${max_on_default_hours}"
|
||||
|
||||
# Compile time Gamma
|
||||
- id: led_gamma_f
|
||||
type: float
|
||||
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)
|
||||
- id: ramp_up_ms # fade-in when turned ON
|
||||
- id: ramp_up_ms
|
||||
type: int
|
||||
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
|
||||
- id: ramp_down_ms
|
||||
type: int
|
||||
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)
|
||||
- id: restart_mode
|
||||
- id: restart_mode
|
||||
type: int
|
||||
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.
|
||||
# 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
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
# Prevent jitter when adjusting the slider
|
||||
- id: suppress_slider_sync
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
# actual 0..100 seen last time, for restart
|
||||
- id: last_brightness_pct
|
||||
initial_value: "false"
|
||||
|
||||
# Actual 0..100 seen last time, for restart
|
||||
- id: last_brightness_pct
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
# last published "Output Set (0-100)" integer
|
||||
initial_value: "0.0"
|
||||
|
||||
# Last published "Output Set (0-100)" integer
|
||||
- id: last_set_pos
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
# helper to keep blink time == transition time
|
||||
initial_value: "-1"
|
||||
|
||||
# Helper to keep blink time == transition time
|
||||
- id: last_ramp_ms
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
# target for "Restore Brightness" scripted ramp
|
||||
initial_value: "0"
|
||||
|
||||
# Target for "Restore Brightness" scripted ramp
|
||||
- id: restore_target_pct
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
# true while a scripted ramp is in progress (to limit flash writes)
|
||||
initial_value: "0.0"
|
||||
|
||||
# True while a scripted ramp is in progress (to limit flash writes)
|
||||
- id: is_ramping
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
# guards OFF persistence during startup caused by restore_mode: ALWAYS_OFF
|
||||
initial_value: "false"
|
||||
|
||||
# Guards OFF persistence during startup caused by restore_mode: RESTORE_DEFAULT_OFF
|
||||
- id: booting
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'true'
|
||||
# true only while we are performing a ramp-down that briefly turns the light ON to hit the floor
|
||||
initial_value: "true"
|
||||
|
||||
# True only while we are performing a ramp-down that briefly turns the light ON to hit the floor
|
||||
- id: ramping_for_off
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
##########################################################################################
|
||||
# LOGGER COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LOGGER COMPONENT:
|
||||
# https://esphome.io/components/logger.html
|
||||
# Logs all log messages through the serial port and through MQTT topics.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
level: "${log_level}"
|
||||
baud_rate: 0 # set to 0 for no logging via UART
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: ${device_status_led}
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
#:########################################################################################:#
|
||||
# MQTT:
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control to ramp up
|
||||
@@ -327,16 +349,17 @@ mqtt:
|
||||
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
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
# Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce)
|
||||
- platform: template
|
||||
@@ -356,10 +379,10 @@ switch:
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
#:########################################################################################:#
|
||||
# BUTTON COMPONENT:
|
||||
# https://esphome.io/components/button/index.html
|
||||
#################################################################################################
|
||||
#:########################################################################################:#
|
||||
button:
|
||||
# Start ramping UP (from current level)
|
||||
- platform: template
|
||||
@@ -369,7 +392,7 @@ button:
|
||||
on_press:
|
||||
- lambda: |-
|
||||
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.execute: ramp_on_script
|
||||
|
||||
@@ -381,7 +404,7 @@ button:
|
||||
on_press:
|
||||
- lambda: |-
|
||||
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.execute: ramp_off_script
|
||||
|
||||
@@ -391,7 +414,6 @@ button:
|
||||
name: "${friendly_name} Fade Stop"
|
||||
icon: mdi:pause
|
||||
on_press:
|
||||
# Stop any pending scripts (and their delayed actions)
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
- lambda: |-
|
||||
@@ -399,7 +421,7 @@ button:
|
||||
id(ramping_for_off) = 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;
|
||||
if (cv.is_on()) {
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
@@ -415,12 +437,10 @@ button:
|
||||
id(last_brightness_pct) = pct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#########################################################################################
|
||||
# SELECT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SELECT COMPONENT:
|
||||
# https://esphome.io/components/select/index.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
id: restart_action
|
||||
@@ -442,10 +462,10 @@ select:
|
||||
id(restart_mode) = 2;
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: btn_gpio12
|
||||
@@ -467,21 +487,21 @@ binary_sensor:
|
||||
# Target is currently ON -> press should go OFF (start ramp-down)
|
||||
- lambda: |-
|
||||
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.execute: ramp_off_script
|
||||
else:
|
||||
# Target is currently OFF -> press should go ON (start ramp-up)
|
||||
- lambda: |-
|
||||
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.execute: ramp_on_script
|
||||
|
||||
##########################################################################################
|
||||
# SENSOR COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SENSOR COMPONENT:
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
- platform: template
|
||||
id: mosfet_output_pct
|
||||
@@ -489,7 +509,7 @@ sensor:
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:percent
|
||||
accuracy_decimals: 0
|
||||
update_interval: 2s # consider 200ms if you want fewer updates
|
||||
update_interval: 2s
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
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;
|
||||
return pwm * 100.0f;
|
||||
|
||||
##########################################################################################
|
||||
# OUTPUT COMPONENT
|
||||
# https://esphome.io/components/light/index.html
|
||||
##########################################################################################
|
||||
# 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 COMPONENT:
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: mosfet_pwm
|
||||
pin: ${device_mosfet_out}
|
||||
frequency: ${pwm_frequency}
|
||||
|
||||
- platform: gpio
|
||||
id: green_led_out # Green LED
|
||||
id: green_led_out # Green LED
|
||||
pin:
|
||||
number: ${device_fading_led}
|
||||
inverted: false
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LIGHT COMPONENT:
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: monochromatic
|
||||
id: mosfet_leds
|
||||
@@ -582,7 +600,7 @@ light:
|
||||
- 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.
|
||||
# Guarded by booting flag so the automatic OFF at boot from RESTORE_DEFAULT_OFF does not zero persistence.
|
||||
on_turn_off:
|
||||
- output.turn_off: green_led_out
|
||||
- if:
|
||||
@@ -607,18 +625,17 @@ light:
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (!cv.is_on()) return;
|
||||
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();
|
||||
call.set_state(true);
|
||||
call.set_brightness(cap);
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# NUMBER COMPONENT
|
||||
#:########################################################################################:#
|
||||
# NUMBER COMPONENT:
|
||||
# https://esphome.io/components/number/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
number:
|
||||
- platform: template
|
||||
id: cfg_ramp_up_s
|
||||
@@ -668,24 +685,22 @@ number:
|
||||
min_value: 0
|
||||
max_value: 100
|
||||
step: 1
|
||||
# Show current position mapped into 0..100 across [min..max]
|
||||
lambda: |-
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0
|
||||
if (actual <= 0.0f) return 0.0f; // when OFF, show 0
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
if (actual <= 0.0f) return 0.0f;
|
||||
float pos = (actual - minp) * 100.0f / (maxp - minp);
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
return floorf(pos + 0.5f); // integer
|
||||
return floorf(pos + 0.5f);
|
||||
set_action:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return x <= 0.0f;'
|
||||
then:
|
||||
# 0 means OFF
|
||||
- lambda: 'id(suppress_slider_sync) = true;'
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
@@ -695,16 +710,15 @@ number:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
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;
|
||||
- delay: 400ms
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
else:
|
||||
# Map 1..100 - [min..max] and set ON
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync) = true;
|
||||
float pos = x; // 0..100
|
||||
if (pos < 1.0f) pos = 1.0f; // 0 is OFF
|
||||
float pos = x;
|
||||
if (pos < 1.0f) pos = 1.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f));
|
||||
- script.stop: ramp_off_script
|
||||
@@ -712,7 +726,7 @@ number:
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
@@ -722,13 +736,13 @@ number:
|
||||
transition_length: 250ms
|
||||
- lambda: |-
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float out_pct = minp + (pos * (maxp - minp) / 100.0f);
|
||||
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
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
|
||||
@@ -762,19 +776,18 @@ number:
|
||||
then:
|
||||
- script.execute: max_on_watchdog
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SCRIPT COMPONENT:
|
||||
# https://esphome.io/components/script.html
|
||||
# Scripts can be executed nearly anywhere in your device configuration with a single call.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
|
||||
# Script: ramp up from current level. Obey global max. (LED ON while ramping)
|
||||
# Script: ramp up from current level. Obey global max.
|
||||
- id: ramp_on_script
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: 'id(is_ramping) = true;'
|
||||
- script.stop: ramp_off_script
|
||||
|
||||
# Ensure we start at at least the floor without a visible "pop".
|
||||
- if:
|
||||
condition:
|
||||
@@ -787,6 +800,7 @@ script:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: 80ms
|
||||
|
||||
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
@@ -810,21 +824,23 @@ script:
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- lambda: |-
|
||||
id(is_ramping) = false;
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
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
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: 'id(is_ramping) = true;'
|
||||
- script.stop: ramp_off_script
|
||||
|
||||
# Ensure we start at the floor cleanly.
|
||||
- if:
|
||||
condition:
|
||||
@@ -837,6 +853,7 @@ script:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: 80ms
|
||||
|
||||
# Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms.
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
@@ -866,17 +883,17 @@ script:
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- lambda: |-
|
||||
id(is_ramping) = false;
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
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)
|
||||
# Script: ramp down from current level to floor, then cleanly cut to OFF.
|
||||
- id: ramp_off_script
|
||||
mode: restart
|
||||
then:
|
||||
@@ -884,6 +901,7 @@ script:
|
||||
id(is_ramping) = true;
|
||||
id(ramping_for_off) = true;
|
||||
- script.stop: ramp_on_script
|
||||
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
@@ -899,6 +917,7 @@ script:
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
id(last_ramp_ms) = (int) (id(ramp_down_ms) * frac);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
@@ -907,7 +926,7 @@ script:
|
||||
- lambda: |-
|
||||
id(is_ramping) = 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(led_output_set_pct).publish_state(0);
|
||||
|
||||
@@ -933,7 +952,7 @@ script:
|
||||
- id: deferred_restore_brightness
|
||||
mode: restart
|
||||
then:
|
||||
- delay: 5s # let preferences/globals load and light settle
|
||||
- delay: 5s # let preferences/globals load and light settle
|
||||
- lambda: |-
|
||||
// Use ONLY the exact last saved brightness.
|
||||
float target = id(last_brightness_pct);
|
||||
@@ -951,7 +970,7 @@ script:
|
||||
lambda: 'return id(restore_target_pct) > 0.5f;'
|
||||
then:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = true; // reflect our intent
|
||||
id(ramp_switch_target_on) = true;
|
||||
id(suppress_slider_sync) = true;
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_to_target_script
|
||||
@@ -962,5 +981,4 @@ script:
|
||||
- lambda: 'id(ramp_switch_target_on) = false;'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
transition_length: 0s
|
||||
# (Removed: output.turn_off: green_led_out) # make sure LED is off if no ramp
|
||||
transition_length: 0s
|
||||
@@ -1,67 +1,98 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CENTRAL STAIRS - BOTTOM LIGHTSWITCH
|
||||
# V3.7 2025-09-24 upload to this device
|
||||
#:########################################################################################:#
|
||||
# TITLE: CENTRAL STAIRS - BOTTOM LIGHTSWITCH
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# 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
|
||||
# - Light switch at top of the stairs, only the footer lights physically connected.
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Remote device 2 (Stair Footer Lights):
|
||||
# - 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Custom Naming
|
||||
device_name: "esp-centralstairs-bottom"
|
||||
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.
|
||||
|
||||
# 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
|
||||
|
||||
# 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_2: "stair-footerlights"
|
||||
|
||||
# I/O Naming
|
||||
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
|
||||
#relay_1_name: "Garage Lights"
|
||||
#button_1_name: "Power Button"
|
||||
#relay_icon: "mdi:lightbulb-group"
|
||||
|
||||
# Project Naming
|
||||
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_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
|
||||
|
||||
# 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_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_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_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
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -70,6 +101,7 @@ packages:
|
||||
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
|
||||
@@ -83,23 +115,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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_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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -108,39 +140,39 @@ esphome:
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
#on_boot:
|
||||
#on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
#########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#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.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_connect:
|
||||
then:
|
||||
- if:
|
||||
# Status of relay 1, which has an actual light connected
|
||||
condition:
|
||||
lambda: 'return id(Relay_1).state;'
|
||||
then:
|
||||
@@ -199,26 +231,26 @@ mqtt:
|
||||
then:
|
||||
- switch.turn_off: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
@@ -230,7 +262,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
@@ -251,10 +283,10 @@ binary_sensor:
|
||||
payload: "${mqtt_command_ON}"
|
||||
retain: false
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
@@ -275,4 +307,4 @@ switch:
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
# No mqtt.publish here (this is a mirror only)
|
||||
# No mqtt.publish here (this is a mirror only)
|
||||
@@ -1,67 +1,99 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CENTRAL STAIRS - TOP LIGHTSWITCH
|
||||
# V3.7 2025-09-24 upload to this device
|
||||
#:########################################################################################:#
|
||||
# TITLE: CENTRAL STAIRS - TOP LIGHTSWITCH
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#:########################################################################################:#
|
||||
# HARDWARE:
|
||||
# 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
|
||||
# - Light switch at top of the stairs
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Remote device 2 (Stair Footer Lights):
|
||||
# - 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Custom Naming
|
||||
device_name: "esp-centralstairs-top"
|
||||
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.
|
||||
|
||||
# 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
|
||||
|
||||
# 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_2: "stair-footerlights"
|
||||
|
||||
# I/O Naming
|
||||
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
|
||||
#relay_1_name: "Garage Lights"
|
||||
#button_1_name: "Power Button"
|
||||
#relay_icon: "mdi:lightbulb-group"
|
||||
|
||||
# Project Naming
|
||||
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_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
|
||||
|
||||
# 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_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_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_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
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -70,6 +102,7 @@ packages:
|
||||
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
|
||||
@@ -83,23 +116,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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_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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -108,39 +141,39 @@ esphome:
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
#on_boot:
|
||||
#on_boot:
|
||||
# priority: 200
|
||||
# then:
|
||||
# - switch.turn_on: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
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
|
||||
|
||||
#########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#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.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_connect:
|
||||
then:
|
||||
- if:
|
||||
# Status of relay 1, which has an actual light connected
|
||||
condition:
|
||||
lambda: 'return id(Relay_2).state;'
|
||||
then:
|
||||
@@ -199,32 +232,32 @@ mqtt:
|
||||
then:
|
||||
- switch.turn_off: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: yes
|
||||
inverted: true
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
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:
|
||||
condition:
|
||||
lambda: 'return id(Relay_1).state;'
|
||||
@@ -243,7 +276,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
@@ -251,10 +284,10 @@ binary_sensor:
|
||||
on_press:
|
||||
- switch.toggle: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
@@ -275,6 +308,4 @@ switch:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_status_topic_2}"
|
||||
payload: "${mqtt_command_OFF}"
|
||||
retain: false
|
||||
|
||||
|
||||
retain: false
|
||||
@@ -1,43 +1,69 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DATA CUPBOARD FAN CONTROL
|
||||
# Fan control for Data Cupboard
|
||||
#
|
||||
# Hardware: Yunshan 7-30V 10A Relay Board (HW-622) with ESP8266MOD
|
||||
#
|
||||
#:########################################################################################:#
|
||||
# TITLE: DATA CUPBOARD FAN CONTROL
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# 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.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.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).
|
||||
# - 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.
|
||||
# - 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:
|
||||
# Device Naming
|
||||
device_name: "esp-datacupboardfans"
|
||||
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"
|
||||
|
||||
# Project Naming
|
||||
project_name: "Yunshan.HW-622 ESP8266MOD Relay Board"
|
||||
project_version: "v1.3"
|
||||
|
||||
# Passwords
|
||||
# Passwords and Secrets (Unfortunately, you cannot use substitutions inside secret names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-datacupboardfans_ip
|
||||
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_device_name: "data-cupboard-fans"
|
||||
mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}"
|
||||
@@ -67,9 +93,10 @@ substitutions:
|
||||
default_temp_on: "35"
|
||||
default_temp_off: "28"
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
##########################################################################################
|
||||
# https://esphome.io/components/packages.html
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -78,6 +105,7 @@ packages:
|
||||
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 ####
|
||||
common_api: !include
|
||||
@@ -99,9 +127,10 @@ packages:
|
||||
diag_basic: !include common/include_basic_diag_sensors.yaml
|
||||
diag_more: !include common/include_more_diag_sensors.yaml
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -120,9 +149,11 @@ esphome:
|
||||
- script.execute: apply_fan_control
|
||||
- script.execute: evaluate_fan_fault
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp12e
|
||||
restore_from_flash: true
|
||||
@@ -133,75 +164,87 @@ preferences:
|
||||
mdns:
|
||||
disabled: false
|
||||
|
||||
##########################################################################################
|
||||
# LOGGING
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LOGGING:
|
||||
# https://esphome.io/components/logger.html
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}"
|
||||
baud_rate: 0
|
||||
|
||||
##########################################################################################
|
||||
# GLOBALS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# GLOBAL VARIABLES:
|
||||
# https://esphome.io/components/globals.html
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
# Max temperature tracking
|
||||
- id: g_max_temp_today
|
||||
type: float
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "-1000.0"
|
||||
|
||||
- id: g_max_temp_yesterday
|
||||
type: float
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "-1000.0"
|
||||
|
||||
- id: g_max_temp_month
|
||||
type: float
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "-1000.0"
|
||||
|
||||
- id: g_max_temp_last_month
|
||||
type: float
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "-1000.0"
|
||||
|
||||
- id: g_max_temp_year
|
||||
type: float
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "-1000.0"
|
||||
|
||||
# Last seen date parts (for rollover)
|
||||
- id: g_last_day
|
||||
type: int
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
- id: g_last_month
|
||||
type: int
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
- id: g_last_year
|
||||
type: int
|
||||
restore_value: yes
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
# Fault evaluation grace timing
|
||||
- id: boot_ms
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
initial_value: "0"
|
||||
- id: relay_last_change_ms
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
restore_value: false
|
||||
initial_value: "0"
|
||||
|
||||
##########################################################################################
|
||||
# INTERVAL (periodic evaluations)
|
||||
- id: relay_last_change_ms
|
||||
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.
|
||||
##########################################################################################
|
||||
interval:
|
||||
- interval: 5s
|
||||
then:
|
||||
- script.execute: evaluate_fan_fault
|
||||
|
||||
##########################################################################################
|
||||
# SWITCHES (Relay + Override)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SWITCHES:
|
||||
# https://esphome.io/components/switch/
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
# Relay output (GPIO4) - powers both fans
|
||||
- platform: gpio
|
||||
@@ -239,9 +282,11 @@ switch:
|
||||
- script.execute: apply_fan_control
|
||||
- script.execute: evaluate_fan_fault
|
||||
|
||||
##########################################################################################
|
||||
# NUMBERS (On/Off thresholds with hysteresis)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# NUMBERS:
|
||||
# https://esphome.io/components/number/
|
||||
#:########################################################################################:#
|
||||
# On/Off thresholds with hysteresis
|
||||
number:
|
||||
- platform: template
|
||||
name: "Fans On Temperature"
|
||||
@@ -275,9 +320,10 @@ number:
|
||||
set_action:
|
||||
- script.execute: apply_fan_control
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS (Door + Fault)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
# Door status on GPIO5
|
||||
- platform: gpio
|
||||
@@ -298,17 +344,19 @@ binary_sensor:
|
||||
id: fan_fault
|
||||
device_class: problem
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED (GPIO2)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# SENSORS (Temp/Humidity + Fan RPM + Max temp templates)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SENSORS:
|
||||
# https://esphome.io/components/sensor/
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
# DHT22 on GPIO0
|
||||
- platform: dht
|
||||
@@ -419,19 +467,22 @@ sensor:
|
||||
lambda: |-
|
||||
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).
|
||||
##########################################################################################
|
||||
text_sensor:
|
||||
- platform: template
|
||||
name: "${fan_status_name}"
|
||||
id: fan_status
|
||||
icon: "mdi:fan-alert"
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPTS
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# SCRIPTS:
|
||||
# https://esphome.io/components/script.html
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
# Apply fan control logic (override + hysteresis thresholds)
|
||||
- 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};
|
||||
|
||||
// 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);
|
||||
|
||||
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_year).publish_state(id(g_max_temp_year));
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS (device-specific)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT (DEVICE-SPECIFIC COMMAND SUBSCRIPTIONS):
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Relay control
|
||||
|
||||
@@ -1,24 +1,43 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DATA CUPBOARD POWER MONITOR - LEFT
|
||||
#
|
||||
# Controlled by a Athom Smart Plug V2 No Relay
|
||||
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml
|
||||
#
|
||||
#:########################################################################################:#
|
||||
# TITLE: DATA CUPBOARD POWER MONITOR - LEFT
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# 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
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-datacupboardpower-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"
|
||||
|
||||
# Project Naming
|
||||
@@ -30,20 +49,22 @@ substitutions:
|
||||
ota_pass: !secret esp-ota_pass
|
||||
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
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# Device Specific Settings (Athom Power Monitor Plug V2)
|
||||
sensor_update_interval: "10s"
|
||||
hide_energy_sensor: "true" # boolean (used by "internal:")
|
||||
hide_energy_sensor: "true" # boolean (used by "internal:")
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -52,6 +73,7 @@ packages:
|
||||
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
|
||||
@@ -65,21 +87,20 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
|
||||
# Device Specific included packages
|
||||
# Athom Power Monitor Plug V2 (No Relay)
|
||||
#### DEVICE SPECIFIC: Athom Power Monitor Plug V2 (No Relay) ####
|
||||
common_athompowermonV2: !include
|
||||
file: common/athompowermonv2norelay_common.yaml
|
||||
vars:
|
||||
@@ -87,10 +108,10 @@ packages:
|
||||
sensor_update_interval: "${sensor_update_interval}"
|
||||
hide_energy_sensor: "${hide_energy_sensor}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -102,10 +123,10 @@ esphome:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp8285
|
||||
restore_from_flash: true
|
||||
@@ -117,11 +138,10 @@ preferences:
|
||||
mdns:
|
||||
disabled: false
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome LOGGING
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}"
|
||||
baud_rate: 0 # free UART for CSE7766
|
||||
|
||||
baud_rate: 0 # free UART for CSE7766
|
||||
@@ -1,50 +1,71 @@
|
||||
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DATA CUPBOARD POWER MONITOR - RIGHT
|
||||
#
|
||||
# Controlled by a Athom Smart Plug V2 No Relay
|
||||
# https://github.com/athom-tech/athom-configs/blob/main/athom-without-relay-plug.yaml
|
||||
#
|
||||
#:########################################################################################:#
|
||||
# TITLE: DATA CUPBOARD POWER MONITOR - RIGHT
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-datacupboardpower-right.yaml
|
||||
#:########################################################################################:#
|
||||
# VERSIONS:
|
||||
# V1.1 2026-02-25 Updated yaml to zorruno layout V1.1
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-datacupboardpower-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"
|
||||
|
||||
# Project Naming
|
||||
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)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
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
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG, VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# Device Specific Settings (Athom Power Monitor Plug V2)
|
||||
sensor_update_interval: "10s"
|
||||
hide_energy_sensor: "true" # boolean (used by "internal:")
|
||||
hide_energy_sensor: "true" # boolean (used by "internal:")
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -53,6 +74,7 @@ packages:
|
||||
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
|
||||
@@ -66,21 +88,20 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
|
||||
# Device Specific included packages
|
||||
# Athom Power Monitor Plug V2 (No Relay)
|
||||
#### DEVICE SPECIFIC: Athom Power Monitor Plug V2 (No Relay) ####
|
||||
common_athompowermonV2: !include
|
||||
file: common/athompowermonv2norelay_common.yaml
|
||||
vars:
|
||||
@@ -88,10 +109,10 @@ packages:
|
||||
sensor_update_interval: "${sensor_update_interval}"
|
||||
hide_energy_sensor: "${hide_energy_sensor}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -103,10 +124,10 @@ esphome:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp8285
|
||||
restore_from_flash: true
|
||||
@@ -118,10 +139,10 @@ preferences:
|
||||
mdns:
|
||||
disabled: false
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome LOGGING
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}"
|
||||
baud_rate: 0 # free UART for CSE7766
|
||||
baud_rate: 0 # free UART for CSE7766
|
||||
@@ -1,55 +1,83 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOWNSTAIRS DISHWASHER POWER MONITOR
|
||||
#
|
||||
# Controlled by a Athom Smart Plug V1
|
||||
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml
|
||||
#
|
||||
#:########################################################################################:#
|
||||
# TITLE: DOWNSTAIRS DISHWASHER POWER MONITOR
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# REPO:
|
||||
# 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.2 2025-06-15 Changed to Athom V1
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-downstdishwasher"
|
||||
friendly_name: "Downstairs Dishwasher Power"
|
||||
description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V2"
|
||||
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
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.
|
||||
|
||||
# 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
|
||||
project_name: "Athom Technology.Smart Plug V2"
|
||||
project_version: "v1.4"
|
||||
|
||||
# Passwords (unfortunately you can't use substitutions inside secrets names)
|
||||
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
|
||||
|
||||
# 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
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# Device Specific Settings
|
||||
# Athom Power Monitor Plug V2
|
||||
relay_icon: "mdi:power-socket-au"
|
||||
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
||||
relay_icon: "mdi:power-socket-au"
|
||||
current_limit: "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
||||
sensor_update_interval: "10s"
|
||||
relay_restore_mode: RESTORE_DEFAULT_ON
|
||||
hide_energy_sensor: "true"
|
||||
|
||||
##########################################################################################
|
||||
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -58,6 +86,7 @@ packages:
|
||||
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
|
||||
@@ -71,18 +100,18 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
|
||||
# Device Specific included packages
|
||||
# Athom Power Monitor Plug
|
||||
@@ -96,15 +125,16 @@ packages:
|
||||
power_plug_type: "${relay_icon}"
|
||||
hide_energy_sensor: "${hide_energy_sensor}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
|
||||
#:########################################################################################:#
|
||||
# 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}"
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
name_add_mac_suffix: false
|
||||
min_version: 2024.6.0
|
||||
project:
|
||||
@@ -116,27 +146,27 @@ esphome:
|
||||
- select.set_index:
|
||||
id: power_mode
|
||||
index: !lambda |-
|
||||
return id(restore_mode)-1;
|
||||
return id(restore_mode) - 1;
|
||||
- lambda: |-
|
||||
switch(id(restore_mode))
|
||||
{
|
||||
case 1:{
|
||||
id(relay).turn_off();
|
||||
break;
|
||||
}
|
||||
case 2:{
|
||||
id(relay).turn_on();
|
||||
break;
|
||||
}
|
||||
default:{
|
||||
break;
|
||||
}
|
||||
switch (id(restore_mode)) {
|
||||
case 1: {
|
||||
id(relay).turn_off();
|
||||
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:
|
||||
board: esp8285
|
||||
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
|
||||
@@ -148,18 +178,20 @@ preferences:
|
||||
mdns:
|
||||
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
|
||||
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# 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:
|
||||
# 0 = Always_Off. 1 = Restore_Power_Off. 2 = Always_On.
|
||||
- id: restore_mode
|
||||
@@ -167,14 +199,15 @@ globals:
|
||||
restore_value: yes
|
||||
initial_value: "2"
|
||||
|
||||
##########################################################################################
|
||||
# SELECT COMPONENT
|
||||
|
||||
#:########################################################################################:#
|
||||
# SELECT COMPONENT:
|
||||
# https://esphome.io/components/select/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
name: "Power On State"
|
||||
id: "power_mode"
|
||||
id: power_mode
|
||||
optimistic: true
|
||||
icon: mdi:electric-switch
|
||||
options:
|
||||
@@ -184,4 +217,4 @@ select:
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
id(restore_mode)=i+1;
|
||||
id(restore_mode) = i + 1;
|
||||
@@ -1,83 +1,111 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Title: DOWNSTAIRS KITCHEN - OVER PANTRY LEDS
|
||||
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstairskitchleds.yaml
|
||||
#:########################################################################################:#
|
||||
# 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
|
||||
#:########################################################################################:#
|
||||
# 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.
|
||||
# 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)
|
||||
# - 3D-printed case for Sinilink XY-WFMS
|
||||
# https://cults3d.com/en/3d-model/tool/snapfit-enclosure-for-esp8266-sinilink-xy-wfms-5v-36v-mosfet-switch-module
|
||||
#
|
||||
# ------------------------------------------
|
||||
# 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)
|
||||
# ------------------------------------------
|
||||
# GPIO02 Blue LED, active-low (used for ESPHome status)
|
||||
# GPIO04 MOSFET output (0V when switched) and Red LED
|
||||
# GPIO12 Toggle button
|
||||
# GPIO13 Green LED (used to display fading status)
|
||||
# - GPIO02 Blue LED, active-low (used for ESPHome status)
|
||||
# - GPIO04 MOSFET output (0V when switched) and Red LED
|
||||
# - GPIO12 Toggle button
|
||||
# - 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
|
||||
# https://cults3d.com/en/3d-model/tool/snapfit-enclosure-for-esp8266-sinilink-xy-wfms-5v-36v-mosfet-switch-module
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# - Status topic:
|
||||
# ${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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-downstairskitchleds" # yaml file should be device_name.yaml
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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_name: "Sinilink.XY-WFMS" # Project details. Manufacturer before the dot, device after the dot.
|
||||
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
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-downstairskitchleds_ip # CHANGE THIS
|
||||
|
||||
ota_pass: !secret esp-ota_pass
|
||||
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_device_name: "downstairskitchen-pantryleds"
|
||||
mqtt_local_command_main_topic: !secret mqtt_command_main_topic
|
||||
@@ -88,24 +116,24 @@ substitutions:
|
||||
mqtt_local_device_command_OFF: "OFF"
|
||||
|
||||
# Device Specific Settings
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
|
||||
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
|
||||
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
|
||||
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
|
||||
log_level: "NONE" # NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
|
||||
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
|
||||
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
|
||||
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
|
||||
|
||||
# Device Specific GPIO (so we can easily update for other devices)
|
||||
device_status_led: GPIO02
|
||||
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_fading_led: GPIO13 # if no LED, 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
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -114,6 +142,7 @@ packages:
|
||||
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
|
||||
@@ -127,22 +156,23 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
#common_sntp: !include common/sntp_common.yaml
|
||||
#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
|
||||
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 CORE CONFIGURATION
|
||||
#:########################################################################################:#
|
||||
# ESPHOME: Core Configuration
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -190,25 +220,10 @@ esphome:
|
||||
# Boot complete: allow OFF handlers again
|
||||
- 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
|
||||
# https://esphome.io/components/esp8266.html
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
@@ -219,118 +234,127 @@ mdns:
|
||||
preferences:
|
||||
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
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
# Minimum Brightness % for LEDs (will switch off if <=)
|
||||
- id: min_brightness_pct
|
||||
type: int
|
||||
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)
|
||||
- id: max_brightness_pct
|
||||
type: int
|
||||
restore_value: false
|
||||
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
|
||||
initial_value: "${maximum_led_output}" # hard cap; never exceed this
|
||||
|
||||
# The maximum time the lights will stay on, in hours. 0 = forever
|
||||
- id: max_on_hours
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${max_on_default_hours}"
|
||||
|
||||
# Compile time Gamma
|
||||
- id: led_gamma_f
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: ${led_gamma} # <-- numeric at compile time
|
||||
initial_value: ${led_gamma}
|
||||
|
||||
# Default Fading Up Time (Selectable and will be retained)
|
||||
- id: ramp_up_ms # fade-in when turned ON
|
||||
- id: ramp_up_ms
|
||||
type: int
|
||||
restore_value: true
|
||||
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)
|
||||
initial_value: "5000" # 5 s
|
||||
|
||||
# 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)
|
||||
# Default Fading Down Time (Selectable and will be retained)
|
||||
- id: ramp_down_ms
|
||||
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
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
# Prevent jitter when adjusting the slider
|
||||
- id: suppress_slider_sync
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
# actual 0..100 seen last time, for restart
|
||||
- id: last_brightness_pct
|
||||
initial_value: "false"
|
||||
|
||||
# actual 0..100 seen last time, for restart
|
||||
- id: last_brightness_pct
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
# last published "Output Set (0-100)" integer
|
||||
- id: last_set_pos
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
# helper to keep blink time == transition time
|
||||
initial_value: "-1"
|
||||
|
||||
# helper to keep blink time == transition time
|
||||
- id: last_ramp_ms
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
initial_value: "0"
|
||||
|
||||
# target for "Restore Brightness" scripted ramp
|
||||
- id: restore_target_pct
|
||||
type: float
|
||||
restore_value: false
|
||||
initial_value: '0.0'
|
||||
initial_value: "0.0"
|
||||
|
||||
# true while a scripted ramp is in progress (to limit flash writes)
|
||||
- id: is_ramping
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
# guards OFF persistence during startup caused by restore_mode: ALWAYS_OFF
|
||||
- id: booting
|
||||
type: bool
|
||||
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
|
||||
- id: ramping_for_off
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
initial_value: "false"
|
||||
|
||||
##########################################################################################
|
||||
# LOGGER COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LOGGING
|
||||
# https://esphome.io/components/logger.html
|
||||
# Logs all log messages through the serial port and through MQTT topics.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
level: "${log_level}"
|
||||
baud_rate: 0
|
||||
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: ${device_status_led}
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# MQTT: Device-specific command triggers
|
||||
#:########################################################################################:#
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control to ramp up
|
||||
@@ -338,18 +362,19 @@ mqtt:
|
||||
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
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
# Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce)
|
||||
# Ramp-aware ON/OFF for HA (asymmetric; no bounce)
|
||||
- platform: template
|
||||
id: mosfet_ramp_switch
|
||||
name: "${friendly_name} Fade Up-Down"
|
||||
@@ -367,10 +392,10 @@ switch:
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
#:########################################################################################:#
|
||||
# BUTTON
|
||||
# https://esphome.io/components/button/index.html
|
||||
#################################################################################################
|
||||
#:########################################################################################:#
|
||||
button:
|
||||
# Start ramping UP (from current level)
|
||||
- platform: template
|
||||
@@ -402,15 +427,12 @@ button:
|
||||
name: "${friendly_name} Fade Stop"
|
||||
icon: mdi:pause
|
||||
on_press:
|
||||
# Stop any pending scripts (and their delayed actions)
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
- lambda: |-
|
||||
// We are no longer ramping (up or down)
|
||||
id(ramping_for_off) = false;
|
||||
id(is_ramping) = false;
|
||||
|
||||
// Freeze the light at its *current* level by overwriting the transition
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
@@ -420,18 +442,15 @@ button:
|
||||
call.perform();
|
||||
}
|
||||
|
||||
// Persist the exact frozen level so restore survives a reboot
|
||||
if (cv.is_on()) {
|
||||
float pct = cv.get_brightness() * 100.0f;
|
||||
id(last_brightness_pct) = pct;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#########################################################################################
|
||||
# SELECT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SELECT
|
||||
# https://esphome.io/components/select/index.html
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
select:
|
||||
- platform: template
|
||||
id: restart_action
|
||||
@@ -453,10 +472,10 @@ select:
|
||||
id(restart_mode) = 2;
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSOR
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: btn_gpio12
|
||||
@@ -475,24 +494,22 @@ binary_sensor:
|
||||
condition:
|
||||
lambda: 'return id(ramp_switch_target_on);'
|
||||
then:
|
||||
# Target is currently ON -> press should go OFF (start ramp-down)
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
else:
|
||||
# Target is currently OFF -> press should go ON (start ramp-up)
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = true;
|
||||
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_on_script
|
||||
|
||||
##########################################################################################
|
||||
# SENSOR COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SENSOR
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
sensor:
|
||||
- platform: template
|
||||
id: mosfet_output_pct
|
||||
@@ -500,17 +517,15 @@ sensor:
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:percent
|
||||
accuracy_decimals: 0
|
||||
update_interval: 2s # consider 200ms if you want fewer updates
|
||||
update_interval: 2s
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
return cv.is_on() ? (float) (int)(cv.get_brightness() * 100.0f + 0.5f) : 0.0f;
|
||||
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
// If not suppressing sync, update the 0..100 slider only when its INT changes
|
||||
if (!id(suppress_slider_sync)) {
|
||||
float actual = x; // x is current Output (%)
|
||||
float actual = x;
|
||||
float minp = (float) id(min_brightness_pct);
|
||||
float maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
@@ -541,28 +556,26 @@ sensor:
|
||||
if (pwm > 1.0f) pwm = 1.0f;
|
||||
return pwm * 100.0f;
|
||||
|
||||
##########################################################################################
|
||||
# OUTPUT COMPONENT
|
||||
# https://esphome.io/components/light/index.html
|
||||
##########################################################################################
|
||||
# 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
|
||||
# https://esphome.io/components/output/
|
||||
#:########################################################################################:#
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: mosfet_pwm
|
||||
pin: ${device_mosfet_out}
|
||||
frequency: ${pwm_frequency}
|
||||
|
||||
- platform: gpio
|
||||
id: green_led_out # Green LED
|
||||
id: green_led_out
|
||||
pin:
|
||||
number: ${device_fading_led}
|
||||
inverted: false
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# LIGHT
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
light:
|
||||
- platform: monochromatic
|
||||
id: mosfet_leds
|
||||
@@ -573,7 +586,6 @@ light:
|
||||
icon: mdi:led-strip-variant
|
||||
gamma_correct: "${led_gamma}"
|
||||
|
||||
# ON: publish state, track intent, arm watchdog if configured
|
||||
on_turn_on:
|
||||
- output.turn_on: green_led_out
|
||||
- mqtt.publish:
|
||||
@@ -581,7 +593,6 @@ light:
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
retain: true
|
||||
- lambda: |-
|
||||
// Do not flip "intent to ON" when we're inside an OFF ramp's floor-kick
|
||||
if (!id(ramping_for_off)) {
|
||||
id(ramp_switch_target_on) = true;
|
||||
}
|
||||
@@ -592,8 +603,6 @@ light:
|
||||
then:
|
||||
- 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:
|
||||
- output.turn_off: green_led_out
|
||||
- if:
|
||||
@@ -611,31 +620,29 @@ light:
|
||||
id(last_set_pos) = 0;
|
||||
id(led_output_set_pct).publish_state(0);
|
||||
|
||||
# Cap brightness to max_brightness_pct without a visible step
|
||||
on_state:
|
||||
- lambda: |-
|
||||
const float cap = id(max_brightness_pct) / 100.0f;
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (!cv.is_on()) return;
|
||||
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();
|
||||
call.set_state(true);
|
||||
call.set_brightness(cap);
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# NUMBER COMPONENT
|
||||
#:########################################################################################:#
|
||||
# NUMBER
|
||||
# https://esphome.io/components/number/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
number:
|
||||
- platform: template
|
||||
id: cfg_ramp_up_s
|
||||
name: "${friendly_name} Fade Up Time (s)"
|
||||
entity_category: config
|
||||
unit_of_measurement: s
|
||||
unit_of_measurement: "s"
|
||||
icon: mdi:timer-sand
|
||||
mode: slider
|
||||
min_value: 0
|
||||
@@ -655,7 +662,7 @@ number:
|
||||
id: cfg_ramp_down_s
|
||||
name: "${friendly_name} Fade Down Time (s)"
|
||||
entity_category: config
|
||||
unit_of_measurement: s
|
||||
unit_of_measurement: "s"
|
||||
icon: mdi:timer-sand-complete
|
||||
mode: slider
|
||||
min_value: 0
|
||||
@@ -679,24 +686,22 @@ number:
|
||||
min_value: 0
|
||||
max_value: 100
|
||||
step: 1
|
||||
# Show current position mapped into 0..100 across [min..max]
|
||||
lambda: |-
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0
|
||||
if (actual <= 0.0f) return 0.0f; // when OFF, show 0
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
if (actual <= 0.0f) return 0.0f;
|
||||
float pos = (actual - minp) * 100.0f / (maxp - minp);
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
return floorf(pos + 0.5f); // integer
|
||||
return floorf(pos + 0.5f);
|
||||
set_action:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return x <= 0.0f;'
|
||||
then:
|
||||
# 0 means OFF
|
||||
- lambda: 'id(suppress_slider_sync) = true;'
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
@@ -706,16 +711,15 @@ number:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
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;
|
||||
- delay: 400ms
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
else:
|
||||
# Map 1..100 - [min..max] and set ON
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync) = true;
|
||||
float pos = x; // 0..100
|
||||
if (pos < 1.0f) pos = 1.0f; // 0 is OFF
|
||||
float pos = x;
|
||||
if (pos < 1.0f) pos = 1.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f));
|
||||
- script.stop: ramp_off_script
|
||||
@@ -723,7 +727,7 @@ number:
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
@@ -733,13 +737,13 @@ number:
|
||||
transition_length: 250ms
|
||||
- lambda: |-
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float out_pct = minp + (pos * (maxp - minp) / 100.0f);
|
||||
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
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
|
||||
@@ -747,7 +751,7 @@ number:
|
||||
id: cfg_max_on_hours
|
||||
name: "${friendly_name} Max On (h)"
|
||||
entity_category: config
|
||||
unit_of_measurement: h
|
||||
unit_of_measurement: "h"
|
||||
icon: mdi:timer-cog
|
||||
mode: slider
|
||||
min_value: 0
|
||||
@@ -758,7 +762,7 @@ number:
|
||||
set_action:
|
||||
- lambda: |-
|
||||
int hrs = (int) x;
|
||||
if (hrs < 0) hrs = 0;
|
||||
if (hrs < 0) hrs = 0;
|
||||
if (hrs > 48) hrs = 48;
|
||||
id(max_on_hours) = hrs;
|
||||
id(cfg_max_on_hours).publish_state((float) hrs);
|
||||
@@ -773,20 +777,16 @@ number:
|
||||
then:
|
||||
- script.execute: max_on_watchdog
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPT COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SCRIPT
|
||||
# https://esphome.io/components/script.html
|
||||
# Scripts can be executed nearly anywhere in your device configuration with a single call.
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
script:
|
||||
|
||||
# Script: ramp up from current level. Obey global max. (LED ON while ramping)
|
||||
- id: ramp_on_script
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: 'id(is_ramping) = true;'
|
||||
- script.stop: ramp_off_script
|
||||
# Ensure we start at at least the floor without a visible "pop".
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
@@ -798,7 +798,6 @@ script:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: 80ms
|
||||
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(max_brightness_pct) / 100.0f;'
|
||||
@@ -814,7 +813,7 @@ script:
|
||||
id(last_ramp_ms) = id(ramp_up_ms);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
}
|
||||
if (curr > cap) curr = cap;
|
||||
if (curr > cap) curr = cap;
|
||||
if (curr < floor) curr = floor;
|
||||
float frac = (cap - curr) / (cap - floor);
|
||||
if (frac < 0.0f) frac = 0.0f;
|
||||
@@ -827,16 +826,14 @@ script:
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
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
|
||||
mode: restart
|
||||
then:
|
||||
- lambda: 'id(is_ramping) = true;'
|
||||
- script.stop: ramp_off_script
|
||||
# Ensure we start at the floor cleanly.
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
@@ -848,7 +845,6 @@ script:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: 80ms
|
||||
# Ramp from current (>= floor) to restore_target_pct over a fraction of ramp_up_ms.
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda |-
|
||||
@@ -870,7 +866,7 @@ script:
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
}
|
||||
|
||||
if (curr > cap) curr = cap;
|
||||
if (curr > cap) curr = cap;
|
||||
if (curr < floor) curr = floor;
|
||||
float frac = (cap - curr) / (cap - floor);
|
||||
if (frac < 0.0f) frac = 0.0f;
|
||||
@@ -883,11 +879,9 @@ script:
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
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
|
||||
mode: restart
|
||||
then:
|
||||
@@ -918,7 +912,7 @@ script:
|
||||
- lambda: |-
|
||||
id(is_ramping) = 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(led_output_set_pct).publish_state(0);
|
||||
|
||||
@@ -940,20 +934,17 @@ script:
|
||||
- script.stop: ramp_on_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
|
||||
mode: restart
|
||||
then:
|
||||
- delay: 5s # let preferences/globals load and light settle
|
||||
- delay: 5s
|
||||
- lambda: |-
|
||||
// Use ONLY the exact last saved brightness.
|
||||
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 maxp = (float) id(max_brightness_pct);
|
||||
if (target > 0.0f && target < minp) target = minp;
|
||||
if (target > maxp) target = maxp;
|
||||
if (target > maxp) target = maxp;
|
||||
|
||||
id(restore_target_pct) = target;
|
||||
|
||||
@@ -962,16 +953,14 @@ script:
|
||||
lambda: 'return id(restore_target_pct) > 0.5f;'
|
||||
then:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = true; // reflect our intent
|
||||
id(suppress_slider_sync) = true;
|
||||
id(ramp_switch_target_on) = true;
|
||||
id(suppress_slider_sync) = true;
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_to_target_script
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
else:
|
||||
# Exact last was 0 -> remain OFF
|
||||
- lambda: 'id(ramp_switch_target_on) = false;'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
transition_length: 0s
|
||||
# (Removed: output.turn_off: green_led_out) # make sure LED is off if no ramp
|
||||
transition_length: 0s
|
||||
@@ -1,53 +1,77 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOWNSTAIRS BATHROOM MAIN LIGHTSWITCH
|
||||
#:########################################################################################:#
|
||||
# TITLE: 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
|
||||
# V1.0 2025-02-14 Initial Version
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Triple push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# NOTES
|
||||
# -
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# 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:
|
||||
# - 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-downstbathswitch"
|
||||
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)"
|
||||
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
|
||||
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.
|
||||
|
||||
# Passwords
|
||||
api_key: !secret esp-downstbathswitch_api_key # unfortunately you can't use substitutions inside secrets names
|
||||
ota_pass: !secret esp-downstbathswitch_ota_pass # unfortunately you can't use substitutions inside secrets names
|
||||
# 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 (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
|
||||
|
||||
# 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
|
||||
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_1_name: "Main Lights"
|
||||
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
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -56,6 +80,7 @@ packages:
|
||||
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
|
||||
@@ -69,65 +94,70 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
common_sntp: !include common/sntp_common.yaml
|
||||
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
|
||||
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
|
||||
#:########################################################################################:#
|
||||
# ESPHOME:
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" #Appears on the esphome page in HA
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
#baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
#:########################################################################################:#
|
||||
# STATUS LED:
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: True
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
#:########################################################################################:#
|
||||
# BINARY SENSORS:
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
use_interrupt: false # This pin doesn't support interrupts so use polling. Only supresses a warning.
|
||||
inverted: true
|
||||
use_interrupt: false # GPIO16 does not support interrupts so use polling (suppresses warning).
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_1
|
||||
@@ -136,7 +166,7 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_2
|
||||
@@ -145,10 +175,10 @@ binary_sensor:
|
||||
pin:
|
||||
number: GPIO4
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
inverted: true
|
||||
name: "Button 3: ${switch_3_name}"
|
||||
on_multi_click:
|
||||
# Single click: 1 press → relay on for 5 minutes
|
||||
# Single click: 1 press -> relay on for 5 minutes
|
||||
- timing:
|
||||
- ON for at most 0.5s
|
||||
- OFF for at least 0.5s
|
||||
@@ -163,7 +193,7 @@ binary_sensor:
|
||||
- delay: 5min
|
||||
- switch.turn_off: Relay_3
|
||||
|
||||
# Double click: 2 presses → relay on for 30 minutes
|
||||
# Double click: 2 presses -> relay on for 30 minutes
|
||||
- timing:
|
||||
- ON for at most 0.5s
|
||||
- OFF for at most 0.5s
|
||||
@@ -180,7 +210,7 @@ binary_sensor:
|
||||
- delay: 30min
|
||||
- switch.turn_off: Relay_3
|
||||
|
||||
# Triple click: 3 presses → relay on for 4 hours
|
||||
# Triple click: 3 presses -> relay on for 4 hours
|
||||
- timing:
|
||||
- ON for at most 0.5s
|
||||
- OFF for at most 0.5s
|
||||
@@ -199,7 +229,7 @@ binary_sensor:
|
||||
- delay: 4h
|
||||
- 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:
|
||||
- ON for at least 2s
|
||||
then:
|
||||
@@ -211,22 +241,22 @@ binary_sensor:
|
||||
else:
|
||||
- switch.turn_on: Relay_3
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 3: ${switch_3_name}"
|
||||
pin: GPIO14
|
||||
id: Relay_3
|
||||
|
||||
|
||||
id: Relay_3
|
||||
@@ -1,15 +1,22 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOWNSTAIRS BATHROOM HEATED TOWEL RAIL
|
||||
# Controlled by a Sonoff Basic
|
||||
#
|
||||
#:########################################################################################:#
|
||||
# TITLE: DOWNSTAIRS BATHROOM HEATED TOWEL RAIL
|
||||
# zorruno.com layout v1.1 2026
|
||||
#:########################################################################################:#
|
||||
# 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.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
|
||||
# V2.0 2025-06-05 YAML Tidyups
|
||||
# V1.1 2025-04-12 Fixes to timers and offline modes
|
||||
# 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
|
||||
# - 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)
|
||||
@@ -17,55 +24,68 @@
|
||||
# - 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)
|
||||
# - 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
|
||||
# - 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
|
||||
# - 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 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)
|
||||
# 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/evening-on/09:00 : Time device will go on
|
||||
# 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/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)
|
||||
#:########################################################################################:#
|
||||
# MQTT COMMANDS:
|
||||
# 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)
|
||||
# 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/evening-on/09:00 : Time device will go on
|
||||
# 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/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:
|
||||
# 0 = OFF
|
||||
# 1 = ON
|
||||
# 2 = TIMER
|
||||
# 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)
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-downstbathtowelrail"
|
||||
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.
|
||||
|
||||
# Project Naming
|
||||
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
|
||||
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
|
||||
# Passwords (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-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
|
||||
relay_icon: "mdi:heating-coil"
|
||||
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
@@ -73,18 +93,16 @@ substitutions:
|
||||
|
||||
# Timer Settings
|
||||
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
|
||||
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
|
||||
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
|
||||
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_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_off_default: "1320" # Default in minutes from midnight. Default 22:00 => 1320
|
||||
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/packages.html
|
||||
##########################################################################################
|
||||
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
packages:
|
||||
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
|
||||
common_wifi: !include
|
||||
@@ -93,6 +111,7 @@ packages:
|
||||
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
|
||||
@@ -111,31 +130,34 @@ packages:
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
|
||||
#### 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 ####
|
||||
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_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
|
||||
#:########################################################################################:#
|
||||
# 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}"
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
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
|
||||
- "-Os" # optimize for size
|
||||
- "-Wl,--gc-sections" # drop unused code/data
|
||||
#- "-fno-exceptions" # strip C++ exceptions
|
||||
#- "-fno-rtti" # strip C++ RTTI
|
||||
on_boot:
|
||||
priority: 900 # High priority to run after globals are initialized
|
||||
priority: 900 # High priority to run after globals are initialized
|
||||
then:
|
||||
# This evaluates if we switch on 4+ times in 20 seconds
|
||||
# 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)
|
||||
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
|
||||
# https://esphome.io/components/esp32.html
|
||||
#############################################
|
||||
#:########################################################################################:#
|
||||
# ESP PLATFORM AND FRAMEWORK:
|
||||
# https://esphome.io/components/esp8266/
|
||||
# https://esphome.io/components/esp32/
|
||||
#:########################################################################################:#
|
||||
esp8266:
|
||||
board: esp01_1m # The original sonoff basic
|
||||
restore_from_flash: True # restore some values on reboot
|
||||
board: esp01_1m # The original sonoff basic
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min
|
||||
@@ -192,21 +215,21 @@ preferences:
|
||||
mdns:
|
||||
disabled: true
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
#:########################################################################################:#
|
||||
# LOGGING: ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
logger:
|
||||
level: "${log_level}" #INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 #set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
|
||||
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)
|
||||
#esp8266_store_log_strings_in_flash: false
|
||||
#tx_buffer_size: 64
|
||||
|
||||
####################################################
|
||||
# SWITCH COMPONENT
|
||||
#:########################################################################################:#
|
||||
# SWITCH COMPONENT:
|
||||
# https://esphome.io/components/switch/
|
||||
# Relay Switch (Sonoff Basic Relay on GPIO12)
|
||||
####################################################
|
||||
#:########################################################################################:#
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Towel Rail Power"
|
||||
@@ -242,12 +265,11 @@ switch:
|
||||
on_turn_off:
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
##########################################################################################
|
||||
# Global Variables for use in automations etc
|
||||
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# GLOBAL VARIABLES:
|
||||
# https://esphome.io/guides/automations.html#global-variables
|
||||
#:########################################################################################:#
|
||||
globals:
|
||||
|
||||
# Tracks the time (in seconds from midnight) at the previous boot
|
||||
- id: last_boot_time_s
|
||||
type: int
|
||||
@@ -260,31 +282,31 @@ globals:
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
# Morning On time (minutes from midnight),
|
||||
# Morning On time (minutes from midnight)
|
||||
- id: morning_on
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${morning_on_default}"
|
||||
|
||||
# Morning Off time (minutes from midnight),
|
||||
# Morning Off time (minutes from midnight)
|
||||
- id: morning_off
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${morning_off_default}"
|
||||
|
||||
# Evening On time (minutes from midnight),
|
||||
# Evening On time (minutes from midnight)
|
||||
- id: evening_on
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${evening_on_default}"
|
||||
|
||||
# Evening Off time (minutes from midnight),
|
||||
# Evening Off time (minutes from midnight)
|
||||
- id: evening_off
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${evening_off_default}"
|
||||
|
||||
# Boost Duration (minutes),
|
||||
# Boost Duration (minutes)
|
||||
- id: boost_duration
|
||||
type: int
|
||||
restore_value: true
|
||||
@@ -312,18 +334,16 @@ globals:
|
||||
restore_value: false
|
||||
initial_value: "0"
|
||||
|
||||
##########################################################################################
|
||||
# Text Sensors
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
##########################################################################################
|
||||
#:########################################################################################:#
|
||||
# TEXT SENSORS:
|
||||
# https://esphome.io/components/text_sensor/
|
||||
#:########################################################################################:#
|
||||
text_sensor:
|
||||
############################
|
||||
# MQTT Subscriptions
|
||||
############################
|
||||
|
||||
############################
|
||||
# MQTT Subscriptions
|
||||
############################
|
||||
############################
|
||||
# Morning On time => "HH:MM"
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Morning On Time Setting"
|
||||
id: morning_on_topic
|
||||
@@ -340,9 +360,7 @@ text_sensor:
|
||||
ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str());
|
||||
}
|
||||
|
||||
############################
|
||||
# Morning Off time => "HH:MM"
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Morning Off Time Setting"
|
||||
id: morning_off_topic
|
||||
@@ -359,9 +377,7 @@ text_sensor:
|
||||
ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str());
|
||||
}
|
||||
|
||||
############################
|
||||
# Evening On time => "HH:MM"
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Evening On Time Setting"
|
||||
id: evening_on_topic
|
||||
@@ -378,9 +394,7 @@ text_sensor:
|
||||
ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str());
|
||||
}
|
||||
|
||||
############################
|
||||
# Evening Off time => "HH:MM"
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Evening Off Time Setting"
|
||||
id: evening_off_topic
|
||||
@@ -397,9 +411,7 @@ text_sensor:
|
||||
ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str());
|
||||
}
|
||||
|
||||
############################
|
||||
# Boost duration => integer minutes (1-1439)
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Boost Duration"
|
||||
id: boost_time_topic
|
||||
@@ -409,7 +421,6 @@ text_sensor:
|
||||
then:
|
||||
- lambda: |-
|
||||
int v = 0;
|
||||
// Parse as integer
|
||||
if (sscanf(x.c_str(), "%d", &v) == 1 && v >= 1 && v <= 1439) {
|
||||
id(boost_duration) = v;
|
||||
ESP_LOGI("boost_time","Received new Boost Duration: %d mins", v);
|
||||