yaml layout updates to v1.1 and minor fixes

This commit is contained in:
root
2026-03-04 23:41:30 +13:00
parent a8d2927274
commit 2649a33051
10 changed files with 724 additions and 342 deletions
+88 -73
View File
@@ -1,18 +1,23 @@
##########################################################################################
#:########################################################################################:#
# TITLE: MAIN BATHROOM FAN/HEAT COMBO SWITCH
##########################################################################################
# zorruno.com layout v1.1 2026
#:########################################################################################:#
# REPO:
# https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-mainbathfancombo.yaml
#:########################################################################################:#
# VERSIONS:
# V1.6 2026-03-04 Updated yaml to zorruno layout V1.1; adjusted Button 2 click timing for towel rail MQTT reliability
# V1.5 2026-02-23 MQTT numeric timer only applies if fan already ON (does not turn fan ON)
# V1.4 2026-02-23 Add mm:ss countdown text sensor (eg 22:12) + per-second countdown engine
# V1.3 2026-02-23 Add 60-min cap timer + Remaining Minutes sensor (counts down)
# V1.2 2026-02-18 Stop delayed-off countdown when Relay_1 turns OFF
# V1.1 2025-08-26 Minor Changes (MQTT)
# V1.0 2025-06-01 Initial Version
##########################################################################################
#:########################################################################################:#
# HARDWARE:
# Zemismart KS-811 Double Push Button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
##########################################################################################
# - Zemismart KS-811 Double Push Button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#:########################################################################################:#
# OPERATION NOTES:
# a) MQTT Local Usage
# Send ON to ${mqtt_command_main_topic}/${mqtt_local_device_name} and it will turn the fan ON (60 min cap)
@@ -26,32 +31,34 @@
# By default, the fan will be on for 60mins max. Other values can be sent via MQTT/HA
# d) Other device control
# This device can turn on the heated towel rail via MQTT (doubleclick button 2)
##########################################################################################
#:########################################################################################:#
# OFFLINE NOTES:
# a) Home Assistant OFFLINE, but Network and MQTT ONLINE
# - The fan can still be controlled with ON, OFF and given a timer value, via MQTT.
# - The fan can still be controlled with ON, OFF and given a timer value, via MQTT.
# - The Heated towel rail can also be switched on.
# b) HA/MQTT OFFLINE
# With no automation controllers, fan and heater can be controlled on/off with the switches.
# Auto timers cannot be changed, but the fam will be on for 60mins max.
# c) Internet/Wifi OFFLINE
# No further changes, SNTP not required as timing functions do not rely on accurate clock.
##########################################################################################
# - Accurate time is NOT needed (SNTP not required) for core operation (no time-of-day schedules)
#:########################################################################################:#
##########################################################################################
# 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-mainbathfancombo"
friendly_name: "Main Bathroom Fan-Heat Combo Switch (2)"
description_comment: "Main Bathroom Fan/Heat Switch using a Zemismart KS-811 Double Push Button. Extract Fan (1), IR heater (2)"
description_comment: "Main Bathroom Fan/Heat Switch using a Zemismart KS-811 Double Push Button. Extract Fan (1), IR heater (2) (Layout V1.1)"
device_area: "Main Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Zemismart Technologies.KS-811-2 (Double)" # Project Details
project_version: "v1.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
project_version: "v1.6" # 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.
@@ -81,10 +88,11 @@ substitutions:
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}"
mqtt_remote_device1_command1: "BOOST"
##########################################################################################
#:########################################################################################:#
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
#:########################################################################################:#
packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include
@@ -114,20 +122,21 @@ packages:
#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}
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}"
@@ -156,29 +165,32 @@ esphome:
- lambda: |-
id(relay2_forced_relay1) = false;
##########################################################################################
# ESP PLATFORM AND FRAMEWORK
#:########################################################################################:#
# ESP PLATFORM AND FRAMEWORK:
# https://esphome.io/components/esp32.html
##########################################################################################
#:########################################################################################:#
esp8266:
board: esp01_1m
early_pin_init: false # Recommended false where switches are involved.
board_flash_mode: dout # Default is dout
##########################################################################################
# LOGGING
#:########################################################################################:#
# LOGGING:
# https://esphome.io/components/logger.html
##########################################################################################
#:########################################################################################:#
logger:
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
#baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
##########################################################################################
# GLOBAL VARIABLES
#:########################################################################################:#
# GLOBAL VARIABLES:
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
##########################################################################################
#:########################################################################################:#
globals:
# Tracks if Relay_2 forced Relay_1 ON (so we can decide if Relay_1 should turn OFF when Relay_2 turns OFF)
- id: relay2_forced_relay1
@@ -213,20 +225,21 @@ globals:
restore_value: no
initial_value: "0"
##########################################################################################
# STATUS LED
#:########################################################################################:#
# STATUS LED:
# https://esphome.io/components/status_led.html
##########################################################################################
#:########################################################################################:#
# Status LED for KS-811 is gpio2
##########################################################################################
status_led:
pin:
number: GPIO2
inverted: yes
##########################################################################################
# SENSORS
##########################################################################################
#:########################################################################################:#
# SENSORS:
#:########################################################################################:#
sensor:
- platform: template
name: "${entity_prefix} Fan Remaining Minutes"
@@ -253,10 +266,11 @@ text_sensor:
snprintf(buf, sizeof(buf), "%d:%02d", m, s);
return std::string(buf);
##########################################################################################
# MQTT COMMANDS
#:########################################################################################:#
# MQTT: Device-specific MQTT command triggers
# This adds device-specific MQTT command triggers to the common MQTT configuration.
##########################################################################################
#:########################################################################################:#
mqtt:
on_message:
# Fan control: ON / OFF / 1..60 minutes (timer only if fan already ON)
@@ -307,9 +321,10 @@ mqtt:
ESP_LOGW("mqtt", "Ignoring payload '%s' on %s", p.c_str(), "${mqtt_local_command1_topic}");
}
##########################################################################################
# SCRIPTS
##########################################################################################
#:########################################################################################:#
# SCRIPTS:
#:########################################################################################:#
script:
# Starts/restarts mm:ss countdown, and optionally turns fan ON (used for MQTT ON / auto-start)
- id: relay_1_delayed_off
@@ -344,12 +359,12 @@ script:
then:
- switch.turn_on: Relay_1
##########################################################################################
# BINARY SENSORS
#:########################################################################################:#
# BINARY SENSORS:
# https://esphome.io/components/binary_sensor/
##########################################################################################
#:########################################################################################:#
# Buttons for KS-811-2 are GPIO16, GPIO05
##########################################################################################
binary_sensor:
- platform: gpio
pin:
@@ -359,7 +374,7 @@ binary_sensor:
use_interrupt: false # GPIO16 pin doesn't support interrupts so use polling. Only suppresses a warning.
name: "Button 1: Extract Fan"
on_press:
- switch.toggle: "Relay_1"
- switch.toggle: Relay_1
- platform: gpio
pin:
@@ -372,30 +387,30 @@ binary_sensor:
- delayed_off: 20ms
on_multi_click:
# -- Single click: one quick press & release --
# Double click: easier to hit; also prevents single-click heater toggle from stealing the first click
- timing:
- ON for at most 400ms
- OFF for at least 200ms
then:
- switch.toggle: "Relay_2"
# -- Double click: two quick presses/releases --
- timing:
- ON for at most 400ms
- OFF for at most 400ms
- ON for at most 400ms
- OFF for at least 200ms
- ON for at most 500ms
- OFF for at most 900ms
- ON for at most 500ms
- OFF for at least 250ms
then:
- mqtt.publish:
topic: "${mqtt_remote_device1_command_topic}"
payload: "${mqtt_remote_device1_command1}"
##########################################################################################
# SWITCH COMPONENT
# Single click: delayed recognition so a (slower) double-click still works reliably
- timing:
- ON for at most 600ms
- OFF for at least 1200ms
then:
- switch.toggle: Relay_2
#:########################################################################################:#
# SWITCH COMPONENT:
# https://esphome.io/components/switch/
##########################################################################################
#:########################################################################################:#
# Relays for KS-811-2 are GPIO13, GPIO12
##########################################################################################
switch:
- platform: gpio
name: "Relay 1: Extract Fan"
@@ -478,12 +493,12 @@ switch:
then:
- switch.turn_off: Relay_1
##########################################################################################
# INTERVAL COMPONENT
#:########################################################################################:#
# INTERVAL COMPONENT:
# https://esphome.io/components/interval/
##########################################################################################
#:########################################################################################:#
# Assurance: if Relay_2 (Heater) is ever on, check that Relay_1 (Fan) is on also
##########################################################################################
interval:
- interval: 1s
then: