multiple esphome device updates and new devices

This commit is contained in:
root
2025-07-25 13:14:37 +12:00
parent d9ca44a9ee
commit ac887724a2
39 changed files with 3041 additions and 418 deletions

View File

@@ -14,7 +14,7 @@ substitutions:
#############################################
mqtt:
broker: ${mqtt_server}
topic_prefix: ${mqtt_topic}/${device_name}
topic_prefix: ${mqtt_topic}/${local_device_name}
username: ${mqtt_username}
password: ${mqtt_password}
discovery: False # enable entity discovery (true is default)

View File

@@ -23,7 +23,12 @@ substitutions:
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_dns1
static_ip_dns2: !secret ha_wifi_dns2
# Network reconnect every x hours to ensure best access point
base_interval_hours: "6" # Base interval in hours
random_offset_max_minutes: "59" # Max random offset in minutes
#############################################
# Common Wifi Settings
@@ -45,8 +50,9 @@ wifi:
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
dns2: ${static_ip_dns2}
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${device_name} AP
ssid: ${local_device_name} AP
password: ${fallback_ap_password}
ap_timeout: 10min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
@@ -78,4 +84,37 @@ safe_mode:
# https://esphome.io/components/network.html
#############################################
network:
enable_ipv6: ${ipv6_enable}
enable_ipv6: ${ipv6_enable}
#############################################
# Interval
# Restart Networking every x hours + rand mins
# This ensure that the device is connected to the best AP
#############################################
script:
- id: random_reconnect
mode: restart
then:
- lambda: |-
// Compute total delay: base hours + random offset minutes
uint32_t extra;
#if defined(ESP32)
// ESP32 (both Arduino & IDF builds) uses esp_random()
extra = esp_random() % (${random_offset_max_minutes} + 1);
#elif defined(ESP8266)
// ESP8266 Arduino core
extra = os_random() % (${random_offset_max_minutes} + 1);
#else
// Fallback to esp_random() on other platforms
extra = esp_random() % (${random_offset_max_minutes} + 1);
#endif
uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
// Delay inside lambda (blocks script execution but OK for reconnect timing)
delay(total_s * 1000);
- logger.log: "network_check: performing reconnect"
- wifi.disable: {}
- delay: 1s
- wifi.enable: {}
- script.execute: random_reconnect

View File

@@ -0,0 +1,126 @@
substitutions:
##############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ".local"
# Automatically add the mac address to the name
# eg so you can use a single firmware for all devices
add_mac_suffix: "false"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_dns1
static_ip_dns2: !secret ha_wifi_dns2
# Network reconnect every x hours to ensure best access point
base_interval_hours: "6" # Base interval in hours
random_offset_max_minutes: "59" # Max random offset in minutes
#############################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
networks:
- ssid: "vega_control_1"
password: "3Kd#vQBP8RDc"
priority: 1.0
- ssid: ${wifi_ssid}
password: ${wifi_password}
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
priority: 0.5
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
dns2: ${static_ip_dns2}
use_address: ${local_static_ip_address} # required when any network uses manual_ip
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${device_name} AP
password: ${fallback_ap_password}
ap_timeout: 10min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:
#############################################
# Network
# global configuration for all types of networks
# https://esphome.io/components/network.html
#############################################
network:
enable_ipv6: ${ipv6_enable}
#############################################
# Interval
# Restart Networking every x hours + rand mins
#############################################
script:
- id: random_reconnect
mode: restart
then:
- lambda: |-
// Compute total delay: base hours + random offset minutes
uint32_t extra;
#if defined(ESP32)
// ESP32 (both Arduino & IDF builds) uses esp_random()
extra = esp_random() % (${random_offset_max_minutes} + 1);
#elif defined(ESP8266)
// ESP8266 Arduino core
extra = os_random() % (${random_offset_max_minutes} + 1);
#else
// Fallback to esp_random() on other platforms
extra = esp_random() % (${random_offset_max_minutes} + 1);
#endif
uint32_t total_s = ${base_interval_hours} * 3600 + extra * 60;
ESP_LOGI("random_reconnect", "Next reconnect in %u seconds", total_s);
// Delay inside lambda (blocks script execution but OK for reconnect timing)
delay(total_s * 1000);
- logger.log: "network_check: performing reconnect"
- wifi.disable: {}
- delay: 1s
- wifi.enable: {}
- script.execute: random_reconnect

View File

@@ -0,0 +1,81 @@
substitutions:
##############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
wifi_ssid: !secret ha_wifi_ssid
wifi_password: !secret ha_wifi_password
fallback_ap_password: !secret fallback_ap_password
# Enables faster network connections, with last connected SSID being connected to and no full scan for SSID being undertaken
wifi_fast_connect: "false"
# Define a domain for this device to use. i.e. iot.home.lan (so device will appear as athom-smart-plug-v2.iot.home.lan in DNS/DHCP logs)
dns_domain: ".local"
# Automatically add the mac address to the name
# eg so you can use a single firmware for all devices
add_mac_suffix: "false"
# Enable or disable the use of IPv6 networking on the device
ipv6_enable: "false"
# Add these if we are giving it a static ip, or remove them in the Wifi section
static_ip_subnet: !secret ha_wifi_subnet
static_ip_gateway: !secret ha_wifi_gateway
static_ip_dns1: !secret ha_wifi_gateway
#############################################
# Common Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
wifi:
ssid: ${wifi_ssid}
password: ${wifi_password}
#enable_rrm: true # (ESP32 only) enable 802.11k Radio Resource Management
#enable_btm: true # (ESP32 only) enable 802.11v BSS Transition Management
#power_save_mode: LIGHT # https://esphome.io/components/wifi.html#wifi-power-save-mode
manual_ip: # optional static IP address
static_ip: ${local_static_ip_address}
gateway: ${static_ip_gateway}
subnet: ${static_ip_subnet}
dns1: ${static_ip_dns1}
ap: # Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
ssid: ${device_name} AP
password: ${fallback_ap_password}
ap_timeout: 10min # Time until it brings up fallback AP. default is 1min
# Allow rapid re-connection to previously connect WiFi SSID, skipping scan of all SSID
fast_connect: "${wifi_fast_connect}"
# Define dns domain / suffix to add to hostname
domain: "${dns_domain}"
#captive_portal: # extra fallback mechanism for when connecting if the configured WiFi fails
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
ota:
- platform: esphome
password: ${local_ota_pass}
version: 2
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
safe_mode:
#############################################
# Network
# global configuration for all types of networks
# https://esphome.io/components/network.html
#############################################
network:
enable_ipv6: ${ipv6_enable}

View File

@@ -1,7 +1,7 @@
#############################################
##########################################################################################
# GENERAL COMMON SENSORS
# https://esphome.io/components/sensor/
#############################################
##########################################################################################
sensor:
- platform: uptime # Uptime for this device in seconds
name: "Uptime (s):"
@@ -22,16 +22,23 @@ sensor:
entity_category: "diagnostic"
device_class: ""
# Only works with esp8266
#- platform: adc
# pin: VCC
# name: "VCC Voltage"
# id: vcc_voltage_sensor
# entity_category: diagnostic
binary_sensor:
- platform: status
name: "Network Status"
icon: mdi:check-network-outline
entity_category: diagnostic
#############################################
##########################################################################################
# Text Sensors
# https://esphome.io/components/text_sensor/index.html
#############################################
##########################################################################################
text_sensor:
######################################################
# General ESPHome Info
@@ -58,9 +65,9 @@ text_sensor:
update_interval: ${local_update_interval}
entity_category: "diagnostic"
######################################################
###################################################################################################
# Creates a sensor of the uptime of the device, in formatted days, hours, minutes and seconds
######################################################
###################################################################################################
# - platform: template
# name: "Uptime (Days)"
# entity_category: diagnostic
@@ -109,6 +116,10 @@ text_sensor:
# }
# icon: mdi:clock-start
##########################################################################################
# BUTTONS
# Diagnostic buttons, activated if needed in HA
##########################################################################################
button:
- platform: safe_mode
name: "Safe Mode Restart:"

View File

@@ -0,0 +1,183 @@
#############################################
#############################################
# 3D PRINTER POWER AND SWITCH
# V1.0 2025-06-29 Initial Version
#############################################
# Sonoff POW R1
# https://devices.esphome.io/devices/Sonoff-POW-R1
#
# NOTES
# -
#
#############################################
#############################################
#############################################
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
substitutions:
device_name: "esp-3dprinterpow" # Reference name for the device in the system.
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
entity_prefix: "Load" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
friendly_name: "3D Printer Power"
description_comment: "3D Printer inline monitor and switch override using a Sonoff Pow R1."
device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
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-3dprinterpow_ip
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
update_interval: "60s" # update time for for general sensors etc
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# 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}"
#on_boot:
#priority: 200
#then:
# - switch.turn_on: "virtual_button"
#############################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
#############################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
#############################################
# 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)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#############################################
# STATUS LED
# https://esphome.io/components/status_led.html
#############################################
#status_led:
# pin:
# number: GPIO2
# inverted: yes
#############################################
# SENSORS
# https://esphome.io/components/binary_sensor/
#############################################
binary_sensor:
- platform: gpio
pin:
number: GPIO00
mode: INPUT_PULLUP
inverted: True
name: Button
on_press:
- switch.toggle: virtual_button
- platform: template
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;
}
sensor:
- platform: hlw8012
sel_pin: 5
cf_pin: 14
cf1_pin: 13
update_interval: 2s
current:
name: ${entity_prefix} Current
voltage:
name: ${entity_prefix} Voltage
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:
- platform: template
name: "Relay"
optimistic: true
id: virtual_button
turn_on_action:
- switch.turn_on: relay
- light.turn_on: led
turn_off_action:
- switch.turn_off: relay
- light.turn_off: led
- platform: gpio
id: relay
pin: GPIO12
#restore_mode: ALWAYS_ON # Or RESTORE_DEFAULT_ON/RESTORE_DEFAULT_OFF
output:
- platform: esp8266_pwm
id: pow_blue_led
pin:
number: GPIO15
inverted: True
light:
- platform: monochromatic
name: Status LED
output: pow_blue_led
id: led

View File

@@ -0,0 +1,381 @@
##########################################################################################
##########################################################################################
# CEILING FAN - BEDROOM 2
# - 3 speed fan using Sonoff IFan02
# - Also, single Light Output
#
# 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
#
##########################################################################################
##########################################################################################
##########################################################################################
# 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.
# 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
api_key: !secret esp-api_key
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_local_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# 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
# 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 REMOTE Controls
# 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:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
##########################################################################################
# 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
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));'
# platformio_options:
# build_flags:
# - "-Os" # optimize for size
# - "-Wl,--gc-sections" # drop unused code/data
# - "-fno-exceptions" # strip C++ exceptaions
# - "-fno-rtti" # strip C++ RTTI
##########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
##########################################################################################
esp8266:
board: esp01_1m # The original sonoff basic
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)
##########################################################################################
# GLOBAL VARIABLES
##########################################################################################
globals:
- id: speed_value
type: int
restore_value: yes
initial_value: '0'
##########################################################################################
# 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
##########################################################################################
# MQTT COMMANDS
# This adds device-specific MQTT command triggers to the common MQTT configuration.
##########################################################################################
mqtt:
on_message:
# Light control
- topic: "${mqtt_local_command_topic}/light/set"
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 (03) + ramp up/down (+ / -)
- topic: "${mqtt_local_command_topic}/speed/set"
then:
# 1) Compute new speed_value based on payload
- lambda: |-
std::string s = x;
int val = id(speed_value);
if (s == "+") {
val++;
} else if (s == "-") {
val--;
} else if (s.size() && isdigit(s[0])) {
val = atoi(s.c_str());
} else {
ESP_LOGE("ifan02", "Invalid speed payload: '%s'", x.c_str());
return;
}
// Clamp between 0 and 3
if (val < 0) val = 0;
if (val > 3) val = 3;
id(speed_value) = val;
# 2) Drive the fan based on the new value
- if:
condition:
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);'
##########################################################################################
# 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)
##########################################################################################
switch:
- platform: gpio
name: "${switch_3_name}"
pin: GPIO4
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
id: fan4sw
restore_mode: RESTORE_DEFAULT_OFF
internal: true
##########################################################################################
# SELECT COMPONENT
# https://esphome.io/components/select/index.html
##########################################################################################
select:
- platform: template
name: "Bedroom 2 Fan Speed"
id: bedroom2_fan_speed_select
options:
- "Off"
- "Low"
- "Medium"
- "High"
update_interval: 1s
lambda: |-
switch (id(speed_value)) {
case 1: return esphome::optional<std::string>("Low");
case 2: return esphome::optional<std::string>("Medium");
case 3: return esphome::optional<std::string>("High");
default: return esphome::optional<std::string>("Off");
}
set_action:
# OFF
- if:
condition:
lambda: 'return x == "Off";'
then:
- lambda: |-
id(speed_value) = 0;
- fan.turn_off: ifan02_fan
# LOW (1)
- if:
condition:
lambda: 'return x == "Low";'
then:
- lambda: |-
id(speed_value) = 1;
- fan.turn_on:
id: ifan02_fan
speed: 1
# MEDIUM (2)
- if:
condition:
lambda: 'return x == "Medium";'
then:
- lambda: |-
id(speed_value) = 2;
- fan.turn_on:
id: ifan02_fan
speed: 2
# HIGH (3)
- if:
condition:
lambda: 'return x == "High";'
then:
- lambda: |-
id(speed_value) = 3;
- fan.turn_on:
id: ifan02_fan
speed: 3
################################################################################
# TEMPLATE OUTPUTS: drive the real relays when the states change
################################################################################
output:
- platform: gpio
pin: GPIO12
id: lightrelay
- platform: template
type: float
id: fan_decode
write_action:
- lambda: |-
if (state < 0.25) {
id(fan2sw).turn_off();
id(fan3sw).turn_off();
id(fan4sw).turn_off();
}
else if (state < 0.5) {
id(fan2sw).turn_on();
id(fan3sw).turn_off();
id(fan4sw).turn_off();
}
else if (state < 0.75) {
id(fan2sw).turn_on();
id(fan3sw).turn_on();
id(fan4sw).turn_off();
}
else {
id(fan2sw).turn_on();
id(fan3sw).turn_off();
id(fan4sw).turn_on();
}
##########################################################################################
# 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:
on_turn_on:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"
payload: "ON"
on_turn_off:
- mqtt.publish:
topic: "${mqtt_local_status_topic}/light/state"
payload: "OFF"
##########################################################################################
# FAN COMPONENT
# https://esphome.io/components/fan/index.html
##########################################################################################
fan:
- platform: speed
output: fan_decode
name: "Fan"
id: ifan02_fan
speed_count: 3
restore_mode: RESTORE_DEFAULT_OFF
# whenever you explicitly set a speed (13):
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:
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 HAs Fan switch):
on_turn_on:
- lambda: |-
// 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);'
- mqtt.publish:
topic: "${mqtt_local_status_topic}/speed/state"
payload: !lambda 'return to_string(id(speed_value));'

View File

@@ -0,0 +1,265 @@
##########################################################################################
##########################################################################################
# BEDROOM 2 FAN SWITCH
#
# 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,+,-
#
##########################################################################################
##########################################################################################
##########################################################################################
# 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.
# 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
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-bedrm2fanswitch_ip
mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_local_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
# MQTT REMOTE Controls
mqtt_remote_device_name: "bedroom2-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
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
##########################################################################################
# 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
# on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_3
##########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
##########################################################################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
##########################################################################################
# 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)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
##########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
##########################################################################################
# Status LED for KS-811 is GPIO02
##########################################################################################
status_led:
pin:
number: GPIO02
inverted: yes
##########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
##########################################################################################
# Buttons for KS-811-3 are GPIO16, GPIO05, GPIO04
##########################################################################################
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT
inverted: True
name: "Button 1: ${switch_1_name}"
on_press:
- mqtt.publish:
topic: "${mqtt_remote_device_command_topic}"
payload: "${mqtt_remote_device_command1}"
- platform: gpio
pin:
number: GPIO05
mode: INPUT
inverted: True
name: "Button 2: ${switch_2_name}"
on_press:
- mqtt.publish:
topic: "${mqtt_remote_device_command_topic}"
payload: "${mqtt_remote_device_command2}"
- platform: gpio
pin:
number: GPIO4
mode: INPUT
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
# 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:
on_message:
- topic: "${mqtt_local_status_topic}"
then:
- lambda: |-
int val = atoi(x.c_str());
ESP_LOGI("fan_switch", "Received requested speed: %d", val);
// Desired states
bool r1 = false;
bool r2 = false;
bool r3 = false;
switch (val) {
case 1:
r3 = true;
break;
case 2:
r2 = true;
r3 = true;
break;
case 3:
r1 = true;
r2 = true;
r3 = true;
break;
case 0:
default:
// all remain false
break;
}
// Only change relays if necessary
if (id(Relay_1).state != r1) {
if (r1) {
id(Relay_1).turn_on();
} else {
id(Relay_1).turn_off();
}
}
if (id(Relay_2).state != r2) {
if (r2) {
id(Relay_2).turn_on();
} else {
id(Relay_2).turn_off();
}
}
if (id(Relay_3).state != r3) {
if (r3) {
id(Relay_3).turn_on();
} else {
id(Relay_3).turn_off();
}
}

View File

@@ -0,0 +1,180 @@
##########################################################################################
##########################################################################################
# LAUNDRY MAIN LIGHTSWITCH
# 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
# -
#
##########################################################################################
##########################################################################################
##########################################################################################
# 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-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.
# 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
# Passwords & 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
# 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
# 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
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#########################################################################################
# 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}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
#########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
#########################################################################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
#########################################################################################
# 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)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
#########################################################################################
status_led:
pin:
number: GPIO2
inverted: yes
#########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
#########################################################################################
binary_sensor:
- platform: gpio
pin:
number: GPIO16
mode: INPUT
inverted: True
name: "Button 1: ${switch_1_name}"
on_press:
- switch.toggle: Relay_1
- platform: gpio
pin:
number: GPIO05
mode: INPUT
inverted: True
name: "Button 2: ${switch_2_name}"
on_press:
- switch.toggle: Relay_2
# KS-811-2 is a double only
# - platform: gpio
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#########################################################################################
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
# KS-811-2 is a double only
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3

View File

@@ -22,7 +22,7 @@ substitutions:
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 Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Zemismart Technologies.KS-811 Triple" # Project Details
@@ -42,24 +42,27 @@ substitutions:
switch_2_name: "Cabinet Light"
switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include

View File

@@ -54,7 +54,7 @@ substitutions:
device_name: "esp-downstbathtowelrail"
friendly_name: "Downstairs Bathroom Towelrail"
description_comment: "Heated Towel Rail, Downstairs Bathroom :: Sonoff Basic"
device_area: "Downstairs Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
@@ -78,24 +78,27 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -122,6 +125,8 @@ esphome:
on_boot:
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.
- lambda: |-
// 1) Figure out the current time in "seconds from midnight"
// using SNTP if available, otherwise current_mins * 60.
@@ -159,6 +164,7 @@ 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
#############################################
# ESP Platform and Framework
@@ -218,31 +224,31 @@ globals:
# Morning On time (minutes from midnight),
- id: morning_on
type: int
restore_value: False
restore_value: true
initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight),
- id: morning_off
type: int
restore_value: False
restore_value: true
initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight),
- id: evening_on
type: int
restore_value: False
restore_value: true
initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight),
- id: evening_off
type: int
restore_value: False
restore_value: true
initial_value: "${evening_off_default}"
# Boost Duration (minutes),
- id: boost_duration
type: int
restore_value: False
restore_value: true
initial_value: "${boost_duration_default}"
####################################################
@@ -254,7 +260,7 @@ globals:
####################################################
- id: operation_mode
type: int
restore_value: false
restore_value: true
initial_value: "2"
####################################################
@@ -446,7 +452,6 @@ text_sensor:
lambda: |-
int hour = id(morning_off) / 60;
int minute = id(morning_off) % 60;
// Increase buffer size to 8 just to be safe
// Increase to 16 for safety
char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
@@ -461,7 +466,6 @@ text_sensor:
lambda: |-
int hour = id(evening_on) / 60;
int minute = id(evening_on) % 60;
// Increase buffer size to 8 just to be safe
// Increase to 16 for safety
char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
@@ -476,7 +480,6 @@ text_sensor:
lambda: |-
int hour = id(evening_off) / 60;
int minute = id(evening_off) % 60;
// Increase buffer size to 8 just to be safe
// Increase to 16 for safety
char buff[16];
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
@@ -584,6 +587,23 @@ button:
id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state
- platform: template
name: "Default timer settings"
id: default_timer_settings_button
icon: "mdi:restore"
on_press:
- lambda: |-
// Restore all timing globals to their YAML defaults
id(morning_on) = ${morning_on_default};
id(morning_off) = ${morning_off_default};
id(evening_on) = ${evening_on_default};
id(evening_off) = ${evening_off_default};
id(boost_duration)= ${boost_duration_default};
// Reset mode to TIMER and clear any running boost
id(operation_mode)= 2;
id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied");
- script.execute: evaluate_relay_state
#################################################################################################
# SELECT COMPONENT

View File

@@ -0,0 +1,186 @@
##########################################################################################
##########################################################################################
# DOWNSTAIRS BEDROOM 1 LIGHTS
# V3.5 2025-07-24 YAML tidyups
##########################################################################################
# Zemismart KS-811 Triple push button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#
# NOTES
# -
#
##########################################################################################
##########################################################################################
##########################################################################################
# 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-downstbedrm1lights"
friendly_name: "Downstairs Bedroom 1 Lightswitch (3)"
description_comment: "Downstairs Bedroom 1 Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Wardrobe Lights (2), Spare (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: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & 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-downstbedrm1lights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# 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
# MQTT LOCAL Controls
#mqtt_device_name: "downst-bedroom2-lights"
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# MQTT REMOTE Controls
# Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights"
switch_2_name: "Wardrobe Lights"
switch_3_name: "Spare"
#########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#########################################################################################
# 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}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
#########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
#########################################################################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
#########################################################################################
# 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)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
#########################################################################################
status_led:
pin:
number: GPIO2
inverted: yes
#########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
#########################################################################################
binary_sensor:
# GPIO16 for KS-811 first button
- platform: gpio
pin:
number: GPIO16
mode: INPUT
inverted: True
name: "Button 1: ${switch_1_name}"
on_press:
- switch.toggle: Relay_1
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple)
- platform: gpio
pin:
number: GPIO05
mode: INPUT
inverted: True
name: "Button 2: ${switch_2_name}"
on_press:
- switch.toggle: Relay_2
# GPIO04 for third button (only for KS-811-3 Triple)
- platform: gpio
pin:
number: GPIO4
mode: INPUT
inverted: True
name: "Button 3: ${switch_3_name}"
on_press:
- switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#########################################################################################
switch:
# GPIO13 for KS-811 first relay
- platform: gpio
name: "Relay 1: ${switch_1_name}"
pin: GPIO13
id: Relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
- platform: gpio
name: "Relay 2: ${switch_2_name}"
pin: GPIO12
id: Relay_2
# GPIO14 for third relay (only for KS-811-3 Triple)
- platform: gpio
name: "Relay 3: ${switch_3_name}"
pin: GPIO14
id: Relay_3

View File

@@ -0,0 +1,187 @@
##########################################################################################
##########################################################################################
# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH
# V3.5 2025-07-24 YAML tidyups
##########################################################################################
# Zemismart KS-811 Single push button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#
# NOTES
# -
#
##########################################################################################
##########################################################################################
##########################################################################################
# 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-downstbedrm2lights"
friendly_name: "Downstairs Bedroom 2 Lightswitch (1)"
description_comment: "Downstairs Bedroom 2 Main Lightswitch using a Zemismart KS-811 Single Push Button. Main Lights (1)"
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 Single" # Project Details
project_version: "v3.5" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & 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-downstbedrm2lights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# 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
# MQTT LOCAL Controls
#mqtt_device_name: "downst-bedroom2-lights"
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# MQTT REMOTE Controls
# Switch/Relay/Button Naming & Icons
#relay_icon: "mdi:lightbulb-group"
switch_1_name: "Main Lights"
#switch_2_name: "Nil"
#switch_3_name: "Nil"
#########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#########################################################################################
# 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}"
#on_boot:
# priority: 200
# then:
# - switch.turn_on: Relay_2
#########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
#########################################################################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
#########################################################################################
# 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)
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
#########################################################################################
status_led:
pin:
number: GPIO2
inverted: yes
#########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
#########################################################################################
binary_sensor:
# GPIO16 for KS-811 first button UNLESS
# it is a single button KS-811 in which case it is GPIO00
- platform: gpio
pin:
number: GPIO00
mode: INPUT
inverted: True
name: "Button 1: ${switch_1_name}"
on_press:
- switch.toggle: Relay_1
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple)
# - platform: gpio
# pin:
# number: GPIO05
# mode: INPUT
# inverted: True
# name: "Button 2: ${switch_2_name}"
# on_press:
# - switch.toggle: Relay_2
# GPIO04 for third button (only for KS-811-3 Triple)
# - platform: gpio
# pin:
# number: GPIO4
# mode: INPUT
# inverted: True
# name: "Button 3: ${switch_3_name}"
# on_press:
# - switch.toggle: Relay_3
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#########################################################################################
switch:
# GPIO13 for KS-811 first button
- platform: gpio
name: "Relay 1: ${switch_1_name}"
pin: GPIO13
id: Relay_1
# GPIO12 for second relay (only for KS-811-2 Double or -3 Triple)
# - platform: gpio
# name: "Relay 2: ${switch_2_name}"
# pin: GPIO12
# id: Relay_2
# GPIO14 for third relay (only for KS-811-3 Triple)
# - platform: gpio
# name: "Relay 3: ${switch_3_name}"
# pin: GPIO14
# id: Relay_3

View File

@@ -20,7 +20,7 @@ substitutions:
device_name: "esp-downstdishwpower"
friendly_name: "Downstairs Dishwasher Power"
description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V1"
device_area: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Athom Technology.Smart Plug V1" # Project Details
@@ -40,19 +40,26 @@ substitutions:
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
##########################################################################################
# PACKAGES
# https://esphome.io/components/esphome.html
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -61,12 +68,6 @@ packages:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
# Web and MQTT Packages
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
# Device Specific included packages
common_athompowermonV1: !include
file: common/athompowermonv1_common.yaml

View File

@@ -22,7 +22,7 @@ substitutions:
device_name: "esp-downstkitchlights"
friendly_name: "Downstairs Kitchen Lightswitch (3)"
description_comment: "Downstairs Kitch Main Lightswitch using a Zemismart KS-811 Triple Push Button. Dining Light (1), Kitchen Light (2), Extract Fan (3)"
device_area: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
device_area: "Downstairs Flat" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Passwords
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
@@ -38,24 +38,27 @@ substitutions:
switch_2_name: "Kitchen Light"
switch_3_name: "Extract Fan" # This is virtual only, no power connected to 3rd relay
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include

View File

@@ -10,7 +10,7 @@
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
substitutions:
devicename: "esp-entbtproxy"
device_name: "esp-entbtproxy"
friendly_name: "Outside Entrance Bluetooth Proxy"
description_comment: "D1 Mini ESP32 outside entranceway with BT Proxy"
api_key: !secret esp-entbtproxy_api_key #unfortunately you can't use substitutions in secrets names
@@ -26,38 +26,41 @@ substitutions:
#
#
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome
# https://esphome.io/components/esphome.html
#############################################
esphome:
name: ${devicename}
name: ${device_name}
friendly_name: ${friendly_name}
comment: ${description_comment} #appears on the esphome page in HA
min_version: 2024.6.0 #

View File

@@ -10,7 +10,7 @@
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
substitutions:
devicename: "esp-entmulti"
device_name: "esp-entmulti"
friendly_name: "Outside Entrance Multisensor"
description_comment: "D1 Mini ESP32 outside entranceway with, mmWave presence, PIR and more"
api_key: !secret esp-entmulti_api_key #unfortunately you can't use substitutions in secrets names
@@ -44,38 +44,41 @@ substitutions:
#web_server_username: !secret web_server_username
#web_server_password: !secret web_server_password
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
common_webportal: !include
file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
# common_sntp: !include
# file: common/sntp_common.yaml
# common_general_sensors: !include
# file: common/sensors_common.yaml
# vars:
# local_friendly_name: ${friendly_name}
# local_update_interval: ${update_interval}
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome
# https://esphome.io/components/esphome.html
#############################################
esphome:
name: ${devicename}
name: ${device_name}
friendly_name: ${friendly_name}
comment: ${description_comment} #appears on the esphome page in HA
min_version: 2024.6.0
@@ -113,80 +116,6 @@ logger:
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#############################################
# Enable the Home Assistant API
# https://esphome.io/components/api.html
#############################################
#api:
# encryption:
# key: ${api_key}
# on_client_connected:
# - esp32_ble_tracker.start_scan:
# continuous: true
# on_client_disconnected:
# - esp32_ble_tracker.stop_scan:
#############################################
# Enable Over the Air Update Capability
# https://esphome.io/components/ota.html?highlight=ota
#############################################
#ota:
# - platform: esphome
# password: ${ota_pass}
#############################################
# Safe Mode
# Safe mode will detect boot loops
# https://esphome.io/components/safe_mode
#############################################
#safe_mode:
#############################################
# Wifi Settings
# https://esphome.io/components/wifi.html
#
# Power Save mode (can reduce wifi reliability)
# NONE (least power saving, Default for ESP8266)
# LIGHT (Default for ESP32)
# HIGH (most power saving)
#############################################
#wifi:
# ssid: ${wifi_ssid}
# password: ${wifi_password}
#power_save_mode: LIGHT #https://esphome.io/components/wifi.html#wifi-power-save-mode
#manual_ip: #optional static IP address
#static_ip: ${static_ip_address}
#gateway: ${static_ip_gateway}
#subnet: ${static_ip_subnet}
# ap: #Details for fallback hotspot in case wifi connection fails https://esphome.io/components/wifi.html#access-point-mode
# ssid: $devicename fallback AP
# password: !secret fallback_ap_password
# ap_timeout: 5min #Time until it brings up fallback AP. default is 1min
#############################################
# Web Portal for display and monitoring
# Turning this off is probably a good idea to save resources.
# https://esphome.io/components/web_server.html
#############################################
#web_server:
# port: 80
# auth:
# username: ${web_server_username} #probably a good idea to secure it
# password: ${web_server_password}
#############################################
# MQTT Monitoring
# https://esphome.io/components/mqtt.html?highlight=mqtt
# MUST also have api enabled if you enable MQTT
#############################################
#mqtt:
# broker: ${mqtt_server}
# topic_prefix: ${mqtt_topic}/${devicename}
# username: ${mqtt_username}
# password: ${mqtt_password}
# discovery: False # enable entity discovery (true is default)
# discover_ip: False # enable device discovery (true is default)
#############################################
# i2c bus
# https://esphome.io/components/i2c.html

View File

@@ -30,31 +30,34 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -30,31 +30,34 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -1,27 +1,27 @@
#############################################
#############################################
##########################################################################################
##########################################################################################
# LAUNDRY MAIN LIGHTSWITCH
# V3.5 2025-07-24 YAML tidyups
# V3.0 2025-06-05 YAML tidyups
# V2.0 2025-06-01 Was initially a 3 button switch, now 2
# V1.0 2025-05-30 Initial Version
#############################################
# Zemismart KS-811 Triple push button
##########################################################################################
# Zemismart KS-811 Double push button
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
#
# NOTES
# -
#
#############################################
#############################################
##########################################################################################
##########################################################################################
#############################################
##########################################################################################
# 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-laundrylights"
friendly_name: "Laundry Main Lightswitch (2)"
description_comment: "Laundry Main Lightswitch using a Zemismart KS-811 Double Push Button. Laundry Lights (1), Laundry Power Signal (2)"
device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
@@ -30,37 +30,50 @@ substitutions:
project_name: "Zemismart Technologies.KS-811 Double" # Project Details
project_version: "v3.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & 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-laundrylights_ip
#mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
#mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# 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 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
# Switch Naming
switch_1_name: "Laundry Lights"
switch_2_name: "Laundry Power Enable" # This is virtual only, no power connected to 3rd relay
#switch_3_name: "Spare"
#switch_3_name: "Fan 3 Relay"
#switch_4_name: "Fan 4 Relay"
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
#########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -69,10 +82,10 @@ packages:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
#########################################################################################
# ESPHome
# https://esphome.io/components/esphome.html
#############################################
#########################################################################################
esphome:
name: "${device_name}"
friendly_name: "${friendly_name}"
@@ -86,16 +99,16 @@ esphome:
then:
- switch.turn_on: Relay_2
#############################################
#########################################################################################
# ESP Platform and Framework
# https://esphome.io/components/esp32.html
#############################################
#########################################################################################
esp8266:
board: esp01_1m
early_pin_init: False # Initialise pins early to known values. Recommended false where switches are involved. Defaults to True.
board_flash_mode: dout # Default is dout
#############################################
#########################################################################################
# ESPHome Logging Enable
# https://esphome.io/components/logger.html
#############################################
@@ -105,19 +118,19 @@ logger:
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
#############################################
#########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
#############################################
#########################################################################################
status_led:
pin:
number: GPIO2
inverted: yes
#############################################
#########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
#############################################
#########################################################################################
binary_sensor:
- platform: gpio
pin:
@@ -147,10 +160,10 @@ binary_sensor:
# on_press:
# - switch.toggle: Relay_3
#############################################
#########################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#############################################
#########################################################################################
switch:
- platform: gpio
name: "Relay 1: ${switch_1_name}"

View File

@@ -30,31 +30,34 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -30,31 +30,34 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
# file: common/mqtt_common.yaml
# common_sntp: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -23,7 +23,7 @@ substitutions:
description_comment: "Main Bathroom Fan/Heat Switch using a Zemismart KS-811 Double Push Button. Extract Fan (1), IR heater (2)"
device_area: "Laundry" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
# Project Naming
project_name: "Zemismart Technologies.KS-811-2 (Double)" # Project Details
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
@@ -45,34 +45,34 @@ substitutions:
mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation"
mqtt_remote_device1_command1: "BOOST"
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
device_name: ${device_name}
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
device_name: ${device_name}
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -30,34 +30,34 @@ substitutions:
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
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
device_name: ${device_name}
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
device_name: ${device_name}
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -39,19 +39,26 @@ substitutions:
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
##########################################################################################
# PACKAGES
# https://esphome.io/components/esphome.html
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -60,12 +67,6 @@ packages:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
# Web and MQTT Packages
#common_webportal: !include
# file: common/webportal_common.yaml
#common_mqtt: !include
# file: common/mqtt_common.yaml
# Device Specific included packages
common_athompowermonV1: !include
file: common/athompowermonv1_common.yaml

View File

@@ -78,24 +78,27 @@ substitutions:
evening_on_default: "1260" # Default in minutes from midnight. Default 21:00 => 1260
evening_off_default: "1439" # Default in minutes from midnight. Default 23:59 => 1439 => 1440 is midnight
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
common_webportal: !include
file: common/webportal_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -122,6 +125,8 @@ esphome:
on_boot:
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.
- lambda: |-
// 1) Figure out the current time in "seconds from midnight"
// using SNTP if available, otherwise current_mins * 60.
@@ -159,6 +164,7 @@ 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
#############################################
# ESP Platform and Framework
@@ -166,7 +172,7 @@ esphome:
#############################################
esp8266:
board: esp01_1m # The original sonoff basic
restore_from_flash: True # restore some values on reboot
restore_from_flash: true # restore some values on reboot
preferences:
flash_write_interval: 5min
@@ -218,31 +224,31 @@ globals:
# Morning On time (minutes from midnight),
- id: morning_on
type: int
restore_value: False
restore_value: true
initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight),
- id: morning_off
type: int
restore_value: False
restore_value: true
initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight),
- id: evening_on
type: int
restore_value: False
restore_value: true
initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight),
- id: evening_off
type: int
restore_value: False
restore_value: true
initial_value: "${evening_off_default}"
# Boost Duration (minutes),
- id: boost_duration
type: int
restore_value: False
restore_value: true
initial_value: "${boost_duration_default}"
####################################################
@@ -254,14 +260,13 @@ globals:
####################################################
- id: operation_mode
type: int
restore_value: false
restore_value: true
initial_value: "2"
####################################################
# current_mins is set if SNTP is invalid.
# We assume user powers on the device at 12:00 noon
# => 12 * 60 = 720 minutes from midnight.
# Not restored, so it resets each boot.
####################################################
- id: current_mins
type: int
@@ -602,6 +607,23 @@ button:
id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state
- platform: template
name: "Default timer settings"
id: default_timer_settings_button
icon: "mdi:restore"
on_press:
- lambda: |-
// Restore all timing globals to their YAML defaults
id(morning_on) = ${morning_on_default};
id(morning_off) = ${morning_off_default};
id(evening_on) = ${evening_on_default};
id(evening_off) = ${evening_off_default};
id(boost_duration)= ${boost_duration_default};
// Reset mode to TIMER and clear any running boost
id(operation_mode)= 2;
id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied");
- script.execute: evaluate_relay_state
#################################################################################################
# SELECT COMPONENT

View File

@@ -47,34 +47,34 @@ substitutions:
update_interval: "60s" # update time for for general sensors etc
room: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
#web_server: !remove
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome

View File

@@ -37,31 +37,34 @@ substitutions:
#
#
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
# common_api: !include
# file: common/api_common.yaml
# vars:
# local_api_key: ${api_key}
# common_webportal: !include
# file: common/webportal_common.yaml
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
file: common/sensors_common.yaml
vars:
local_friendly_name: ${friendly_name}
local_update_interval: ${update_interval}
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
#############################################
# ESPHome
@@ -73,29 +76,35 @@ esphome:
comment: ${description_comment} #appears on the esphome page in HA
min_version: 2024.6.0
area: "${device_area}"
on_boot: #LD1125H Initial Setting, will remember previous values (if set)
priority: -200
then:
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f",id(LD1125H_mth1).state) +"\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f",id(LD1125H_mth2).state) +"\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f",id(LD1125H_mth3).state) +"\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f",id(LD1125H_rmax).state) +"\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
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:
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th1st = "mth1=" + str_sprintf("%.0f", id(LD1125H_mth1).state) + "\r\n";
return std::vector<uint8_t>(th1st.begin(), th1st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th2st = "mth2=" + str_sprintf("%.0f", id(LD1125H_mth2).state) + "\r\n";
return std::vector<uint8_t>(th2st.begin(), th2st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string th3st = "mth3=" + str_sprintf("%.0f", id(LD1125H_mth3).state) + "\r\n";
return std::vector<uint8_t>(th3st.begin(), th3st.end());
- uart.write:
id: LD1125H_UART_BUS
data: !lambda |-
std::string rmaxst = "rmax=" + str_sprintf("%.1f", id(LD1125H_rmax).state) + "\r\n";
return std::vector<uint8_t>(rmaxst.begin(), rmaxst.end());
#############################################
# ESP Platform and Framework

View File

@@ -7,12 +7,15 @@
# Controlled by a Sonoff Dual R1
# A sonoff dual uses serial data to turn the relays on/off
#
# V2.4 - 2025-06-30 Tidied up MQTT direct relay control (esps can control each other via MQTT)
# V2.3 - 2025-06-18 Added MQTT direct relay control
#
# NOTES:
# Command the lights on with MQTT
# ${mqtt_command_topic}/relay2/set ON or OFF
# ${mqtt_command_topic}/relay2/set ON or OFF
# ${mqtt_local_command_full_topic}/relay1/set ON or OFF
# ${mqtt_local_command_full_topic}/relay2/set ON or OFF
# ${mqtt_local_status_full_topic}/relay1/set ON or OFF
# ${mqtt_local_status_full_topic}/relay2/set ON or OFF
#
##########################################################################################
##########################################################################################
@@ -32,10 +35,12 @@ substitutions:
project_name: "Sonoff Technologies.Sonoff Dual R1" # Project Details
project_version: "v2.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords
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-officeduallights_ip
# Passwords & Secrets
api_key: !secret esp-api_key
ota_pass: !secret esp-ota_pass
static_ip_address: !secret esp-officeduallights_ip # unfortunately you can't use substitutions inside secrets names
mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# Device Settings
relay_icon: "mdi:lightbulb-group"
@@ -44,31 +49,38 @@ substitutions:
# MQTT Controls
mqtt_device_name: "office-dual-lights"
mqtt_main_command_topic: !secret mqtt_main_command_topic
mqtt_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external withougt HA
#mqtt_status_topic: "${mqtt_main_status_topic}/esphome/${device_name}" # Topic we will use to read stuff from external withougt HA
#mqtt_main_status_topic: !secret mqtt_main_status_topic
#mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation"
#mqtt_remote_device1_command1: "BOOST"
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# Switch Naming
switch_1_name: "Dual L1 Relay"
relay_1_icon: "mdi:lightbulb"
light_1_name: "Light 1 (Right Hand Bunker Light)"
switch_2_name: "Dual L2 Relay"
relay_2_icon: "mdi:lightbulb"
light_2_name: "Light 2 (Cool White Overhead Lights)"
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/esphome.html
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -139,24 +151,24 @@ mqtt:
# Direct MQTT control for relays via serial commands
on_message:
# Relay 1 control
- topic: "${mqtt_topic}/relay1/set"
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "ON"
then:
- switch.turn_on: relay_1
- light.turn_on: light_1
- topic: "${mqtt_topic}/relay1/set"
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "OFF"
then:
- switch.turn_off: relay_1
- light.turn_off: light_1
# Relay 2 control
- topic: "${mqtt_topic}/relay2/set"
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "ON"
then:
- switch.turn_on: relay_2
- light.turn_on: light_2
- topic: "${mqtt_topic}/relay2/set"
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "OFF"
then:
- switch.turn_off: relay_2
@@ -206,14 +218,14 @@ binary_sensor:
#############################################
switch:
- platform: template
name: "Dual L1 Relay"
name: "${switch_1_name}"
id: relay_1
optimistic: true
icon: "${relay_icon}"
icon: "${relay_1_icon}"
internal: true
turn_on_action:
- mqtt.publish:
topic: "${mqtt_topic}/relay1/state"
topic: "${mqtt_local_status_topic}/relay1/state"
payload: "ON"
- if:
condition:
@@ -224,7 +236,7 @@ switch:
- uart.write: [0xA0, 0x04, 0x03, 0xA1]
turn_off_action:
- mqtt.publish:
topic: "${mqtt_topic}/relay1/state"
topic: "${mqtt_local_status_topic}/relay1/state"
payload: "OFF"
- if:
condition:
@@ -234,14 +246,14 @@ switch:
else:
- uart.write: [0xA0, 0x04, 0x02, 0xA1]
- platform: template
name: "Dual L2 Relay"
name: "${switch_2_name}"
id: relay_2
optimistic: true
icon: "${relay_icon}"
icon: "${relay_2_icon}"
internal: true
turn_on_action:
- mqtt.publish:
topic: "${mqtt_topic}/relay2/state"
topic: "${mqtt_local_status_topic}/relay2/state"
payload: "ON"
- if:
condition:
@@ -252,7 +264,7 @@ switch:
- uart.write: [0xA0, 0x04, 0x03, 0xA1]
turn_off_action:
- mqtt.publish:
topic: "${mqtt_topic}/relay2/state"
topic: "${mqtt_local_status_topic}/relay2/state"
payload: "OFF"
- if:
condition:
@@ -288,7 +300,7 @@ output:
##########################################################################################
light:
- platform: binary
name: "Light 1 (Right Hand Bunker Light)"
name: "${light_1_name}"
id: light_1
output: light_output_1

View File

@@ -44,12 +44,13 @@ substitutions:
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/esphome.html
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
@@ -60,6 +61,8 @@ packages:
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include

View File

@@ -42,24 +42,27 @@ substitutions:
switch_2_name: "Daytime Lights" # This is virtual only, no power connected to 2nd relay
switch_3_name: "Spare" # This is virtual only, no power connected to 3rd relay
#############################################
# Included Common Packages
# https://esphome.io/components/esphome.html
#############################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
# common_webportal: !include
# file: common/webportal_common.yaml
# common_mqtt: !include
# file: common/mqtt_common.yaml
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include

View File

@@ -42,14 +42,15 @@ substitutions:
mqtt_device_name: "office-usbhub-power"
mqtt_main_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA
#########################################################################################
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/esphome.html
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
@@ -60,6 +61,8 @@ packages:
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include

View File

@@ -83,19 +83,26 @@ substitutions:
evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight
##########################################################################################
# Included Common Packages
# https://esphome.io/components/esphome.html
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -104,12 +111,6 @@ packages:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
# Web and MQTT Packages
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
# Device Specific included packages
common_athompowermonV3: !include
file: common/athompowermonv3_common.yaml
@@ -134,6 +135,9 @@ esphome:
board_build.mcu: esp32c3
board_build.variant: esp32c3
board_build.flash_mode: dio
on_boot:
then:
- script.execute: evaluate_relay_state
##########################################################################################
# ESP Platform and Framework
@@ -184,31 +188,31 @@ globals:
# Morning On time (minutes from midnight),
- id: morning_on
type: int
restore_value: False
restore_value: true
initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight),
- id: morning_off
type: int
restore_value: False
restore_value: true
initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight),
- id: evening_on
type: int
restore_value: False
restore_value: true
initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight),
- id: evening_off
type: int
restore_value: False
restore_value: true
initial_value: "${evening_off_default}"
# Boost Duration (minutes),
- id: boost_duration
type: int
restore_value: False
restore_value: true
initial_value: "${boost_duration_default}"
####################################################
@@ -220,28 +224,26 @@ globals:
####################################################
- id: operation_mode
type: int
restore_value: false
restore_value: true
initial_value: "2"
####################################################
# current_mins is set if SNTP is invalid.
# We assume user powers on the device at 12:00 noon
# => 12 * 60 = 720 minutes from midnight.
# Not restored, so it resets each boot.
####################################################
- id: current_mins
type: int
restore_value: false
restore_value: true
initial_value: "720" # 720 is 12:00 Noon
####################################################
# boost_timer: counts minutes in BOOST mode
# After 'boost_duration' minutes, revert to TIMER.
# Not restored, so each boot starts fresh at 0.
####################################################
- id: boost_timer
type: int
restore_value: false
restore_value: true
initial_value: "0"
##########################################################################################
@@ -576,6 +578,23 @@ button:
id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state
- platform: template
name: "Default timer settings"
id: default_timer_settings_button
icon: "mdi:restore"
on_press:
- lambda: |-
// Restore all timing globals to their YAML defaults
id(morning_on) = ${morning_on_default};
id(morning_off) = ${morning_off_default};
id(evening_on) = ${evening_on_default};
id(evening_off) = ${evening_off_default};
id(boost_duration)= ${boost_duration_default};
// Reset mode to TIMER and clear any running boost
id(operation_mode)= 2;
id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied");
- script.execute: evaluate_relay_state
#################################################################################################
# SELECT COMPONENT

View File

@@ -82,19 +82,26 @@ substitutions:
evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight
##########################################################################################
# PACKAGES
# https://esphome.io/components/esphome.html
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
file: common/api_common.yaml
vars:
local_api_key: "${api_key}"
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -103,12 +110,6 @@ packages:
local_friendly_name: "${friendly_name}"
local_update_interval: "${update_interval}"
# Web and MQTT Packages
#common_webportal: !include
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
# Device Specific included packages
common_athompowermonV3: !include
file: common/athompowermonv3_common.yaml
@@ -133,6 +134,9 @@ esphome:
board_build.mcu: esp32c3
board_build.variant: esp32c3
board_build.flash_mode: dio
on_boot:
then:
- script.execute: evaluate_relay_state
##########################################################################################
# ESP Platform and Framework
@@ -183,31 +187,31 @@ globals:
# Morning On time (minutes from midnight),
- id: morning_on
type: int
restore_value: False
restore_value: true
initial_value: "${morning_on_default}"
# Morning Off time (minutes from midnight),
- id: morning_off
type: int
restore_value: False
restore_value: true
initial_value: "${morning_off_default}"
# Evening On time (minutes from midnight),
- id: evening_on
type: int
restore_value: False
restore_value: true
initial_value: "${evening_on_default}"
# Evening Off time (minutes from midnight),
- id: evening_off
type: int
restore_value: False
restore_value: true
initial_value: "${evening_off_default}"
# Boost Duration (minutes),
- id: boost_duration
type: int
restore_value: False
restore_value: true
initial_value: "${boost_duration_default}"
####################################################
@@ -219,14 +223,13 @@ globals:
####################################################
- id: operation_mode
type: int
restore_value: True
restore_value: true
initial_value: "2"
####################################################
# current_mins is set if SNTP is invalid.
# We assume user powers on the device at 12:00 noon
# => 12 * 60 = 720 minutes from midnight.
# Not restored, so it resets each boot.
####################################################
- id: current_mins
type: int
@@ -236,7 +239,6 @@ globals:
####################################################
# boost_timer: counts minutes in BOOST mode
# After 'boost_duration' minutes, revert to TIMER.
# Not restored, so each boot starts fresh at 0.
####################################################
- id: boost_timer
type: int
@@ -575,6 +577,23 @@ button:
id(operation_mode) = 3;
# 2) immediately re-evaluate relay state
- script.execute: evaluate_relay_state
- platform: template
name: "Default timer settings"
id: default_timer_settings_button
icon: "mdi:restore"
on_press:
- lambda: |-
// Restore all timing globals to their YAML defaults
id(morning_on) = ${morning_on_default};
id(morning_off) = ${morning_off_default};
id(evening_on) = ${evening_on_default};
id(evening_off) = ${evening_off_default};
id(boost_duration)= ${boost_duration_default};
// Reset mode to TIMER and clear any running boost
id(operation_mode)= 2;
id(boost_timer) = 0;
ESP_LOGI("timer","Default timer settings applied");
- script.execute: evaluate_relay_state
#################################################################################################
# SELECT COMPONENT

View File

@@ -28,7 +28,8 @@ substitutions:
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-underhouselights_ip
mqtt_main_command_topic: !secret mqtt_main_command_topic
mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
# Device Settings
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
@@ -36,7 +37,8 @@ substitutions:
# MQTT Controls
mqtt_device_name: "underhouse-lights-control"
mqtt_main_topic: "${mqtt_main_command_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# Switch Naming
switch_1_name: "Underhouse Entrance Lights"
@@ -54,12 +56,13 @@ substitutions:
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/esphome.html
# https://esphome.io/components/packages.html
##########################################################################################
packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_device_name: "${device_name}"
local_static_ip_address: "${static_ip_address}"
local_ota_pass: "${ota_pass}"
common_api: !include
@@ -70,6 +73,8 @@ packages:
# file: common/webportal_common.yaml
common_mqtt: !include
file: common/mqtt_common.yaml
vars:
local_device_name: "${device_name}"
common_sntp: !include
file: common/sntp_common.yaml
common_general_sensors: !include
@@ -252,12 +257,40 @@ status_led:
mqtt:
on_message:
# Relay 1 control
- topic: "${mqtt_main_topic}/relay1/set"
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "ON"
then:
- switch.turn_on: relay1
- topic: "${mqtt_main_topic}/relay1/set"
- topic: "${mqtt_local_command_topic}/relay1/set"
payload: "OFF"
then:
- switch.turn_off: relay1
# Relay 2 control
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "ON"
then:
- switch.turn_on: relay2
- topic: "${mqtt_local_command_topic}/relay2/set"
payload: "OFF"
then:
- switch.turn_off: relay2
# Relay 3 control
- topic: "${mqtt_local_command_topic}/relay3/set"
payload: "ON"
then:
- switch.turn_on: relay3
- topic: "${mqtt_local_command_topic}/relay3/set"
payload: "OFF"
then:
- switch.turn_off: relay3
# Relay 4 control
- topic: "${mqtt_local_command_topic}/relay4/set"
payload: "ON"
then:
- switch.turn_on: relay4
- topic: "${mqtt_local_command_topic}/relay4/set"
payload: "OFF"
then:
- switch.turn_off: relay4