Compare commits
27 Commits
23abe209a5
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
540fe186ff | ||
|
c547bd8cb9 | ||
|
8adb0a63ba | ||
|
40e289e99a | ||
|
7aa8badcae | ||
|
ab1240e720 | ||
|
0dfa19b235 | ||
|
1b9ebd08d5 | ||
|
e3d0224364 | ||
|
77f2af3d74 | ||
|
a0588bf6c2 | ||
|
c73e41496d | ||
|
c76ca83932 | ||
|
f7ad26c288 | ||
|
27b26d165f | ||
|
40ff88e0f5 | ||
|
c286a11f8d | ||
|
b5375b2219 | ||
|
a6ddc60ec9 | ||
|
f7ac6f7165 | ||
|
4c8df42b89 | ||
|
ba4f7a19cc | ||
|
e96336dbc4 | ||
|
42796bc46e | ||
|
ac887724a2 | ||
|
d9ca44a9ee | ||
|
6034bc0320 |
@@ -8,6 +8,7 @@ homeassistant:
|
||||
customize: !include customize.yaml
|
||||
packages: !include_dir_named packages
|
||||
|
||||
template: !include_dir_merge_list templates
|
||||
#group: !include groups.yaml
|
||||
group: !include_dir_merge_named group/
|
||||
automation: !include_dir_merge_list automations/
|
||||
|
@@ -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
|
188
esphome/archive/esp-officemultiusb.yaml
Normal file
188
esphome/archive/esp-officemultiusb.yaml
Normal file
@@ -0,0 +1,188 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# OFFICE MULTI USB CONTROL
|
||||
# Controlled by a Sonoff Basic R1
|
||||
#
|
||||
# V1.0 2025-06-18 Initial Version
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-officemultiusb"
|
||||
friendly_name: "Office Multi USB Control"
|
||||
mqtt_device_name: "office-multiusb-control"
|
||||
description_comment: "Multi USB control in the Office (behind monitors) :: Sonoff Basic"
|
||||
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
|
||||
project_version: "v1.0" # 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-officemultiusb_ip
|
||||
mqtt_main_command_topic: !secret mqtt_main_command_topic
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:generator-portable"
|
||||
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# MQTT Controls
|
||||
mqtt_main_topic: "${mqtt_main_command_topic}/${mqtt_device_name}/operation" # 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"
|
||||
|
||||
##########################################################################################
|
||||
# PACKAGES: Included Common Packages
|
||||
# https://esphome.io/components/esphome.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
|
||||
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}"
|
||||
|
||||
##########################################################################################
|
||||
# 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}"
|
||||
# platformio_options:
|
||||
# build_flags:
|
||||
# - "-Os" # optimize for size
|
||||
# - "-Wl,--gc-sections" # drop unused code/data
|
||||
# - "-fno-exceptions" # strip C++ exceptions
|
||||
# - "-fno-rtti" # strip C++ RTTI
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# 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: False
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 Relay Switch is GPIO12
|
||||
#############################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "ELV Power Supply"
|
||||
pin: GPIO12
|
||||
id: relay1
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
icon: "${relay_icon}"
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 Button is GPIO03
|
||||
#############################################
|
||||
binary_sensor:
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "Power Button"
|
||||
id: power_button
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
on_click:
|
||||
- min_length: 20ms
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay1).state) {
|
||||
// Relay is ON: turn it OFF
|
||||
id(relay1).turn_off();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay1).turn_on();
|
||||
}
|
||||
|
||||
# Mimics actual relay status (but not controllable)
|
||||
- platform: template
|
||||
name: "Relay Status"
|
||||
lambda: |-
|
||||
return id(relay1).state;
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 LED is GPIO13
|
||||
#############################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: yes
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Relay 1 control
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay1
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay1
|
||||
|
@@ -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
|
9
esphome/common/api_common_noencryption.yaml
Normal file
9
esphome/common/api_common_noencryption.yaml
Normal file
@@ -0,0 +1,9 @@
|
||||
#############################################
|
||||
# Enable the Home Assistant API
|
||||
# https://esphome.io/components/api.html
|
||||
#############################################
|
||||
api:
|
||||
#encryption:
|
||||
#key: ${local_api_key}
|
||||
reboot_timeout: 0s # disables watchdog reboot on API failure
|
||||
|
@@ -14,10 +14,11 @@ 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)
|
||||
discover_ip: False # enable device discovery (true is default)
|
||||
id: mqtt_client
|
||||
reboot_timeout: 0s # same for MQTT
|
||||
log_topic: null # <— stops MQTT log streaming (big JSON payloads)
|
||||
|
@@ -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: "23" # Base interval in hours
|
||||
random_offset_max_minutes: "59" # Max random offset in minutes
|
||||
|
||||
#############################################
|
||||
# Common Wifi Settings
|
||||
@@ -45,8 +50,10 @@ wifi:
|
||||
gateway: ${static_ip_gateway}
|
||||
subnet: ${static_ip_subnet}
|
||||
dns1: ${static_ip_dns1}
|
||||
dns2: ${static_ip_dns2}
|
||||
use_address: ${local_static_ip_address}
|
||||
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
|
||||
@@ -64,6 +71,7 @@ ota:
|
||||
- platform: esphome
|
||||
password: ${local_ota_pass}
|
||||
version: 2
|
||||
#- platform: web_server
|
||||
|
||||
#############################################
|
||||
# Safe Mode
|
||||
@@ -79,3 +87,36 @@ safe_mode:
|
||||
#############################################
|
||||
network:
|
||||
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
|
||||
|
||||
|
126
esphome/common/network_common_dual.yaml
Normal file
126
esphome/common/network_common_dual.yaml
Normal 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
|
||||
|
81
esphome/common/network_common_fallback.yaml
Normal file
81
esphome/common/network_common_fallback.yaml
Normal 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}
|
@@ -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
|
||||
@@ -57,10 +64,36 @@ text_sensor:
|
||||
icon: mdi:clock-start
|
||||
update_interval: ${local_update_interval}
|
||||
entity_category: "diagnostic"
|
||||
- platform: template
|
||||
name: "Last Reset Reason"
|
||||
update_interval: 30s
|
||||
entity_category: diagnostic
|
||||
lambda: |-
|
||||
#if defined(USE_ESP8266)
|
||||
return { ESP.getResetReason().c_str() };
|
||||
#elif defined(USE_ESP32)
|
||||
auto r = esp_reset_reason();
|
||||
switch (r) {
|
||||
case ESP_RST_POWERON: return { "Power-on" };
|
||||
case ESP_RST_EXT: return { "External pin" };
|
||||
case ESP_RST_SW: return { "Software reset" };
|
||||
case ESP_RST_PANIC: return { "Exception/Panic" };
|
||||
case ESP_RST_INT_WDT: return { "Interrupt WDT" };
|
||||
case ESP_RST_TASK_WDT: return { "Task WDT" };
|
||||
case ESP_RST_WDT: return { "Other WDT" };
|
||||
case ESP_RST_DEEPSLEEP: return { "Deep sleep wake" };
|
||||
case ESP_RST_BROWNOUT: return { "Brownout" };
|
||||
case ESP_RST_SDIO: return { "SDIO" };
|
||||
default: return { "Unknown" };
|
||||
}
|
||||
#else
|
||||
return { "Unknown" };
|
||||
#endif
|
||||
|
||||
######################################################
|
||||
|
||||
###################################################################################################
|
||||
# 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 +142,10 @@ text_sensor:
|
||||
# }
|
||||
# icon: mdi:clock-start
|
||||
|
||||
##########################################################################################
|
||||
# BUTTONS
|
||||
# Diagnostic buttons, activated if needed in HA
|
||||
##########################################################################################
|
||||
button:
|
||||
- platform: safe_mode
|
||||
name: "Safe Mode Restart:"
|
||||
|
41
esphome/common/sensors_common_lite.yaml
Normal file
41
esphome/common/sensors_common_lite.yaml
Normal file
@@ -0,0 +1,41 @@
|
||||
##########################################################################################
|
||||
# GENERAL COMMON SENSORS
|
||||
# https://esphome.io/components/sensor/
|
||||
# LITE (1MB-friendly)
|
||||
##########################################################################################
|
||||
sensor:
|
||||
- platform: uptime
|
||||
name: "Uptime (s):"
|
||||
update_interval: ${local_update_interval}
|
||||
id: uptime_sensor
|
||||
entity_category: diagnostic
|
||||
|
||||
- platform: wifi_signal
|
||||
name: "Wifi (dB):"
|
||||
id: wifi_signal_db
|
||||
update_interval: ${local_update_interval}
|
||||
entity_category: diagnostic
|
||||
|
||||
binary_sensor:
|
||||
- platform: status
|
||||
name: "Network Status"
|
||||
icon: mdi:check-network-outline
|
||||
entity_category: diagnostic
|
||||
|
||||
##########################################################################################
|
||||
# BUTTONS
|
||||
# Diagnostic buttons, activated if needed in HA
|
||||
##########################################################################################
|
||||
button:
|
||||
- platform: safe_mode
|
||||
name: "Safe Mode Restart:"
|
||||
entity_category: "diagnostic"
|
||||
disabled_by_default: true
|
||||
- platform: restart
|
||||
name: "Restart:"
|
||||
entity_category: "diagnostic"
|
||||
disabled_by_default: true
|
||||
- platform: factory_reset
|
||||
name: "FACTORY RESET:"
|
||||
entity_category: "diagnostic"
|
||||
disabled_by_default: true
|
183
esphome/esp-3dprinterpow.yaml
Normal file
183
esphome/esp-3dprinterpow.yaml
Normal 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
|
1019
esphome/esp-6buttontest-pmb.yaml
Normal file
1019
esphome/esp-6buttontest-pmb.yaml
Normal file
File diff suppressed because it is too large
Load Diff
381
esphome/esp-bedrm2ceilingfan.yaml
Normal file
381
esphome/esp-bedrm2ceilingfan.yaml
Normal 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 (0–3) + 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 (1–3):
|
||||
on_speed_set:
|
||||
- lambda: |-
|
||||
id(speed_value) = x;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
# whenever the fan goes fully off:
|
||||
on_turn_off:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: "0"
|
||||
# whenever the fan goes off→on (e.g. via HA’s Fan switch):
|
||||
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));'
|
265
esphome/esp-bedrm2fanswitch.yaml
Normal file
265
esphome/esp-bedrm2fanswitch.yaml
Normal 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_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
|
||||
# Device Settings
|
||||
#relay_icon: "mdi:heating-coil"
|
||||
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# MQTT LOCAL Controls
|
||||
#mqtt_device_name: "bedroom2-ceilingfan-switch"
|
||||
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device_name: "bedroom2-ceilingfan"
|
||||
mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/speed/set"
|
||||
mqtt_remote_device_command1: "+"
|
||||
mqtt_remote_device_command2: "-"
|
||||
mqtt_remote_device_command3: "0"
|
||||
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
|
||||
|
||||
# Button Naming & Icons
|
||||
|
||||
# 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();
|
||||
}
|
||||
}
|
180
esphome/esp-bedrm2lights.yaml
Normal file
180
esphome/esp-bedrm2lights.yaml
Normal file
@@ -0,0 +1,180 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 2 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
|
||||
|
||||
|
381
esphome/esp-bedrm3ceilingfan.yaml
Normal file
381
esphome/esp-bedrm3ceilingfan.yaml
Normal file
@@ -0,0 +1,381 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CEILING FAN - BEDROOM 3
|
||||
# - 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-bedrm3ceilingfan"
|
||||
friendly_name: "Bedroom 3 Ceiling Fan"
|
||||
description_comment: "3 Speed Overhead Ceiling Fan Bedroom 3 :: Sonoff ifan02"
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# 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-bedrm3ceilingfan_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: "bedroom3-ceilingfan"
|
||||
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
|
||||
# Button Naming & Icons
|
||||
|
||||
# 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 (0–3) + 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 (1–3):
|
||||
on_speed_set:
|
||||
- lambda: |-
|
||||
id(speed_value) = x;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: !lambda 'return to_string(id(speed_value));'
|
||||
# whenever the fan goes fully off:
|
||||
on_turn_off:
|
||||
- lambda: |-
|
||||
id(speed_value) = 0;
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/speed/state"
|
||||
payload: "0"
|
||||
# whenever the fan goes off→on (e.g. via HA’s Fan switch):
|
||||
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));'
|
265
esphome/esp-bedrm3fanswitch.yaml
Normal file
265
esphome/esp-bedrm3fanswitch.yaml
Normal file
@@ -0,0 +1,265 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 3 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-bedrm3fanswitch"
|
||||
friendly_name: "Bedroom 3 Fan Wall Switch (3)"
|
||||
description_comment: "Switch for Bedroom 3 Ceiling Fan using Zemismart KS-811 Triple Push Button. Speed Up (1), Speed Down (2), Fan Off (3)"
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Zemismart Technologies.KS-811-3 (Triple)" # Project Details
|
||||
project_version: "v1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
#entity_prefix: "Main Bathroom" # Simple device name where we want to prefix a sensor or switch, eg "Load" Current.
|
||||
|
||||
# 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-bedrm3fanswitch_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: "bedroom3-ceilingfan"
|
||||
mqtt_remote_device_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set"
|
||||
mqtt_remote_device_command1: "+"
|
||||
mqtt_remote_device_command2: "-"
|
||||
mqtt_remote_device_command3: "0"
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
|
||||
|
||||
# Button Naming & Icons
|
||||
|
||||
# Switch/Relay Naming & Icons
|
||||
#relay_icon: "mdi:heating-coil"
|
||||
switch_1_name: "Fan Speed Up" # This is virtual only, no power connected to 1st relay
|
||||
switch_2_name: "Fan Speed Down" # This is virtual only, no power connected to 2nd relay
|
||||
switch_3_name: "Fan Off" # This is virtual only, no power connected to 3rd relay
|
||||
|
||||
##########################################################################################
|
||||
# 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();
|
||||
}
|
||||
}
|
238
esphome/esp-bedrm3lights.yaml
Normal file
238
esphome/esp-bedrm3lights.yaml
Normal file
@@ -0,0 +1,238 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# BEDROOM 3 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-bedrm3lights"
|
||||
friendly_name: "Bedroom 3 Lightswitch (2)"
|
||||
description_comment: "Bedroom 3 Main Lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1-Virtual), All Lights Off (2-Virtual)"
|
||||
device_area: "Bedroom 3" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# 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-bedrm3lights_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: "bedroom3-lightswitch"
|
||||
#mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device_name: "bedroom3-ceilingfan"
|
||||
mqtt_remote_device_command_topic1: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/light/set"
|
||||
mqtt_remote_status_topic1: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/light/state" # Topic we will use to view status of remote without HA
|
||||
mqtt_remote_device_command_ON: "ON"
|
||||
mqtt_remote_device_command_OFF: "OFF"
|
||||
mqtt_remote_device_command_topic2: "${mqtt_local_command_main_topic}/${mqtt_remote_device_name}/speed/set"
|
||||
#mqtt_remote_device_command1: "+"
|
||||
#mqtt_remote_device_command2: "-"
|
||||
mqtt_remote_device_command_0: "0"
|
||||
#mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device_name}/speed/state" # Topic we will use to view status locally without HA
|
||||
|
||||
# Button Naming & Icons
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Main Lights" # Nothing physically connected to this output. Lights are physically on IFan02 light output
|
||||
switch_2_name: "All Lights Off" # Nothing physically connected to this output
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
|
||||
#GLobals
|
||||
|
||||
globals:
|
||||
- id: btn1_last_ms
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
initial_value: '0'
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
id: button_1
|
||||
pin:
|
||||
number: GPIO16
|
||||
mode:
|
||||
input: true
|
||||
pullup: false # set to true if you need an internal pull-up
|
||||
inverted: true
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
on_press:
|
||||
# cooldown: 250 ms between publishes
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
return (millis() - id(btn1_last_ms)) > 250;
|
||||
then:
|
||||
- lambda: |-
|
||||
id(btn1_last_ms) = millis();
|
||||
- if:
|
||||
condition:
|
||||
switch.is_on: Relay_1
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
qos: 0
|
||||
retain: false
|
||||
else:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic1}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
qos: 0
|
||||
retain: false
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.turn_off: Relay_2
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
qos: 0
|
||||
retain: false
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic2}"
|
||||
payload: "${mqtt_remote_device_command_0}"
|
||||
qos: 0
|
||||
retain: false
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Switch control. Turn on/off relay if remote device switched on/off
|
||||
- topic: "${mqtt_remote_status_topic1}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
- topic: "${mqtt_remote_status_topic1}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
248
esphome/esp-centralstairs-bottom.yaml
Normal file
248
esphome/esp-centralstairs-bottom.yaml
Normal file
@@ -0,0 +1,248 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CENTRAL STAIRS - BOTTOM LIGHTSWITCH
|
||||
# V3.7 2025-09-24 upload to this device
|
||||
# V3.5 2025-07-24 YAML tidyups
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# NOTES
|
||||
# - Light switch at top of the stairs, only the footer lights physically connected.
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-centralstairs-bottom"
|
||||
friendly_name: "Central Stair Lightswitch - Bottom (2)"
|
||||
description_comment: "Central Stair Lightswitch - Bottom, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2)"
|
||||
device_area: "" # 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.7" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-centralstairs-bottom_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_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_local_device_name: "stair-mainlights-lower"
|
||||
mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}/set" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}/state" # Topic we will use to view status locally without HA
|
||||
mqtt_local_device_command_ON: "ON"
|
||||
mqtt_local_device_command_OFF: "OFF"
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device1_name: "stair-footerlights"
|
||||
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/set"
|
||||
mqtt_remote_device1_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device1_name}/state"
|
||||
#mqtt_remote_device2_name: "stair-mainlights-upper"
|
||||
#mqtt_remote_device2_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device2_name}/relay3/set"
|
||||
#mqtt_remote_device2_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device2_name}/relay3/state"
|
||||
mqtt_remote_device_command_ON: "ON"
|
||||
mqtt_remote_device_command_OFF: "OFF"
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Main Stair Lights (Lower)" # Physical, but just the lower lights below the media cabinet
|
||||
switch_2_name: "Stair Footer Lights" # virtual only, nothing connected to this output
|
||||
#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
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_connect:
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(Relay_1).state;'
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
qos: 0
|
||||
retain: false
|
||||
else:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
qos: 0
|
||||
retain: false
|
||||
on_message:
|
||||
# Light control to turn on relay 1
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
# Light control to turn off relay 1
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
||||
- topic: "${mqtt_remote_device1_status_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_2
|
||||
# Light control to turn off relay 2
|
||||
- topic: "${mqtt_remote_device1_status_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_1
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
# Toggle the remote Footer Lights via COMMAND topic, based on our mirrored state
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(Relay_2).state;'
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
retain: false
|
||||
else:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
retain: false
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
retain: false
|
||||
on_turn_off:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
retain: false
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
# No mqtt.publish here (this is a mirror only)
|
232
esphome/esp-centralstairs-top.yaml
Normal file
232
esphome/esp-centralstairs-top.yaml
Normal file
@@ -0,0 +1,232 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# CENTRAL STAIRS - TOP LIGHTSWITCH
|
||||
# V3.7 2025-09-24 upload to this device
|
||||
# V3.5 2025-07-24 YAML tidyups
|
||||
##########################################################################################
|
||||
# Zemismart KS-811 Double push button
|
||||
# pinout/schematic https://community.home-assistant.io/t/zemismart-ks-811-working-with-esphome/
|
||||
#
|
||||
# NOTES
|
||||
# - Light switch at top of the stairs
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-centralstairs-top"
|
||||
friendly_name: "Central Stair Lightswitch - Top (2)"
|
||||
description_comment: "Central Stair Lightswitch - Top, using Zemismart KS-811 Double Push Button. Main Stair Lights (1), Stair Footer Lights (2)"
|
||||
device_area: "" # 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.7" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-centralstairs-top_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_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_local_device_name: "stair-footerlights"
|
||||
mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_local_device_name}/set" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_local_device_name}/state" # Topic we will use to view status locally without HA
|
||||
mqtt_local_device_command_ON: "ON"
|
||||
mqtt_local_device_command_OFF: "OFF"
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device1_name: "stair-mainlights-lower"
|
||||
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/set"
|
||||
mqtt_remote_device1_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device1_name}/state"
|
||||
#mqtt_remote_device2_name: "stair-mainlights-upper"
|
||||
#mqtt_remote_device2_command_topic: "${mqtt_local_command_main_topic}/${mqtt_remote_device2_name}/relay3/set"
|
||||
#mqtt_remote_device2_status_topic: "${mqtt_local_status_main_topic}/${mqtt_remote_device2_name}/relay3/state"
|
||||
mqtt_remote_device_command_ON: "ON"
|
||||
mqtt_remote_device_command_OFF: "OFF"
|
||||
|
||||
# Switch Naming
|
||||
switch_1_name: "Main Stair Lights" # virtual only, nothing connected to this output
|
||||
switch_2_name: "Stair Footer Lights"
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control to turn on relay 2
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_2
|
||||
# Light control to turn off relay 2
|
||||
- topic: "${mqtt_local_command_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_2
|
||||
- topic: "${mqtt_remote_device1_status_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
# Light control to turn off relay 2
|
||||
- topic: "${mqtt_remote_device1_status_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
# Toggle the remote Main Stair Lights (lower) via COMMAND topic, based on our mirrored state
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(Relay_1).state;'
|
||||
then:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
retain: false
|
||||
else:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
retain: false
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO05
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
filters:
|
||||
- delayed_on: 30ms
|
||||
- delayed_off: 30ms
|
||||
name: "Button 2: ${switch_2_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_2
|
||||
|
||||
#########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
#########################################################################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
# No mqtt.publish here (this is a mirror only)
|
||||
|
||||
- platform: gpio
|
||||
name: "Relay 2: ${switch_2_name}"
|
||||
pin: GPIO12
|
||||
id: Relay_2
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
retain: false
|
||||
on_turn_off:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
retain: false
|
||||
|
||||
|
755
esphome/esp-dinpowermonitor-pmb.yaml
Normal file
755
esphome/esp-dinpowermonitor-pmb.yaml
Normal file
@@ -0,0 +1,755 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# SMART DIN POWER MONITOR AND RELAY (Originally CBU)
|
||||
# V1.0 2025-08-26 Initial Version
|
||||
##########################################################################################
|
||||
# Ex Tuya Smart Relay
|
||||
# Uses this chip for power monitoring BL0942
|
||||
# Replacement https://templates.blakadder.com/ESP8685-WROOM-06.html
|
||||
#
|
||||
# NOTES
|
||||
# - DIN rail power monitor and relay
|
||||
# - Relay is a pulse to latch ON (GPIO04) and pulse to latch OFF (GPIO05)
|
||||
# - Has an "is it running" template sensor with a minimum wattage value of ${min_power_to_state_running_default}
|
||||
# - The relay opens on over-current at ${max_current_trip_default} (Trip Active sensor set). Trip is latched
|
||||
# (relay stays OFF) until manually reset via the "Clear Trip" button or you toggle the relay ON again.
|
||||
# - The status_led flashes with a speed depending on current (faster near limit).
|
||||
# - The status_led is ON when the relay has tripped
|
||||
# - Inrush debounce: current must remain above the trip threshold for ${overcurrent_debounce_ms} ms
|
||||
# before the trip occurs (helps ignore short inrush spikes).
|
||||
# - Energy totals calculated on-device:
|
||||
# * Last Hour Energy (kWh) - snapshot of the previous completed hour
|
||||
# * Today / Yesterday (kWh) - resets at local midnight, survives reboots
|
||||
# * This Week / Last Week (kWh) - resets at Monday 00:00 local time, survives reboots
|
||||
# * This Month / Last Month (kWh) - resets at 1st of month 00:00 local time, survives reboots
|
||||
# - For rolling 24h Min/Max Power, use HA "Statistics" helper instead of on-device buffers.
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
||||
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
||||
##########################################################################################
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "dinpowermonitor-pmb"
|
||||
friendly_name: "Din Power"
|
||||
description_comment: "DIN Rail mounted current monitor and relay, with current based (software) trip"
|
||||
device_area: "Hallway" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Generic ESP32.ESP8685-WROOM-06" # Project details, a dot separates the HA columns
|
||||
project_version: "v1.0" # Project version allows checking of deployed vs latest version
|
||||
|
||||
# Passwords
|
||||
api_key: !secret esp-api_key # unfortunately you cannot use substitutions inside secrets names
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-dinpowermonitor-pmb_ip
|
||||
|
||||
# Device General Settings
|
||||
log_level: "ERROR" # NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for general sensors etc
|
||||
|
||||
# Device Specific Defaults (used to seed HA-tunable numbers)
|
||||
relay_1_name: "Relay"
|
||||
button_1_name: "Toggle Button"
|
||||
status_led_name: "Power Active"
|
||||
min_power_to_state_running_default: 4 # Watts, initial value only
|
||||
max_current_trip_default: 6 # Amps, initial value only
|
||||
led_flash_slow_ms: 1000 # slow flash period when just running
|
||||
led_flash_fast_ms: 100 # very fast flash period near trip
|
||||
overcurrent_debounce_ms: 300 # Over-current inrush debounce (ms)
|
||||
|
||||
##########################################################################################
|
||||
# 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: -100
|
||||
then:
|
||||
# Restore "Last Trip" text from persisted epoch (if any)
|
||||
- lambda: |-
|
||||
if (id(last_trip_epoch) > 0) {
|
||||
auto t = time::ESPTime::from_epoch_local(id(last_trip_epoch));
|
||||
char buf[24];
|
||||
t.strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S");
|
||||
id(ts_last_trip).publish_state(buf);
|
||||
} else {
|
||||
id(ts_last_trip).publish_state("Never");
|
||||
}
|
||||
# Apply Power Restore Mode selector (Always ON / Always OFF / Previous State)
|
||||
- lambda: |-
|
||||
std::string mode = id(sel_restore_mode).state;
|
||||
if (mode == "Always ON") {
|
||||
id(relay_virtual).turn_on();
|
||||
} else if (mode == "Always OFF") {
|
||||
id(relay_virtual).turn_off();
|
||||
} else {
|
||||
// "Previous State" -> do nothing (template switch will keep last or default OFF)
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
esp32:
|
||||
board: esp32-c3-devkitm-1
|
||||
variant: esp32c3
|
||||
framework:
|
||||
type: esp-idf
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome Logging Enable
|
||||
# https://esphome.io/components/logger.html
|
||||
##########################################################################################
|
||||
logger:
|
||||
level: ${log_level}
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED (BLUE) - low = ON per mapping
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO8
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# UART BUS
|
||||
# https://esphome.io/components/uart/
|
||||
##########################################################################################
|
||||
uart:
|
||||
# for BL0942
|
||||
id: bl_uart
|
||||
rx_pin: GPIO19 # BL0942 TXD -> MCU RX
|
||||
tx_pin: GPIO18 # BL0942 RXD -> MCU TX
|
||||
baud_rate: 4800
|
||||
parity: NONE
|
||||
stop_bits: 1
|
||||
|
||||
##########################################################################################
|
||||
# GLOBALS
|
||||
# https://esphome.io/components/globals.html
|
||||
##########################################################################################
|
||||
globals:
|
||||
# Used for LED blink period calculation (in milliseconds)
|
||||
- id: _blink_period_ms
|
||||
type: int
|
||||
restore_value: no
|
||||
initial_value: "500"
|
||||
|
||||
# Last trip time, saved across reboots.
|
||||
- id: last_trip_epoch
|
||||
type: uint32_t
|
||||
restore_value: yes
|
||||
initial_value: "0"
|
||||
|
||||
# Debounce start timestamp (ms since boot) for over-current detection
|
||||
- id: _oc_start_ms
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
initial_value: "0"
|
||||
|
||||
# ---- ENERGY ACCUMULATION & PERIOD SNAPSHOTS ----
|
||||
- id: g_last_ms # millis() timestamp of last integration step
|
||||
type: uint32_t
|
||||
restore_value: no
|
||||
initial_value: "0"
|
||||
|
||||
# Current-period totals (persisted)
|
||||
- id: g_hour_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_today_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_week_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_month_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
|
||||
# Last-period snapshots (persisted)
|
||||
- id: g_last_hour_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_yesterday_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_last_week_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
- id: g_last_month_kwh
|
||||
type: float
|
||||
restore_value: yes
|
||||
initial_value: "0.0"
|
||||
|
||||
# Boundary trackers (don't persist)
|
||||
- id: g_last_hour_seen
|
||||
type: int
|
||||
restore_value: no
|
||||
initial_value: "-1"
|
||||
- id: g_last_doy_seen
|
||||
type: int
|
||||
restore_value: no
|
||||
initial_value: "-1"
|
||||
- id: g_last_wday_seen
|
||||
type: int
|
||||
restore_value: no
|
||||
initial_value: "-1"
|
||||
- id: g_last_month_seen
|
||||
type: int
|
||||
restore_value: no
|
||||
initial_value: "-1"
|
||||
|
||||
##########################################################################################
|
||||
# SENSORS
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
sensor:
|
||||
- platform: bl0942
|
||||
uart_id: bl_uart
|
||||
update_interval: 250ms
|
||||
voltage:
|
||||
name: "${friendly_name} Voltage"
|
||||
id: pm_voltage
|
||||
accuracy_decimals: 1
|
||||
unit_of_measurement: "V"
|
||||
device_class: voltage
|
||||
state_class: measurement
|
||||
current:
|
||||
name: "${friendly_name} Current"
|
||||
id: pm_current
|
||||
accuracy_decimals: 3
|
||||
unit_of_measurement: "A"
|
||||
device_class: current
|
||||
state_class: measurement
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
// OVER-CURRENT TRIP HANDLER with inrush debounce
|
||||
// Trip when current > n_max_trip and relay is ON, but only if it stays above
|
||||
// for ${overcurrent_debounce_ms} ms (to ignore short inrush spikes).
|
||||
if (id(bs_tripped).state) {
|
||||
// Already tripped: reset debounce tracker and do nothing
|
||||
id(_oc_start_ms) = 0;
|
||||
} else if (id(relay_virtual).state && x > id(n_max_trip).state) {
|
||||
// Over threshold while relay is ON
|
||||
if (id(_oc_start_ms) == 0) {
|
||||
id(_oc_start_ms) = millis(); // start debounce window
|
||||
}
|
||||
uint32_t elapsed = millis() - id(_oc_start_ms);
|
||||
if (elapsed >= ${overcurrent_debounce_ms}) {
|
||||
ESP_LOGI("trip",
|
||||
"Overcurrent trip: %.3f A > %.3f A for %u ms (>= %u ms), opening relay",
|
||||
x, id(n_max_trip).state, (unsigned) elapsed, (unsigned) ${overcurrent_debounce_ms});
|
||||
|
||||
// Mark trip, stop blinker FIRST
|
||||
id(bs_tripped).publish_state(true);
|
||||
id(led_blinker).stop();
|
||||
|
||||
// Open latching relay (template handles OFF coil pulse)
|
||||
id(relay_virtual).turn_off();
|
||||
|
||||
// Force LED solid ON to indicate trip
|
||||
auto call = id(led).turn_on();
|
||||
call.perform();
|
||||
|
||||
// Time-stamp "Last Trip" using SNTP time (YYYY-MM-DD HH:MM:SS) and persist
|
||||
auto now_clk = id(sntp_time).now();
|
||||
if (now_clk.is_valid()) {
|
||||
char buf[24];
|
||||
now_clk.strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S");
|
||||
id(ts_last_trip).publish_state(buf);
|
||||
id(last_trip_epoch) = (uint32_t) now_clk.timestamp;
|
||||
} else {
|
||||
id(ts_last_trip).publish_state("unknown");
|
||||
}
|
||||
|
||||
// Reset debounce tracker
|
||||
id(_oc_start_ms) = 0;
|
||||
}
|
||||
} else {
|
||||
// Below threshold or relay OFF: reset debounce tracker
|
||||
id(_oc_start_ms) = 0;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------
|
||||
// ENERGY ACCUMULATION (kWh) + PERIOD ROLLOVERS (hour/day/week/month)
|
||||
// ------------------------------------------------------------------
|
||||
// Integrate W over time using millis() -> kWh
|
||||
uint32_t now_ms = millis();
|
||||
if (id(g_last_ms) == 0) {
|
||||
id(g_last_ms) = now_ms; // first sample since boot
|
||||
} else {
|
||||
uint32_t dt_ms = now_ms - id(g_last_ms);
|
||||
id(g_last_ms) = now_ms;
|
||||
|
||||
float p_w = (isnan(x) || x < 0.0f) ? 0.0f : x; // sanitize power
|
||||
float inc_kwh = p_w * (dt_ms / 3600000.0f); // W * hours -> kWh
|
||||
|
||||
id(g_hour_kwh) += inc_kwh;
|
||||
id(g_today_kwh) += inc_kwh;
|
||||
id(g_week_kwh) += inc_kwh; // Week rolls at Monday 00:00 local time
|
||||
id(g_month_kwh) += inc_kwh;
|
||||
}
|
||||
|
||||
// Use SNTP time for clean boundary changes
|
||||
auto now = id(sntp_time).now();
|
||||
if (now.is_valid()) {
|
||||
// Hour rollover: when hour changes
|
||||
if (id(g_last_hour_seen) != now.hour) {
|
||||
if (id(g_last_hour_seen) != -1) {
|
||||
id(g_last_hour_kwh) = id(g_hour_kwh);
|
||||
id(s_last_hour_kwh).publish_state(id(g_last_hour_kwh));
|
||||
}
|
||||
id(g_hour_kwh) = 0.0f;
|
||||
id(g_last_hour_seen) = now.hour;
|
||||
}
|
||||
|
||||
// Day rollover (midnight local)
|
||||
if (id(g_last_doy_seen) != now.day_of_year) {
|
||||
if (id(g_last_doy_seen) != -1) {
|
||||
id(g_yesterday_kwh) = id(g_today_kwh);
|
||||
id(s_yesterday_kwh).publish_state(id(g_yesterday_kwh));
|
||||
}
|
||||
id(g_today_kwh) = 0.0f;
|
||||
id(g_last_doy_seen) = now.day_of_year;
|
||||
}
|
||||
|
||||
// Week rollover: Monday 00:00 local time (i.e., after Sunday)
|
||||
// ESPHome day_of_week: Monday=1 ... Sunday=7
|
||||
if (now.day_of_week == 1 && now.hour == 0 && id(g_last_wday_seen) != 1) {
|
||||
id(g_last_week_kwh) = id(g_week_kwh);
|
||||
id(s_last_week_kwh).publish_state(id(g_last_week_kwh));
|
||||
id(g_week_kwh) = 0.0f;
|
||||
}
|
||||
id(g_last_wday_seen) = now.day_of_week;
|
||||
|
||||
// Month rollover: first day of month at 00:00
|
||||
if (id(g_last_month_seen) != now.month) {
|
||||
if (id(g_last_month_seen) != -1 && now.day_of_month == 1 && now.hour == 0) {
|
||||
id(g_last_month_kwh) = id(g_month_kwh);
|
||||
id(s_last_month_kwh).publish_state(id(g_last_month_kwh));
|
||||
id(g_month_kwh) = 0.0f;
|
||||
}
|
||||
id(g_last_month_seen) = now.month;
|
||||
}
|
||||
}
|
||||
power:
|
||||
name: "${friendly_name} Power"
|
||||
id: pm_power
|
||||
accuracy_decimals: 1
|
||||
unit_of_measurement: "W"
|
||||
device_class: power
|
||||
state_class: measurement
|
||||
energy:
|
||||
name: "${friendly_name} Energy"
|
||||
id: pm_energy
|
||||
unit_of_measurement: "Wh"
|
||||
device_class: energy
|
||||
state_class: total_increasing
|
||||
frequency:
|
||||
name: "${friendly_name} Frequency"
|
||||
id: pm_freq
|
||||
unit_of_measurement: "Hz"
|
||||
device_class: frequency
|
||||
state_class: measurement
|
||||
# Optional calibration references (uncomment and tune if needed)
|
||||
# voltage_reference: 15968
|
||||
# current_reference: 124180
|
||||
# power_reference: 309.1
|
||||
# energy_reference: 2653
|
||||
|
||||
##########################################################################
|
||||
# ENERGY TOTALS (kWh) EXPOSED TO HA
|
||||
# These read the persisted globals; they update periodically.
|
||||
##########################################################################
|
||||
- platform: template
|
||||
name: "${friendly_name} Last Hour Energy"
|
||||
id: s_last_hour_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_last_hour_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} Today Energy"
|
||||
id: s_today_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_today_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} Yesterday Energy"
|
||||
id: s_yesterday_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_yesterday_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} This Week Energy"
|
||||
id: s_week_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_week_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} Last Week Energy"
|
||||
id: s_last_week_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_last_week_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} This Month Energy"
|
||||
id: s_month_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_month_kwh);
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} Last Month Energy"
|
||||
id: s_last_month_kwh
|
||||
unit_of_measurement: "kWh"
|
||||
device_class: energy
|
||||
state_class: total
|
||||
accuracy_decimals: 3
|
||||
update_interval: 30s
|
||||
lambda: |-
|
||||
return id(g_last_month_kwh);
|
||||
|
||||
##########################################################################################
|
||||
# TEXT SENSOR COMPONENT
|
||||
# https://esphome.io/components/text_sensor/
|
||||
##########################################################################################
|
||||
text_sensor:
|
||||
# Holds the date/time of last trip (string with seconds)
|
||||
- platform: template
|
||||
name: "${friendly_name} Last Trip"
|
||||
id: ts_last_trip
|
||||
icon: "mdi:clock-alert"
|
||||
entity_category: diagnostic
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
# https://esphome.io/components/binary_sensor/template.html
|
||||
##########################################################################################
|
||||
binary_sensor:
|
||||
# "Is Running" template sensor
|
||||
- platform: template
|
||||
id: bs_running
|
||||
name: "${friendly_name} Running"
|
||||
lambda: |-
|
||||
if (isnan(id(pm_power).state)) {
|
||||
return false;
|
||||
} else if (id(pm_power).state > id(n_min_power).state) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
filters:
|
||||
- delayed_off: 15s
|
||||
on_press:
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
and:
|
||||
- switch.is_on: relay_virtual
|
||||
- lambda: 'return !id(bs_tripped).state;'
|
||||
then:
|
||||
- script.execute: led_blinker
|
||||
on_release:
|
||||
then:
|
||||
- script.stop: led_blinker
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return !id(bs_tripped).state;'
|
||||
then:
|
||||
- light.turn_off: led
|
||||
|
||||
# Trip flag exposed to HA; set true on over-current. Cleared when relay is turned ON or via Reset button.
|
||||
- platform: template
|
||||
id: bs_tripped
|
||||
name: "${friendly_name} Trip Active"
|
||||
device_class: problem
|
||||
|
||||
# On-board button (P17 -> IO9) pulls low when pressed
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO9
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "${button_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: relay_virtual
|
||||
|
||||
##########################################################################################
|
||||
# NUMBER COMPONENT
|
||||
# https://esphome.io/components/number/
|
||||
##########################################################################################
|
||||
# HA-TUNABLE THRESHOLDS (NUMBER ENTITIES)
|
||||
# https://esphome.io/components/number/template.html
|
||||
##########################################################################################
|
||||
number:
|
||||
- platform: template
|
||||
name: "${friendly_name} Min Power Running"
|
||||
id: n_min_power
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: ${min_power_to_state_running_default}
|
||||
min_value: 1
|
||||
max_value: 100
|
||||
step: 1
|
||||
unit_of_measurement: "W"
|
||||
icon: "mdi:flash-outline"
|
||||
|
||||
- platform: template
|
||||
name: "${friendly_name} Max Current Trip"
|
||||
id: n_max_trip
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: ${max_current_trip_default}
|
||||
min_value: 0
|
||||
max_value: 10
|
||||
step: 0.2
|
||||
unit_of_measurement: "A"
|
||||
icon: "mdi:current-ac"
|
||||
|
||||
##########################################################################################
|
||||
# BUTTON COMPONENT
|
||||
# Reset the trip latch from HA (does not close the relay automatically)
|
||||
# https://esphome.io/components/button/
|
||||
##########################################################################################
|
||||
button:
|
||||
- platform: template
|
||||
name: "${friendly_name} Clear Trip"
|
||||
id: btn_clear_trip
|
||||
icon: "mdi:alert-remove-outline"
|
||||
on_press:
|
||||
- logger.log: "Trip reset requested (clearing Trip Active and LED state)"
|
||||
- binary_sensor.template.publish:
|
||||
id: bs_tripped
|
||||
state: false
|
||||
- lambda: |-
|
||||
// Clear any pending debounce
|
||||
id(_oc_start_ms) = 0;
|
||||
- if:
|
||||
condition:
|
||||
and:
|
||||
- switch.is_on: relay_virtual
|
||||
- binary_sensor.is_on: bs_running
|
||||
then:
|
||||
- script.execute: led_blinker
|
||||
else:
|
||||
- light.turn_off: led
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# LATCHING RELAY CONTROL (two coils: ON and OFF)
|
||||
# P24 -> IO5 (close), P26 -> IO4 (open) per mapping.
|
||||
# Two hidden GPIO pulse switches to drive the coils.
|
||||
# User-facing switch sends a short pulse to the appropriate coil.
|
||||
##########################################################################################
|
||||
switch:
|
||||
# Hidden coil driver: ON pulse (GPIO5)
|
||||
- platform: gpio
|
||||
id: relay_on_coil
|
||||
pin:
|
||||
number: GPIO5
|
||||
inverted: false
|
||||
restore_mode: ALWAYS_OFF
|
||||
|
||||
# Hidden coil driver: OFF pulse (GPIO4)
|
||||
- platform: gpio
|
||||
id: relay_off_coil
|
||||
pin:
|
||||
number: GPIO4
|
||||
inverted: false
|
||||
restore_mode: ALWAYS_OFF
|
||||
|
||||
# User-facing virtual switch
|
||||
- platform: template
|
||||
id: relay_virtual
|
||||
name: "${relay_1_name}"
|
||||
optimistic: true
|
||||
# Use default restore behavior; "Previous State" is honored by doing nothing in on_boot.
|
||||
# Set a safe baseline here (default off if no previous state).
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
turn_on_action:
|
||||
- logger.log: "Relay ON: pulsing ON coil"
|
||||
- binary_sensor.template.publish:
|
||||
id: bs_tripped
|
||||
state: false # clear trip on manual ON
|
||||
- switch.turn_on: relay_on_coil
|
||||
- delay: 200ms
|
||||
- switch.turn_off: relay_on_coil
|
||||
- if:
|
||||
condition:
|
||||
and:
|
||||
- binary_sensor.is_on: bs_running
|
||||
- lambda: 'return !id(bs_tripped).state;'
|
||||
then:
|
||||
- script.execute: led_blinker
|
||||
turn_off_action:
|
||||
- logger.log: "Relay OFF: pulsing OFF coil"
|
||||
- switch.turn_on: relay_off_coil
|
||||
- delay: 200ms
|
||||
- switch.turn_off: relay_off_coil
|
||||
- script.stop: led_blinker
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return !id(bs_tripped).state;'
|
||||
then:
|
||||
- light.turn_off: led
|
||||
|
||||
##########################################################################################
|
||||
# OUTPUT COMPONENT
|
||||
# https://esphome.io/components/output/ledc.html
|
||||
##########################################################################################
|
||||
# RED LED AS LIGHT (P9 -> IO10, low = ON)
|
||||
##########################################################################################
|
||||
output:
|
||||
- platform: ledc
|
||||
id: pow_red_led_pwm
|
||||
pin:
|
||||
number: GPIO10
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
# https://esphome.io/components/light/monochromatic.html
|
||||
##########################################################################################
|
||||
# Hidden from HA; still used internally by scripts/logic
|
||||
light:
|
||||
- platform: monochromatic
|
||||
id: led
|
||||
output: pow_red_led_pwm
|
||||
internal: true
|
||||
|
||||
##########################################################################################
|
||||
# SELECT COMPONENT
|
||||
# Choose how the relay state should be restored after boot
|
||||
# https://esphome.io/components/select/template.html
|
||||
##########################################################################################
|
||||
select:
|
||||
- platform: template
|
||||
name: "${friendly_name} Power Restore Mode"
|
||||
id: sel_restore_mode
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
options:
|
||||
- "Always ON"
|
||||
- "Always OFF"
|
||||
- "Previous State"
|
||||
initial_option: "Previous State"
|
||||
icon: "mdi:power-settings"
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPTS
|
||||
# https://esphome.io/components/script.html
|
||||
##########################################################################################
|
||||
script:
|
||||
# LED blinker: variable-speed based on current vs n_max_trip; runs only when running, relay ON, not tripped
|
||||
- id: led_blinker
|
||||
mode: restart
|
||||
then:
|
||||
- while:
|
||||
condition:
|
||||
and:
|
||||
- switch.is_on: relay_virtual
|
||||
- binary_sensor.is_on: bs_running
|
||||
- lambda: 'return !id(bs_tripped).state;'
|
||||
then:
|
||||
# Compute and store current-period ms in _blink_period_ms
|
||||
- lambda: |-
|
||||
float i = isnan(id(pm_current).state) ? 0.0f : id(pm_current).state;
|
||||
float maxA = id(n_max_trip).state;
|
||||
if (maxA < 0.1f) maxA = 0.1f;
|
||||
float f = i / maxA; // 0.0 .. 1.0
|
||||
if (f < 0.0f) f = 0.0f;
|
||||
if (f > 1.0f) f = 1.0f;
|
||||
int slow_ms = ${led_flash_slow_ms};
|
||||
int fast_ms = ${led_flash_fast_ms};
|
||||
if (slow_ms < fast_ms) { int t = slow_ms; slow_ms = fast_ms; fast_ms = t; } # ensure slow >= fast
|
||||
int period = slow_ms - (int)((slow_ms - fast_ms) * f);
|
||||
id(_blink_period_ms) = period;
|
||||
# Blink with 50% duty cycle at the computed period
|
||||
- light.turn_on:
|
||||
id: led
|
||||
brightness: 100%
|
||||
- delay: !lambda 'return (uint32_t)(id(_blink_period_ms) / 2);'
|
||||
- light.turn_off: led
|
||||
- delay: !lambda 'return (uint32_t)(id(_blink_period_ms) / 2);'
|
834
esphome/esp-downstairskitchleds.yaml
Normal file
834
esphome/esp-downstairskitchleds.yaml
Normal file
@@ -0,0 +1,834 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# Title: DOWNSTAIRS KITCHEN - OVER PANTRY LEDS
|
||||
# Hardware: Sinilink MOSFET Board XY-WFMS (ESP8266) — sometimes listed as “XY-VFMS”
|
||||
# https://devices.esphome.io/devices/Sinilink-XY-VFMS
|
||||
# Repo: https://home.fox.co.nz/gitea/zorruno/zorruno-homeassistant/src/branch/master/esphome/esp-downstairskitchleds.yaml
|
||||
#
|
||||
# v1.4 - 2025-08-22 Improved power loss/on actions
|
||||
# v1.3 - 2025-08-22 Added a "max on time” setting (1-48 h, 0 = no limit)
|
||||
# v1.2 - 2025-08-21 Added defaults to “Device Specific Settings” in substitutions & a PWM % view
|
||||
# v1.1 - 2025-08-18 Full tidy-up as general-purpose LED strip controller
|
||||
# v1.0 - 2025-08-17 First setup (and replacement of Tasmota)
|
||||
#
|
||||
# ------------------------------------------
|
||||
# DEVICE GPIO (Sinilink XY-WFMS)
|
||||
# ------------------------------------------
|
||||
# GPIO02 Blue LED (used for ESPHome status)
|
||||
# GPIO04 MOSFET output (0 V when switched) and Red LED
|
||||
# GPIO12 Toggle button
|
||||
# GPIO13 Green LED (used to display fading status)
|
||||
#
|
||||
# ------------------------------------------
|
||||
# OPERATION (as of v1.4)
|
||||
# ------------------------------------------
|
||||
# 1. General-purpose LED controller.
|
||||
# 2. Designed for the Sinilink XY-WFMS board with a MOSFET output (claimed 5A, 5-36 V DC).
|
||||
# 3. Global setting for MAX % output to extend LED life.
|
||||
# 4. Minimum output setting; switches fully OFF at/below the minimum to avoid low-PWM flicker.
|
||||
# 5. PWM frequency is set to 500 Hz by default. You can increase it, but higher values caused
|
||||
# resets on this device. On ESP32 you can run much higher (~40 kHz).
|
||||
# 6. Min/Max output settings are not exposed in Home Assistant/MQTT by default, but can be.
|
||||
# With a 1 MB flash, space is tight and only minimal optimisation has been done so far.
|
||||
# 7. PACKAGES include common items: network settings, diagnostic entities, MQTT, and SNTP (optional).
|
||||
# 8. Default behaviour is to fade slowly up to full at power-up (so it can run with no network).
|
||||
# 9. The green LED flashes while fading (different patterns for up/down). The red LED follows the
|
||||
# output (it shares the MOSFET GPIO).
|
||||
# 10. Fade timing scales with the configured values (proportionally when starting mid-brightness).
|
||||
# 11. Useful 3D-printed case: https://cults3d.com/en/3d-model/tool/snapfit-enclosure-for-esp8266-sinilink-xy-wfms-5v-36v-mosfet-switch-module
|
||||
# 12. Exposed in Home Assistant/MQTT:
|
||||
# - Startup action
|
||||
# - Fade Up / Fade Down / Fade Stop buttons
|
||||
# - Fade Up/Down switch
|
||||
# - Normal On/Off switch (quick ramp up/down)
|
||||
# - Fade up/down times (0-60s)
|
||||
# - Output % (pre-gamma) and PWM % (post-gamma)
|
||||
# - Output Set (1-100, respects min/max)
|
||||
# - Device diagnostics (from the included package)
|
||||
# - Maximum 'on' time before automatic fade-down (1-48 h, 0 = no limit)
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
||||
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
||||
##########################################################################################
|
||||
substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-downstairskitchleds"
|
||||
friendly_name: "Downstairs Kitchen LEDs"
|
||||
description_comment: "Downstairs Kitchen Over Pantry LEDs :: Sinilink XY-WFMS"
|
||||
device_area: "Downstairs Kitchen" # Allows the ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sinilink.XY-WFMS" # Project details
|
||||
project_version: "v1.4" # Project version denotes release of the 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-downstairskitchleds_ip # Unfortunately, you can't use substitutions inside secret names
|
||||
mqtt_local_command_main_topic: !secret mqtt_local_command_main_topic
|
||||
mqtt_local_status_main_topic: !secret mqtt_local_status_main_topic
|
||||
|
||||
# MQTT LOCAL Controls
|
||||
mqtt_local_device_name: "downstairskitchen-pantryleds"
|
||||
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_local_device_name}" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_local_device_name}" # Topic we will use to view status locally without HA
|
||||
mqtt_local_device_command_ON: "ON"
|
||||
mqtt_local_device_command_OFF: "OFF"
|
||||
|
||||
# Device Specific Settings
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "20s" # Update time for general sensors, etc.
|
||||
led_gamma: "1.2" # Gamma from 1.2-3 is sensible to normalise the LED fading vs PWM
|
||||
minimum_led_output: "1" # % If at this value or below, we'll switch it completely off
|
||||
maximum_led_output: "90" # % Maximum output; it is sometimes nice to limit the output for longevity or aesthetics
|
||||
max_on_default_hours: "6" # The maximum time the LEDs will be on, in case they get left on. 0 = no automatic turn-off
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
file: common/api_common_noencryption.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
|
||||
file: common/sensors_common_lite.yaml
|
||||
vars:
|
||||
local_friendly_name: "${friendly_name}"
|
||||
local_update_interval: "${update_interval}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome CORE CONFIGURATION
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}"
|
||||
area: "${device_area}"
|
||||
on_boot:
|
||||
priority: -200
|
||||
then:
|
||||
# Keep the HA dropdown in sync with the stored mode
|
||||
- lambda: |-
|
||||
switch (id(restart_mode)) {
|
||||
case 0: id(restart_action).publish_state("Fade up to full"); break;
|
||||
case 1: id(restart_action).publish_state("Restore Brightness"); break;
|
||||
case 2: default: id(restart_action).publish_state("Remain Off"); break;
|
||||
}
|
||||
|
||||
# Mode 0: Fade up to full (obeys fade settings; no on/off flicker)
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(restart_mode) == 0;'
|
||||
then:
|
||||
- lambda: 'id(ramp_switch_target_on) = true;'
|
||||
- script.execute: ramp_on_script
|
||||
|
||||
# Mode 1: Restore Brightness using the light's normal defaults
|
||||
# (uses default_transition_length and on_turn_on handlers)
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(restart_mode) == 1;'
|
||||
then:
|
||||
- lambda: |-
|
||||
float target = id(last_brightness_pct);
|
||||
if (target < 0.0f) target = 0.0f;
|
||||
if (target > 100.0f) target = 100.0f;
|
||||
|
||||
// Gently clamp to min/max caps to avoid an immediate post-on_state correction.
|
||||
const float minp = (float) id(min_brightness_pct);
|
||||
const float maxp = (float) id(max_brightness_pct);
|
||||
if (target > 0.0f && target < minp) target = minp;
|
||||
if (target > maxp) target = maxp;
|
||||
|
||||
id(suppress_slider_sync) = true;
|
||||
if (target <= 0.0f) {
|
||||
id(ramp_switch_target_on) = false;
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
call.set_state(false);
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
} else {
|
||||
id(ramp_switch_target_on) = true;
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
call.set_state(true);
|
||||
call.set_brightness(target / 100.0f);
|
||||
// No transition_length here: use light.default_transition_length.
|
||||
call.perform();
|
||||
}
|
||||
- delay: 300ms
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
|
||||
# Mode 2: Remain Off (no blip; stays off)
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(restart_mode) == 2;'
|
||||
then:
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
- lambda: 'id(ramp_switch_target_on) = false;'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
transition_length: 0s
|
||||
|
||||
platformio_options:
|
||||
build_unflags:
|
||||
- -flto
|
||||
build_flags:
|
||||
- -fno-lto
|
||||
- -Wl,--gc-sections
|
||||
- -ffunction-sections
|
||||
- -fdata-sections
|
||||
- -DNDEBUG
|
||||
|
||||
##########################################################################################
|
||||
# ESP PLATFORM AND FRAMEWORK
|
||||
# https://esphome.io/components/esp8266.html
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
esp8266:
|
||||
board: esp01_1m
|
||||
restore_from_flash: true # restore some values on reboot
|
||||
|
||||
#preferences:
|
||||
# flash_write_interval: 5min
|
||||
|
||||
mdns:
|
||||
disabled: false # Disabling will make the build file smaller (and it is still available via static IP)
|
||||
|
||||
##########################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
# https://esphome.io/components/globals.html
|
||||
##########################################################################################
|
||||
globals:
|
||||
# Minimum Brightness % for LEDs (will switch off if <=)
|
||||
- id: min_brightness_pct
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${minimum_led_output}" # start/finish at X%
|
||||
# Maximum Brightness % for LEDs (should never go beyond this)
|
||||
- id: max_brightness_pct
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: "${maximum_led_output}" # hard cap; never exceed this
|
||||
# The maximum time the lights will stay on, in hours. Just in case they are left on. 0 = forever
|
||||
- id: max_on_hours
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '${max_on_default_hours}'
|
||||
# Default Fading Up Time (Selectable and will be retained)
|
||||
- id: ramp_up_ms # fade-in when turned ON
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '5000' # 5 s
|
||||
# Default Fading Down Time (Selectable and will be retained)
|
||||
- id: ramp_down_ms # fade-out when turned OFF
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '10000' # 10 s
|
||||
# Action on Restart. (0=Fade full, 1=Restore brightness, 2=Remain off)
|
||||
- id: restart_mode
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: '0' # default = Fade Up to Full (so can be deployed with no other setup)
|
||||
|
||||
# Determine last fade direction.
|
||||
# true when you asked the light to end up ON (Ramp Up)
|
||||
# false when you asked the light to end up OFF (Ramp Down)
|
||||
- id: ramp_switch_target_on
|
||||
type: bool
|
||||
restore_value: true
|
||||
initial_value: 'false'
|
||||
# Prevent jitter when adjusting the slider
|
||||
- id: suppress_slider_sync
|
||||
type: bool
|
||||
restore_value: false
|
||||
initial_value: 'false'
|
||||
# actual 0..100 seen last time, for restart
|
||||
- id: last_brightness_pct
|
||||
type: float
|
||||
restore_value: true
|
||||
initial_value: '0.0'
|
||||
# last published "Output Set (0-100)" integer
|
||||
- id: last_set_pos
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '-1'
|
||||
# helper to keep blink time == transition time
|
||||
- id: last_ramp_ms
|
||||
type: int
|
||||
restore_value: false
|
||||
initial_value: '0'
|
||||
|
||||
##########################################################################################
|
||||
# LOGGER COMPONENT
|
||||
# https://esphome.io/components/logger.html
|
||||
# Logs all log messages through the serial port and through MQTT topics.
|
||||
##########################################################################################
|
||||
logger:
|
||||
level: "${log_level}" # INFO Level suggested, or DEBUG for testing
|
||||
baud_rate: 0 # set to 0 for no logging via UART, needed if you are using it for other serial things (eg PZEM, Serial control)
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control to ramp up
|
||||
- topic: "${mqtt_local_command_topic}/light/set"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
then:
|
||||
- switch.turn_on: mosfet_ramp_switch
|
||||
# Light control to ramp up
|
||||
- topic: "${mqtt_local_command_topic}/light/set"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
then:
|
||||
- switch.turn_off: mosfet_ramp_switch
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
# SINILINK: Status LED Blue LED on GPIO2, active-low
|
||||
#########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2
|
||||
inverted: true
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
switch:
|
||||
# Ramp-aware ON/OFF for HA (asymmetric, eased; no bounce)
|
||||
- platform: template
|
||||
id: mosfet_ramp_switch
|
||||
name: "${friendly_name} Fade Up/Down"
|
||||
icon: mdi:led-strip-variant
|
||||
lambda: |-
|
||||
return id(ramp_switch_target_on);
|
||||
turn_on_action:
|
||||
- lambda: 'id(ramp_switch_target_on) = true;'
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_on_script
|
||||
turn_off_action:
|
||||
- lambda: 'id(ramp_switch_target_on) = false;'
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
# https://esphome.io/components/button/index.html
|
||||
#################################################################################################
|
||||
button:
|
||||
# Start ramping UP (from current level)
|
||||
- platform: template
|
||||
id: fade_up_button
|
||||
name: "${friendly_name} Fade Up"
|
||||
icon: mdi:arrow-up-bold
|
||||
on_press:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = true;
|
||||
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_on_script
|
||||
|
||||
# Start ramping DOWN (from current level)
|
||||
- platform: template
|
||||
id: fade_down_button
|
||||
name: "${friendly_name} Fade Down"
|
||||
icon: mdi:arrow-down-bold
|
||||
on_press:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
|
||||
# STOP any ramping (hold current brightness)
|
||||
- platform: template
|
||||
id: fade_stop_button
|
||||
name: "${friendly_name} Fade Stop"
|
||||
icon: mdi:pause
|
||||
on_press:
|
||||
# Stop any pending scripts (and their delayed turn_off)
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
- script.stop: led_flash_up
|
||||
- script.stop: led_flash_down
|
||||
- output.turn_off: green_led_out
|
||||
# Cancel the light's transition by commanding the current level with 0 ms,
|
||||
# but DO NOT change the ramp switch state/flag.
|
||||
- lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on()) {
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
call.set_state(true);
|
||||
call.set_brightness(cv.get_brightness());
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
# SELECT COMPONENT
|
||||
# https://esphome.io/components/select/index.html
|
||||
#########################################################################################
|
||||
select:
|
||||
- platform: template
|
||||
id: restart_action
|
||||
name: "${friendly_name} Restart Action"
|
||||
icon: mdi:restart
|
||||
optimistic: true
|
||||
options:
|
||||
- "Fade up to full"
|
||||
- "Restore Brightness"
|
||||
- "Remain Off"
|
||||
initial_option: "Restore Brightness"
|
||||
set_action:
|
||||
- lambda: |-
|
||||
if (x == "Fade up to full") {
|
||||
id(restart_mode) = 0;
|
||||
} else if (x == "Restore Brightness") {
|
||||
id(restart_mode) = 1;
|
||||
} else {
|
||||
id(restart_mode) = 2;
|
||||
}
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: btn_gpio12
|
||||
name: "${friendly_name} Button"
|
||||
pin:
|
||||
number: GPIO12
|
||||
mode:
|
||||
input: true
|
||||
pullup: true
|
||||
inverted: true
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
- delayed_off: 20ms
|
||||
on_press:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(ramp_switch_target_on);'
|
||||
then:
|
||||
# Target is currently ON → press should go OFF (start ramp-down)
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
id(mosfet_ramp_switch).publish_state(false); // reflect in HA immediately
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
||||
else:
|
||||
# Target is currently OFF → press should go ON (start ramp-up)
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = true;
|
||||
id(mosfet_ramp_switch).publish_state(true); // reflect in HA immediately
|
||||
- script.stop: ramp_off_script
|
||||
- script.execute: ramp_on_script
|
||||
|
||||
##########################################################################################
|
||||
# SENSOR COMPONENT
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
sensor:
|
||||
- platform: template
|
||||
id: mosfet_output_pct
|
||||
name: "${friendly_name} Output (%)"
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:percent
|
||||
accuracy_decimals: 0
|
||||
update_interval: 250ms # consider 200ms if you want fewer updates
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
return cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f;
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
// Remember latest actual output (0..100) for "Restore Brightness"
|
||||
id(last_brightness_pct) = x;
|
||||
|
||||
// If not suppressing sync, update the 0..100 slider only when its INT changes
|
||||
if (!id(suppress_slider_sync)) {
|
||||
float actual = x; // actual %
|
||||
float minp = (float) id(min_brightness_pct);
|
||||
float maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float pos = (actual <= 0.0f) ? 0.0f : ((actual - minp) * 100.0f / (maxp - minp));
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
int pos_i = (int) floorf(pos + 0.5f);
|
||||
|
||||
if (pos_i != id(last_set_pos)) {
|
||||
id(last_set_pos) = pos_i;
|
||||
id(led_output_set_pct).publish_state(pos_i);
|
||||
}
|
||||
}
|
||||
- platform: template
|
||||
id: mosfet_output_pwm_pct
|
||||
name: "${friendly_name} Output PWM (%)"
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:square-wave
|
||||
accuracy_decimals: 1
|
||||
update_interval: 250ms
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (!cv.is_on()) return 0.0f;
|
||||
const float lin = cv.get_brightness(); // 0..1 (linear brightness)
|
||||
const float gamma = atof("${led_gamma}"); // parse substitution string → float
|
||||
float pwm = powf(lin, gamma); // approx PWM duty after gamma
|
||||
if (pwm < 0.0f) pwm = 0.0f;
|
||||
if (pwm > 1.0f) pwm = 1.0f;
|
||||
return pwm * 100.0f;
|
||||
|
||||
##########################################################################################
|
||||
# OUTPUT COMPONENT
|
||||
# https://esphome.io/components/light/index.html
|
||||
##########################################################################################
|
||||
# An OUTPUT can be binary (0,1) or float, which is any value between 0 and 1.
|
||||
# PWM Outputs such as "ledc" are float. https://esphome.io/components/output/ledc.html
|
||||
##########################################################################################
|
||||
output:
|
||||
- platform: esp8266_pwm
|
||||
id: mosfet_pwm
|
||||
pin: GPIO4
|
||||
frequency: 500 Hz # high frequency to avoid audible/visible artifacts
|
||||
- platform: gpio
|
||||
id: green_led_out # Green LED
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: false
|
||||
|
||||
##########################################################################################
|
||||
# LIGHT COMPONENT
|
||||
# https://esphome.io/components/light/
|
||||
##########################################################################################
|
||||
light:
|
||||
- platform: monochromatic
|
||||
id: mosfet_leds
|
||||
name: "${friendly_name}"
|
||||
output: mosfet_pwm
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
default_transition_length: 2s
|
||||
icon: mdi:led-strip-variant
|
||||
gamma_correct: "${led_gamma}"
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
payload: "${mqtt_local_device_command_ON}"
|
||||
retain: true
|
||||
- lambda: 'id(ramp_switch_target_on) = true;'
|
||||
- script.stop: max_on_watchdog
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(max_on_hours) > 0;'
|
||||
then:
|
||||
- script.execute: max_on_watchdog
|
||||
on_turn_off:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light/state"
|
||||
payload: "${mqtt_local_device_command_OFF}"
|
||||
retain: true
|
||||
- lambda: 'id(ramp_switch_target_on) = false;'
|
||||
- script.stop: max_on_watchdog
|
||||
on_state:
|
||||
- lambda: |-
|
||||
const float cap = id(max_brightness_pct) / 100.0f;
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
if (cv.is_on() && cv.get_brightness() > cap + 0.001f) {
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
call.set_state(true);
|
||||
call.set_brightness(cap);
|
||||
call.set_transition_length(0);
|
||||
call.perform();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# NUMBER COMPONENT
|
||||
# https://esphome.io/components/number/
|
||||
##########################################################################################
|
||||
number:
|
||||
- platform: template
|
||||
id: cfg_ramp_up_s
|
||||
name: "${friendly_name} Fade Up Time (s)"
|
||||
entity_category: config
|
||||
unit_of_measurement: s
|
||||
icon: mdi:timer-sand
|
||||
mode: slider
|
||||
min_value: 0
|
||||
max_value: 60
|
||||
step: 1
|
||||
lambda: |-
|
||||
return (float) id(ramp_up_ms) / 1000.0f;
|
||||
set_action:
|
||||
- lambda: |-
|
||||
int secs = (int) floorf(x + 0.5f);
|
||||
if (secs < 0) secs = 0;
|
||||
if (secs > 60) secs = 60;
|
||||
id(ramp_up_ms) = secs * 1000;
|
||||
id(cfg_ramp_up_s).publish_state((float) secs);
|
||||
|
||||
- platform: template
|
||||
id: cfg_ramp_down_s
|
||||
name: "${friendly_name} Fade Down Time (s)"
|
||||
entity_category: config
|
||||
unit_of_measurement: s
|
||||
icon: mdi:timer-sand-complete
|
||||
mode: slider
|
||||
min_value: 0
|
||||
max_value: 60
|
||||
step: 1
|
||||
lambda: |-
|
||||
return (float) id(ramp_down_ms) / 1000.0f;
|
||||
set_action:
|
||||
- lambda: |-
|
||||
int secs = (int) floorf(x + 0.5f);
|
||||
if (secs < 0) secs = 0;
|
||||
if (secs > 60) secs = 60;
|
||||
id(ramp_down_ms) = secs * 1000;
|
||||
id(cfg_ramp_down_s).publish_state((float) secs);
|
||||
|
||||
- platform: template
|
||||
id: led_output_set_pct
|
||||
name: "${friendly_name} Output Set (0-100)"
|
||||
icon: mdi:tune
|
||||
mode: slider
|
||||
min_value: 0
|
||||
max_value: 100
|
||||
step: 1
|
||||
# Show current position mapped into 0..100 across [min..max]
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
float actual = cv.is_on() ? (cv.get_brightness() * 100.0f) : 0.0f; // 0..100 actual
|
||||
float minp = (float) id(min_brightness_pct);
|
||||
float maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f; // avoid div/0
|
||||
if (actual <= 0.0f) return 0.0f; // when OFF, show 0
|
||||
float pos = (actual - minp) * 100.0f / (maxp - minp);
|
||||
if (pos < 0.0f) pos = 0.0f;
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
return floorf(pos + 0.5f); // integer
|
||||
set_action:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return x <= 0.0f;'
|
||||
then:
|
||||
# 0 means OFF
|
||||
- lambda: 'id(suppress_slider_sync) = true;'
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: ramp_off_script
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
transition_length: 200ms
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
id(led_output_set_pct).publish_state(0);
|
||||
- delay: 400ms
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
else:
|
||||
# Map 1..100 - [min..max] and set ON
|
||||
- lambda: |-
|
||||
id(suppress_slider_sync) = true;
|
||||
float pos = x; // 0..100
|
||||
if (pos < 1.0f) pos = 1.0f; // 0 is OFF
|
||||
if (pos > 100.0f) pos = 100.0f;
|
||||
id(led_output_set_pct).publish_state((int) floorf(pos + 0.5f));
|
||||
- script.stop: ramp_off_script
|
||||
- script.stop: ramp_on_script
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda |-
|
||||
float pos = id(led_output_set_pct).state; // 1..100
|
||||
float minp = (float) id(min_brightness_pct);
|
||||
float maxp = (float) id(max_brightness_pct);
|
||||
if (maxp <= minp) maxp = minp + 1.0f;
|
||||
float out_pct = minp + (pos * (maxp - minp) / 100.0f);
|
||||
if (out_pct > maxp) out_pct = maxp;
|
||||
return out_pct / 100.0f;
|
||||
transition_length: 250ms
|
||||
- lambda: 'id(ramp_switch_target_on) = true;'
|
||||
- delay: 400ms
|
||||
- lambda: 'id(suppress_slider_sync) = false;'
|
||||
|
||||
- platform: template
|
||||
id: cfg_max_on_hours
|
||||
name: "${friendly_name} Max On (h)"
|
||||
entity_category: config
|
||||
unit_of_measurement: h
|
||||
icon: mdi:timer-cog
|
||||
mode: slider
|
||||
min_value: 0
|
||||
max_value: 48
|
||||
step: 1
|
||||
lambda: |-
|
||||
return (float) id(max_on_hours);
|
||||
set_action:
|
||||
- lambda: |-
|
||||
int hrs = (int) x;
|
||||
if (hrs < 0) hrs = 0;
|
||||
if (hrs > 48) hrs = 48;
|
||||
id(max_on_hours) = hrs;
|
||||
id(cfg_max_on_hours).publish_state((float) hrs);
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(mosfet_leds).current_values.is_on();'
|
||||
then:
|
||||
- script.stop: max_on_watchdog
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(max_on_hours) > 0;'
|
||||
then:
|
||||
- script.execute: max_on_watchdog
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPT COMPONENT
|
||||
# https://esphome.io/components/script.html
|
||||
# Scripts can be executed nearly anywhere in your device configuration with a single call.
|
||||
##########################################################################################
|
||||
script:
|
||||
# Blink pattern while ramping UP: quick double-blink, pause, repeat
|
||||
- id: led_flash_up
|
||||
mode: restart
|
||||
then:
|
||||
- while:
|
||||
condition:
|
||||
lambda: 'return true;'
|
||||
then:
|
||||
- output.turn_on: green_led_out
|
||||
- delay: 100ms
|
||||
- output.turn_off: green_led_out
|
||||
- delay: 100ms
|
||||
- output.turn_on: green_led_out
|
||||
- delay: 100ms
|
||||
- output.turn_off: green_led_out
|
||||
- delay: 400ms
|
||||
# Blink pattern while ramping DOWN: steady slow blink
|
||||
- id: led_flash_down
|
||||
mode: restart
|
||||
then:
|
||||
- while:
|
||||
condition:
|
||||
lambda: 'return true;'
|
||||
then:
|
||||
- output.turn_on: green_led_out
|
||||
- delay: 250ms
|
||||
- output.turn_off: green_led_out
|
||||
- delay: 250ms
|
||||
|
||||
# Script: ramp up from current level. Obey global max.
|
||||
- id: ramp_on_script
|
||||
mode: restart
|
||||
then:
|
||||
- script.stop: ramp_off_script
|
||||
- script.stop: led_flash_down
|
||||
- script.execute: led_flash_up
|
||||
# Ensure we start at at least the floor without a visible "pop".
|
||||
- if:
|
||||
condition:
|
||||
lambda: |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
const float floor = id(min_brightness_pct) / 100.0f;
|
||||
return (!cv.is_on()) || (cv.get_brightness() + 0.0005f < floor);
|
||||
then:
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: 80ms
|
||||
# Ramp from current (>= floor) to cap over a fraction of ramp_up_ms.
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(max_brightness_pct) / 100.0f;'
|
||||
transition_length: !lambda |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
const float floor = id(min_brightness_pct) / 100.0f;
|
||||
const float cap = id(max_brightness_pct) / 100.0f;
|
||||
float curr = cv.is_on() ? cv.get_brightness() : 0.0f;
|
||||
if (curr < floor) curr = floor;
|
||||
if (curr > cap) curr = cap;
|
||||
float frac = (cap - curr) / (cap - floor);
|
||||
if (frac < 0.0f) frac = 0.0f;
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
id(last_ramp_ms) = (int) (id(ramp_up_ms) * frac);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- script.stop: led_flash_up
|
||||
- output.turn_off: green_led_out
|
||||
|
||||
|
||||
# Script: ramp down from current level to floor, then cleanly cut to OFF
|
||||
- id: ramp_off_script
|
||||
mode: restart
|
||||
then:
|
||||
- script.stop: ramp_on_script
|
||||
- script.stop: led_flash_up
|
||||
- script.execute: led_flash_down
|
||||
- light.turn_on:
|
||||
id: mosfet_leds
|
||||
brightness: !lambda 'return id(min_brightness_pct) / 100.0f;'
|
||||
transition_length: !lambda |-
|
||||
const auto &cv = id(mosfet_leds).current_values;
|
||||
const float floor = id(min_brightness_pct) / 100.0f;
|
||||
float curr = cv.is_on() ? cv.get_brightness() : 0.0f;
|
||||
if (curr < floor) curr = floor;
|
||||
float frac = (curr - floor) / (1.0f - floor);
|
||||
if (frac < 0.0f) frac = 0.0f;
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
id(last_ramp_ms) = (int) (id(ramp_down_ms) * frac);
|
||||
return (uint32_t) id(last_ramp_ms);
|
||||
- delay: !lambda 'return (uint32_t) id(last_ramp_ms);'
|
||||
- light.turn_off:
|
||||
id: mosfet_leds
|
||||
transition_length: 150ms
|
||||
- delay: 150ms
|
||||
- script.stop: led_flash_down
|
||||
- output.turn_off: green_led_out
|
||||
- lambda: |-
|
||||
auto call = id(mosfet_leds).make_call();
|
||||
call.set_state(false);
|
||||
call.set_brightness(id(max_brightness_pct) / 100.0f);
|
||||
call.perform();
|
||||
- id: max_on_watchdog
|
||||
mode: restart
|
||||
then:
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(max_on_hours) > 0;'
|
||||
then:
|
||||
- delay: !lambda 'return (uint32_t) (id(max_on_hours) * 3600000UL);'
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(mosfet_leds).current_values.is_on();'
|
||||
then:
|
||||
- lambda: |-
|
||||
id(ramp_switch_target_on) = false;
|
||||
id(mosfet_ramp_switch).publish_state(false);
|
||||
- script.stop: ramp_on_script
|
||||
- script.execute: ramp_off_script
|
@@ -19,10 +19,10 @@
|
||||
#############################################
|
||||
substitutions:
|
||||
# Device Naming
|
||||
devicename: "esp-downstbathswitch"
|
||||
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
|
||||
@@ -73,7 +76,7 @@ packages:
|
||||
# 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
|
||||
|
||||
|
@@ -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
|
||||
|
187
esphome/esp-downstbedrm2lights.yaml
Normal file
187
esphome/esp-downstbedrm2lights.yaml
Normal 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: GPIO02
|
||||
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: GPIO0
|
||||
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 UNLESS it is KS-811-1 then it is GIPO12
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO12
|
||||
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
|
||||
|
||||
|
@@ -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
|
||||
@@ -32,7 +32,7 @@ substitutions:
|
||||
static_ip_address: !secret esp-downstdishwpower_ip
|
||||
|
||||
# Device Settings
|
||||
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# Device Settings
|
||||
@@ -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
|
||||
|
@@ -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
|
||||
|
224
esphome/esp-downstloungeentry.yaml
Normal file
224
esphome/esp-downstloungeentry.yaml
Normal file
@@ -0,0 +1,224 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOwNSTAIRS BEDROOM 2 LIGHTSWITCH
|
||||
# V3.6 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-downstloungeentry"
|
||||
friendly_name: "Downstairs Lounge Entry Lightswitch (1)"
|
||||
description_comment: "Downstairs Lounge Entry 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.6" # 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-downstloungeentry_ip
|
||||
mqtt_command_main_topic: !secret mqtt_local_command_main_topic
|
||||
mqtt_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-lounge-entry-light"
|
||||
#mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
#mqtt_local_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device_name: "downst-lounge-main-lights"
|
||||
mqtt_remote_device_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device_name}/light1/set"
|
||||
mqtt_remote_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device_name}/light1/state" # Topic we will use to view status locally without HA
|
||||
mqtt_remote_device_command_on: "On"
|
||||
mqtt_remote_device_command_off: "Off"
|
||||
|
||||
|
||||
# Switch/Relay/Button Naming & Icons
|
||||
#relay_icon: "mdi:lightbulb-group"
|
||||
switch_1_name: "Main Lights" # NOTE there is no physical connection to the lights on this switch
|
||||
#switch_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
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
- topic: "${mqtt_remote_status_topic}"
|
||||
payload: "${mqtt_remote_device_command_on}"
|
||||
then:
|
||||
- delay: 50ms
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return !id(Relay_1).state;' # Only turn on if currently OFF
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
- topic: "${mqtt_remote_status_topic}"
|
||||
payload: "${mqtt_remote_device_command_off}"
|
||||
then:
|
||||
- delay: 50ms
|
||||
- if:
|
||||
condition:
|
||||
lambda: 'return id(Relay_1).state;' # Only turn off if currently ON
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO02
|
||||
inverted: yes
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
binary_sensor:
|
||||
# GPIO16 for KS-811 first button UNLESS it is KS-811-1 in which case it is GPIO00
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO0
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device_command_topic}"
|
||||
payload: !lambda |-
|
||||
if (id(Relay_1).state) {
|
||||
return "${mqtt_remote_device_command_off}";
|
||||
} else {
|
||||
return "${mqtt_remote_device_command_on}";
|
||||
}
|
||||
|
||||
# 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 UNLESS it is KS-811-1 then it is GPIO12
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO12
|
||||
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
|
||||
|
||||
|
221
esphome/esp-downstloungemain.yaml
Normal file
221
esphome/esp-downstloungemain.yaml
Normal file
@@ -0,0 +1,221 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOWNSTAIRS LOUNGE MAIN LIGHTS
|
||||
# V3.5 2025-07-28 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-downstloungemain"
|
||||
friendly_name: "Downstairs Lounge Main Lightswitch (3)"
|
||||
description_comment: "Downstairs Bedroom Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Back Wall Lights (2), Spare (3)"
|
||||
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-downstloungemain_ip
|
||||
mqtt_command_main_topic: !secret mqtt_local_command_main_topic
|
||||
mqtt_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-lounge-main-lights"
|
||||
mqtt_local_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_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: "Back Wall Lights"
|
||||
switch_3_name: "Spare" # NOTE, Nothing connected to this switch output
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Light control
|
||||
- topic: "${mqtt_local_command_topic}/light1/set"
|
||||
payload: "On"
|
||||
then:
|
||||
- switch.turn_on: Relay_1
|
||||
- topic: "${mqtt_local_command_topic}/light1/set"
|
||||
payload: "Off"
|
||||
then:
|
||||
- switch.turn_off: Relay_1
|
||||
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO02
|
||||
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: GPIO16
|
||||
mode: INPUT
|
||||
inverted: True
|
||||
name: "Button 1: ${switch_1_name}"
|
||||
on_press:
|
||||
- switch.toggle: Relay_1
|
||||
# - mqtt.publish:
|
||||
# topic: "${mqtt_local_command_topic}"
|
||||
# payload: !lambda |-
|
||||
# if (id(Relay_1).state) {
|
||||
# return "${mqtt_local_command_off}";
|
||||
# } else {
|
||||
# return "${mqtt_local_command_on}";
|
||||
# }
|
||||
|
||||
# GPIO05 for second button (only for KS-811-2 Double or -3 Triple)
|
||||
- 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 UNLESS it is KS-811-1 then it is GIPO12
|
||||
- platform: gpio
|
||||
name: "Relay 1: ${switch_1_name}"
|
||||
pin: GPIO13
|
||||
id: Relay_1
|
||||
# publish status updates when the light turns on/off:
|
||||
on_turn_on:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light1/state"
|
||||
payload: "On"
|
||||
on_turn_off:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_local_status_topic}/light1/state"
|
||||
payload: "Off"
|
||||
|
||||
|
||||
# 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
|
||||
|
||||
|
187
esphome/esp-downstloungeoutside.yaml
Normal file
187
esphome/esp-downstloungeoutside.yaml
Normal file
@@ -0,0 +1,187 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOwNSTAIRS BEDROOM 2 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-downstloungeoutside"
|
||||
friendly_name: "Downstairs Lounge Outside Lights (2)"
|
||||
description_comment: "Downstairs Lounge Outside Lightswitch using a Zemismart KS-811 Double Push Button. Outside Lights (1), Spare (2)"
|
||||
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-downstloungeoutside_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: "Outside Lights"
|
||||
switch_2_name: "Spare"
|
||||
#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: 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 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
|
||||
|
||||
|
186
esphome/esp-downstmasterbedrmlights.yaml
Normal file
186
esphome/esp-downstmasterbedrmlights.yaml
Normal file
@@ -0,0 +1,186 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# DOWNSTAIRS MASTER 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-downstmasterbedrmlights"
|
||||
friendly_name: "Downstairs Master Bedroom 1 Lightswitch (2)"
|
||||
description_comment: "Downstairs Master Bedroom 1 Main Lightswitch using a Zemismart KS-811 Triple Push Button. Main Lights (1), Wardrobe Lights (2), Spare (3)"
|
||||
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 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-downstmasterbedrmlights_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: GPIO02
|
||||
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
|
||||
|
||||
|
@@ -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 #
|
||||
|
@@ -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
|
||||
@@ -358,21 +287,6 @@ sensor:
|
||||
# accuracy_decimals: 1
|
||||
# oversampling: 2x
|
||||
|
||||
################################
|
||||
# WIFI SIGNAL
|
||||
# Quality of Wifi in dBm
|
||||
# https://esphome.io/components/sensor/wifi_signal.html
|
||||
################################
|
||||
- platform: wifi_signal
|
||||
name: ${friendly_name} WiFi Signal
|
||||
update_interval: 20s
|
||||
#retain: true #retain useful if sleeping
|
||||
|
||||
- platform: uptime
|
||||
name: ${friendly_name} Uptime
|
||||
update_interval: 20s
|
||||
|
||||
|
||||
#The ld2410 sensor values
|
||||
- platform: ld2410
|
||||
light:
|
||||
@@ -489,7 +403,7 @@ binary_sensor:
|
||||
number: GPIO13
|
||||
mode:
|
||||
input: True
|
||||
pullup: False
|
||||
pullup: True
|
||||
inverted: True
|
||||
filters:
|
||||
- delayed_on: 50ms
|
||||
|
181
esphome/esp-entrancebathrmlights.yaml
Normal file
181
esphome/esp-entrancebathrmlights.yaml
Normal file
@@ -0,0 +1,181 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# ENTRANCE BATHROOM LIGHTSWITCH
|
||||
# V3.7 2025-09-34 upload to this bathroom
|
||||
# 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
|
||||
# - Light switch with light and extract fan
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-entrancebathrmlights"
|
||||
friendly_name: "Entrance Bathroom Lightswitch (2)"
|
||||
description_comment: "Entrance bathroom lightswitch using a Zemismart KS-811 Double Push Button. Main Lights (1), Extract Fan (2)"
|
||||
device_area: "Entranceway" # 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-entrancebathrmlights_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: "Extract Fan"
|
||||
#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
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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}"
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -1,6 +1,7 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# MAIN BATHROOM FAN/HEAT COMBO SWITCH
|
||||
# V1.1 2025-08-26 Minor Changes (MQTT)
|
||||
# V1.0 2025-06-01 Initial Version
|
||||
#############################################
|
||||
# Zemismart KS-811 Triple push button
|
||||
@@ -23,9 +24,9 @@ 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
|
||||
project_version: "v1.1" # 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.
|
||||
|
||||
@@ -33,46 +34,47 @@ 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-mainbathfancombo_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
#mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
|
||||
# Device Settings
|
||||
#relay_icon: "mdi:heating-coil"
|
||||
log_level: "INFO" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# MQTT Controls
|
||||
mqtt_main_command_topic: !secret mqtt_main_command_topic
|
||||
#mqtt_main_status_topic: !secret mqtt_main_status_topic
|
||||
mqtt_remote_device1_command_topic: "${mqtt_main_command_topic}/masterbath-towelrail/operation"
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device1_name: "masterbath-towelrail"
|
||||
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/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
|
||||
|
@@ -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
|
||||
|
@@ -1,9 +1,10 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# MAIN DISHWASHER POWER
|
||||
# Controlled by a Athom Smart Plug V1
|
||||
# Controlled by a Athom Smart Plug V3
|
||||
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml
|
||||
#
|
||||
# V3.4 2025-07-30 Changed to Athom V3
|
||||
# V1.1 2025-06-12 package added for energy entities
|
||||
# V1.0 2025-06-10 YAML Tidyups
|
||||
#
|
||||
@@ -18,16 +19,16 @@ substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-maindishwasherpower"
|
||||
friendly_name: "Main Dishwasher Power"
|
||||
description_comment: "Main Dishwasher Power Monitor :: Athom Smart Plug Power Monitor V1"
|
||||
description_comment: "Main Dishwasher Power Monitor :: Athom Smart Plug Power Monitor V3"
|
||||
device_area: "Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Athom Technology.Smart Plug V1" # Project Details
|
||||
project_name: "Athom Technology.Smart Plug V3" # Project Details
|
||||
project_version: "v1.1" # 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
|
||||
api_key: !secret esp-maindishwasherpower_api_key # unfortunately you can't use substitutions inside secrets names
|
||||
ota_pass: !secret esp-maindishwasherpower_ota_pass # unfortunately you can't use substitutions inside secrets names
|
||||
static_ip_address: !secret esp-maindishwasherpower_ip
|
||||
|
||||
# Device Settings
|
||||
@@ -39,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
|
||||
@@ -60,18 +68,10 @@ 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
|
||||
common_athompowermonV3: !include
|
||||
file: common/athompowermonv3_common.yaml
|
||||
vars:
|
||||
local_friendly_name: "${friendly_name}"
|
||||
local_current_limit: "${current_limit}"
|
||||
|
||||
##########################################################################################
|
||||
@@ -81,13 +81,17 @@ packages:
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" # Appears on the esphome page in HA
|
||||
comment: "${description_comment}" #Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
name_add_mac_suffix: False
|
||||
min_version: 2024.6.0
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
platformio_options:
|
||||
board_build.mcu: esp32c3
|
||||
board_build.variant: esp32c3
|
||||
board_build.flash_mode: dio
|
||||
on_boot:
|
||||
priority: 200
|
||||
then:
|
||||
@@ -97,18 +101,19 @@ esphome:
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
esp8266:
|
||||
board: esp8285
|
||||
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
|
||||
esp32:
|
||||
board: esp32-c3-devkitm-1
|
||||
flash_size: 4MB
|
||||
variant: ESP32C3
|
||||
framework:
|
||||
type: esp-idf # "esp-idf" OR "arduino". Suggested ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang.
|
||||
version: recommended # recommended, latest or dev
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 5min
|
||||
|
||||
mdns:
|
||||
disabled: false
|
||||
|
||||
#dashboard_import:
|
||||
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
|
||||
esp32_improv:
|
||||
authorizer: none
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome LOGGING
|
||||
@@ -120,15 +125,6 @@ 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: GPIO13
|
||||
inverted: True
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
@@ -136,7 +132,7 @@ status_led:
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: 3
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "Power Button"
|
||||
@@ -162,9 +158,9 @@ binary_sensor:
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Power Output"
|
||||
pin: GPIO14
|
||||
pin: GPIO05
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
|
||||
restore_mode: RESTORE_DEFAULT_ON # Ensures the relay is restored (or off) at boot
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
icon: "${relay_icon}"
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -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
|
||||
|
@@ -1,7 +1,8 @@
|
||||
#############################################
|
||||
#############################################
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# HiLink LD2410 mmWave sensor, with BME280 Temp/Hum/Pres Sensor and PIR on an ESP32
|
||||
# VERSION
|
||||
# V2.1 2025-08-25 Added some MQTT to send commands to turn on remote lights
|
||||
# V2.0 2025-06-05 YAML Tidyups
|
||||
#
|
||||
# https://github.com/patrick3399/Hi-Link_mmWave_Radar_ESPHome/tree/main
|
||||
@@ -11,51 +12,64 @@
|
||||
# https://www.simplysmart.house/blog/presence-detection-ld2410-home-assistant
|
||||
#
|
||||
# The B and C versions of this device can use Bluetooth, but we are not using it here.
|
||||
#############################################
|
||||
#############################################
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
#############################################
|
||||
##########################################################################################
|
||||
# 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-occupancystair"
|
||||
friendly_name: "Stair Occupancy and Underhouse Environment"
|
||||
description_comment: "D1 Mini ESP32 with LD2410 mmWave for internal stairwell and environment sensors for under house"
|
||||
device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Generic.ESP32" # Project Details
|
||||
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
project_version: "v2.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords
|
||||
api_key: !secret esp-occupancystair_api_key # unfortunately you can't use substitutions inside secrets names
|
||||
ota_pass: !secret esp-occupancystair_ota_pass # unfortunately you can't use substitutions inside secrets names
|
||||
# Passwords & Secrets (unfortunately you can't use substitutions inside secrets names)
|
||||
api_key: !secret esp-api_key
|
||||
ota_pass: !secret esp-ota_pass
|
||||
static_ip_address: !secret esp-occupancystair_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_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
|
||||
|
||||
#############################################
|
||||
# Included Common Packages
|
||||
# https://esphome.io/components/esphome.html
|
||||
#############################################
|
||||
# MQTT REMOTE Controls
|
||||
mqtt_remote_device1_name: "stair-footerlights"
|
||||
mqtt_remote_device1_command_topic: "${mqtt_command_main_topic}/${mqtt_remote_device1_name}/set"
|
||||
#mqtt_remote_device1_status_topic: "${mqtt_status_main_topic}/${mqtt_remote_device1_name}/state"
|
||||
mqtt_remote_device_command_ON: "ON"
|
||||
mqtt_remote_device_command_OFF: "OFF"
|
||||
|
||||
#########################################################################################
|
||||
# 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
|
||||
@@ -64,10 +78,10 @@ packages:
|
||||
local_friendly_name: "${friendly_name}"
|
||||
local_update_interval: "${update_interval}"
|
||||
|
||||
#############################################
|
||||
# ESPHome
|
||||
##########################################################################################
|
||||
# ESPHome CORE CONFIGURATION
|
||||
# https://esphome.io/components/esphome.html
|
||||
#############################################
|
||||
##########################################################################################
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
@@ -78,55 +92,67 @@ esphome:
|
||||
#priority: -200
|
||||
#then:
|
||||
|
||||
#############################################
|
||||
# ESP Platform and Framework
|
||||
##########################################################################################
|
||||
# ESP PLATFORM AND FRAMEWORK
|
||||
# https://esphome.io/components/esp8266.html
|
||||
# https://esphome.io/components/esp32.html
|
||||
#############################################
|
||||
##########################################################################################
|
||||
esp32:
|
||||
board: esp32dev
|
||||
framework:
|
||||
type: esp-idf # "esp-idf" OR "arduino". Suggested ESP-IDF Framework, or Plug Out the UART Cable Might Cause ESP32 Hang.
|
||||
version: recommended # recommended, latest or dev
|
||||
|
||||
#############################################
|
||||
# i2s bus
|
||||
##########################################################################################
|
||||
# GLOBAL VARIABLES
|
||||
# https://esphome.io/components/globals.html
|
||||
##########################################################################################
|
||||
globals:
|
||||
- id: stair_footer_auto_default_s
|
||||
type: int
|
||||
restore_value: yes
|
||||
initial_value: '20'
|
||||
|
||||
##########################################################################################
|
||||
# i2c BUS COMPONENT
|
||||
# https://esphome.io/components/i2c.html
|
||||
#############################################
|
||||
##########################################################################################
|
||||
i2c:
|
||||
sda: GPIO19
|
||||
scl: GPIO21
|
||||
scan: True
|
||||
frequency: 100kHz #10, 50, 100, 200, 800 are possible settings, 100kHz was reliable for me
|
||||
|
||||
#############################################
|
||||
# ESPHome Logging Enable
|
||||
##########################################################################################
|
||||
# LOGGER COMPONENT
|
||||
# https://esphome.io/components/logger.html
|
||||
#############################################
|
||||
# Logs all log messages through the serial port and through MQTT topics.
|
||||
##########################################################################################
|
||||
logger:
|
||||
level: INFO # 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
|
||||
|
||||
#############################################
|
||||
# Bluetooth
|
||||
# https://esphome.io/components/bluetooth_proxy.html
|
||||
# https://esphome.io/components/esp32_ble_tracker.html
|
||||
##########################################################################################
|
||||
# BLUETOOTH
|
||||
# Proxy https://esphome.io/components/bluetooth_proxy.html
|
||||
# BLE https://esphome.io/components/esp32_ble_tracker.html
|
||||
# Remember that this takes a LOT of processing. On the
|
||||
# ESP32, enable the IDF framework, and disable the
|
||||
# Web server component. Changing to the IDF framework
|
||||
# needs to be via cable not OTA to change the
|
||||
# partition setup.
|
||||
#############################################
|
||||
##########################################################################################
|
||||
#bluetooth_proxy:
|
||||
|
||||
#esp32_ble_tracker:
|
||||
|
||||
#############################################
|
||||
# UART Serial
|
||||
# hardware on EPS32, but software, and can be glitchy on ESP8266
|
||||
# https://esphome.io/components/uart.html?highlight=uart
|
||||
#############################################
|
||||
##########################################################################################
|
||||
# UART BUS
|
||||
# hardware on EPS32, but software (and can be glitchy) on ESP8266
|
||||
# https://esphome.io/components/uart.html
|
||||
##########################################################################################
|
||||
uart:
|
||||
id: ld2410_uart
|
||||
rx_pin: GPIO16 #For ESP32, you can use any pin, Recommend Use UART_2, Don't use UART_0, It might Cause Boot Fail or System Hang
|
||||
@@ -136,21 +162,23 @@ uart:
|
||||
stop_bits: 1
|
||||
parity: NONE
|
||||
|
||||
#############################################
|
||||
# General esp status LED
|
||||
#########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
#############################################
|
||||
#########################################################################################
|
||||
# ESP32 D1 Mini Board: Onboard Status LED on GPIO2, active-low
|
||||
#########################################################################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO2 #ESP32 Onboard LED
|
||||
number: GPIO2 # ESP32 Onboard LED
|
||||
ignore_strapping_warning: True #https://esphome.io/guides/faq.html#why-am-i-getting-a-warning-about-strapping-pins
|
||||
inverted: false
|
||||
|
||||
#############################################
|
||||
##########################################################################################
|
||||
# LD2410 Sensors
|
||||
# https://esphome.io/components/sensor/ld2410.html
|
||||
# https://www.hlktech.net/index.php?id=988
|
||||
#############################################
|
||||
##########################################################################################
|
||||
ld2410:
|
||||
uart_id: ld2410_uart
|
||||
#uart_id (Optional, ID): Manually specify the ID of the UART Component if you want to use multiple UART buses.
|
||||
@@ -168,6 +196,11 @@ ld2410:
|
||||
#still_energy (Optional, int): When in engineering mode, the still energy of the gate, otherwise unknown. Value between 0 and 100 inclusive. All options from Sensor.
|
||||
#ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component if you are using multiple components.
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# NUMBER COMPONENT
|
||||
# https://esphome.io/components/number/
|
||||
##########################################################################################
|
||||
#The ld2410 number values for setting thresholds
|
||||
# timeout: 5s
|
||||
# max_move_distance: 2.25m
|
||||
@@ -246,12 +279,34 @@ number:
|
||||
still_threshold:
|
||||
name: "g8 still threshold"
|
||||
|
||||
#The ld2410 select allows you to control your LD2410 Sensor.
|
||||
#distance_resolution (Optional): Control the gates distance resolution. Can be 0.75m or 0.2m. Defaults to 0.75m. All options from Select.
|
||||
#baud_rate (Optional): Control the serial port baud rate. Defaults to 256000. Once changed, all sensors will stop working until a fresh install with an updated UART Component configuration. All options from Select.
|
||||
#light_function (Optional): If set, will affect the OUT pin value, based on light threshold. Can be off, low or above. Defaults to off. All options from Select.
|
||||
#out_pin_level (Optional): Control OUT pin away value. Can be low or high. Defaults to low. All options from Select.
|
||||
#ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component if you are using multiple components.
|
||||
- platform: template
|
||||
id: stair_footer_auto_time_s
|
||||
name: "Stair Footer Lights Auto Time"
|
||||
unit_of_measurement: s
|
||||
min_value: 10
|
||||
max_value: 300
|
||||
step: 1
|
||||
optimistic: true
|
||||
restore_value: true
|
||||
initial_value: 20
|
||||
|
||||
#########################################################################################
|
||||
# SELECT COMPONENT
|
||||
# https://esphome.io/components/select/index.html
|
||||
#########################################################################################
|
||||
# LD2410 SELECT
|
||||
# distance_resolution (Optional): Control the gates distance resolution. Can be 0.75m or 0.2m.
|
||||
# Defaults to 0.75m. All options from Select.
|
||||
# baud_rate (Optional): Control the serial port baud rate. Defaults to 256000. Once changed,
|
||||
# all sensors will stop working until a fresh install with an updated UART Component
|
||||
# configuration. All options from Select.
|
||||
# light_function (Optional): If set, will affect the OUT pin value, based on light
|
||||
# threshold. Can be off, low or above. Defaults to off. All options from Select.
|
||||
# out_pin_level (Optional): Control OUT pin away value. Can be low or high. Defaults
|
||||
# to low. All options from Select.
|
||||
# ld2410_id (Optional, ID): Manually specify the ID for the LD2410 Sensor component
|
||||
# if you are using multiple components.
|
||||
#########################################################################################
|
||||
select:
|
||||
- platform: ld2410
|
||||
distance_resolution:
|
||||
@@ -263,10 +318,10 @@ select:
|
||||
out_pin_level:
|
||||
name: "${friendly_name} LD2140 Out Pin Level"
|
||||
|
||||
#############################################
|
||||
# General Sensors
|
||||
# https://esphome.io/components/sensor/index.html
|
||||
#############################################
|
||||
##########################################################################################
|
||||
# SENSOR COMPONENT
|
||||
# https://esphome.io/components/sensor/
|
||||
##########################################################################################
|
||||
sensor:
|
||||
- platform: bme280_i2c
|
||||
temperature:
|
||||
@@ -283,7 +338,8 @@ sensor:
|
||||
address: 0x76
|
||||
update_interval: "${update_interval}"
|
||||
|
||||
#The ld2410 sensor values
|
||||
# The ld2410 sensor values
|
||||
# https://esphome.io/components/sensor/ld2410/#sensor
|
||||
- platform: ld2410
|
||||
light:
|
||||
name: "Light"
|
||||
@@ -343,29 +399,59 @@ sensor:
|
||||
still_energy:
|
||||
name: "g8 still energy"
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# The ld2410 switch allows you to control your LD2410 Sensor.
|
||||
#Bluetooth switch is only useful of you have a B or C model
|
||||
# Bluetooth switch is only useful of you have a B or C model
|
||||
##########################################################################################
|
||||
switch:
|
||||
# https://esphome.io/components/sensor/ld2410/#switch
|
||||
- platform: ld2410
|
||||
engineering_mode:
|
||||
name: "${friendly_name} LD2140 Engineering Mode"
|
||||
#bluetooth:
|
||||
#name: "${friendly_name} LD2140 Control Bluetooth"
|
||||
|
||||
#The ld2410 binary sensors to get presence notification
|
||||
- platform: template
|
||||
id: stair_footer_auto_enabled
|
||||
name: "Stair Footer Lights Auto"
|
||||
optimistic: true
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
|
||||
#########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
#########################################################################################
|
||||
binary_sensor:
|
||||
# The ld2410 binary sensors to get presence notification
|
||||
# https://esphome.io/components/sensor/ld2410/#binary-sensor
|
||||
- platform: ld2410
|
||||
has_target:
|
||||
name: "mmWave Presence"
|
||||
on_press:
|
||||
- if:
|
||||
condition:
|
||||
switch.is_on: stair_footer_auto_enabled
|
||||
then:
|
||||
- script.execute: stair_footer_auto_script
|
||||
has_moving_target:
|
||||
name: "mmWave Moving Target"
|
||||
on_press:
|
||||
- if:
|
||||
condition:
|
||||
switch.is_on: stair_footer_auto_enabled
|
||||
then:
|
||||
- script.execute: stair_footer_auto_script
|
||||
has_still_target:
|
||||
name: "mmWave Still Target"
|
||||
out_pin_presence_status:
|
||||
name: "LD2140 Out Pin Presence Status"
|
||||
entity_category: diagnostic
|
||||
|
||||
#Standard PIR Sensor
|
||||
# Generic PIR Sensor
|
||||
# https://devices.esphome.io/devices/Generic-PIR
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO13
|
||||
@@ -375,8 +461,21 @@ binary_sensor:
|
||||
inverted: true
|
||||
name: "PIR Sensor"
|
||||
device_class: motion
|
||||
filters:
|
||||
- delayed_on: 50ms
|
||||
on_press:
|
||||
- if:
|
||||
condition:
|
||||
switch.is_on: stair_footer_auto_enabled
|
||||
then:
|
||||
- script.execute: stair_footer_auto_script
|
||||
|
||||
#The ld2410 button allows resetting
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
# https://esphome.io/components/button/index.html
|
||||
#################################################################################################
|
||||
# The ld2410 button allows resetting
|
||||
#################################################################################################
|
||||
button:
|
||||
- platform: ld2410
|
||||
factory_reset:
|
||||
@@ -386,13 +485,41 @@ button:
|
||||
query_params:
|
||||
name: "Query Parameters"
|
||||
|
||||
#The ld2410 text sensor allows you to get information about your LD2410 Sensor.
|
||||
#Bluetooth sensor is only useful of you have a B or C model
|
||||
#################################################################################################
|
||||
# TEXT SENSOR COMPONENT
|
||||
# https://esphome.io/components/text_sensor/
|
||||
#################################################################################################
|
||||
text_sensor:
|
||||
# The ld2410 text sensor allows you to get information about your LD2410 Sensor.
|
||||
# Bluetooth sensor is only useful of you have a B or C model
|
||||
# https://esphome.io/components/sensor/ld2410/#text-sensor
|
||||
- platform: ld2410
|
||||
version:
|
||||
name: "${friendly_name} LD2140 Firmware Version"
|
||||
#mac_address:
|
||||
#name: "${friendly_name} LD2140 BT MAC Address"
|
||||
|
||||
##########################################################################################
|
||||
# SCRIPT COMPONENT
|
||||
# https://esphome.io/components/script.html
|
||||
# Scripts can be executed nearly anywhere in your device configuration with a single call.
|
||||
##########################################################################################
|
||||
script:
|
||||
# Sends commands to turn on and off a remote light
|
||||
- id: stair_footer_auto_script
|
||||
mode: restart
|
||||
then:
|
||||
# Turn lights on (command the Top switch's footer relay)
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_ON}"
|
||||
retain: false
|
||||
|
||||
# Wait for the HA-adjustable timeout
|
||||
- delay: !lambda 'return (uint32_t)(id(stair_footer_auto_time_s).state) * 1000;'
|
||||
|
||||
# Turn lights back off
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_remote_device1_command_topic}"
|
||||
payload: "${mqtt_remote_device_command_OFF}"
|
||||
retain: false
|
||||
|
@@ -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
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
@@ -27,17 +30,17 @@ substitutions:
|
||||
friendly_name: "Office Dual Lights"
|
||||
description_comment: "Dual Office Lights (Overhead and right hand Bunker) :: Sonoff Dual R1"
|
||||
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
mqtt_device_name: "office-dual-lights"
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff Dual R1" # Project Details
|
||||
project_version: "v2.3" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords
|
||||
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
|
||||
mqtt_main_command_topic: !secret mqtt_main_command_topic
|
||||
# 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"
|
||||
@@ -45,30 +48,39 @@ substitutions:
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# MQTT Controls
|
||||
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_device_name: "office-dual-lights"
|
||||
mqtt_local_command_topic: "${mqtt_local_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
|
||||
mqtt_local_status_topic: "${mqtt_local_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
|
||||
|
||||
# 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
|
||||
|
||||
|
@@ -16,7 +16,6 @@ substitutions:
|
||||
# Device Naming
|
||||
device_name: "esp-officeelvcontrol"
|
||||
friendly_name: "Office ELV Control"
|
||||
mqtt_device_name: "office-elv-control"
|
||||
description_comment: "ELV Power Supply control in the Office (under desk) :: Sonoff Basic"
|
||||
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
@@ -28,28 +27,31 @@ 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-officeelvcontrol_ip
|
||||
mqtt_main_command_topic: !secret mqtt_main_command_topic
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
#mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:generator-portable"
|
||||
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# Device Naming
|
||||
relay_1_name: "Office ELV Power Supply"
|
||||
button_1_name: "Power Button"
|
||||
|
||||
# MQTT Controls
|
||||
mqtt_command_topic: "${mqtt_main_command_topic}/${mqtt_device_name}/operation" # 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_device_name: "office-elv-control"
|
||||
mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA
|
||||
|
||||
##########################################################################################
|
||||
# PACKAGES: Included Common Packages
|
||||
# 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 +62,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
|
||||
@@ -84,7 +88,6 @@ esphome:
|
||||
# - "-fno-exceptions" # strip C++ exceptions
|
||||
# - "-fno-rtti" # strip C++ RTTI
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
@@ -117,10 +120,10 @@ logger:
|
||||
#############################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "ELV Power Supply"
|
||||
name: "${relay_1_name}"
|
||||
pin: GPIO12
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
id: relay1
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
icon: "${relay_icon}"
|
||||
|
||||
##########################################################################################
|
||||
@@ -136,7 +139,7 @@ binary_sensor:
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "Power Button"
|
||||
name: "${button_1_name}"
|
||||
id: power_button
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
@@ -145,19 +148,27 @@ binary_sensor:
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay).state) {
|
||||
if (id(relay1).state) {
|
||||
// Relay is ON: turn it OFF
|
||||
id(relay).turn_off();
|
||||
id(relay1).turn_off();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay).turn_on();
|
||||
id(relay1).turn_on();
|
||||
}
|
||||
|
||||
# Mimics actual relay status (but not controllable)
|
||||
- platform: template
|
||||
name: "Relay Status"
|
||||
name: "${relay_1_name} Status"
|
||||
lambda: |-
|
||||
return id(relay).state;
|
||||
return id(relay1).state;
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_topic}/relay1/state"
|
||||
payload: "ON"
|
||||
on_release:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_topic}/relay1/state"
|
||||
payload: "OFF"
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
@@ -171,22 +182,18 @@ status_led:
|
||||
inverted: yes
|
||||
|
||||
##########################################################################################
|
||||
# Text Sensors
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
text_sensor:
|
||||
- platform: mqtt_subscribe
|
||||
name: "Office ELV MQTT Command"
|
||||
id: office_elv_cmd
|
||||
topic: "${mqtt_command_topic}"
|
||||
internal: true # hide from HA
|
||||
on_value:
|
||||
mqtt:
|
||||
on_message:
|
||||
# Relay 1 control
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- lambda: |-
|
||||
// payload is x (std::string)
|
||||
if (x == "ON") {
|
||||
id(relay).turn_on();
|
||||
} else if (x == "OFF") {
|
||||
id(relay).turn_off();
|
||||
}
|
||||
- switch.turn_on: relay1
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay1
|
||||
|
||||
|
@@ -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
|
||||
|
199
esphome/esp-officeusbhubpower.yaml
Normal file
199
esphome/esp-officeusbhubpower.yaml
Normal file
@@ -0,0 +1,199 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# OFFICE USB HUB POWER
|
||||
# Controlled by a Sonoff Basic R1
|
||||
#
|
||||
# V1.0 2025-06-14 Initial Version
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-officeusbhubpower"
|
||||
friendly_name: "Office USB Hub Power"
|
||||
description_comment: "Office USB Hub Power Supply control in the Office (On wall) :: Sonoff Basic"
|
||||
device_area: "Office" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
|
||||
project_version: "v1.0" # 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-officeusbhubpower_ip
|
||||
mqtt_command_main_topic: !secret mqtt_command_main_topic
|
||||
mqtt_status_main_topic: !secret mqtt_status_main_topic
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:generator-portable"
|
||||
log_level: "ERROR" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "60s" # update time for for general sensors etc
|
||||
|
||||
# Device Naming
|
||||
relay_1_name: "USB Hub Power Supply"
|
||||
button_1_name: "Power Button"
|
||||
|
||||
# MQTT Controls
|
||||
mqtt_device_name: "office-usbhub-power"
|
||||
mqtt_main_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command stuff from external without HA
|
||||
|
||||
##########################################################################################
|
||||
# PACKAGES: Included Common Packages
|
||||
# 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}"
|
||||
# platformio_options:
|
||||
# build_flags:
|
||||
# - "-Os" # optimize for size
|
||||
# - "-Wl,--gc-sections" # drop unused code/data
|
||||
# - "-fno-exceptions" # strip C++ exceptions
|
||||
# - "-fno-rtti" # strip C++ RTTI
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# 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: False
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 Relay Switch is GPIO12
|
||||
#############################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "${relay_1_name}"
|
||||
pin: GPIO12
|
||||
id: relay1
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
icon: "${relay_icon}"
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 Button is GPIO03
|
||||
#############################################
|
||||
binary_sensor:
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "${button_1_name}"
|
||||
id: power_button
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
on_click:
|
||||
- min_length: 20ms
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay1).state) {
|
||||
// Relay is ON: turn it OFF
|
||||
id(relay1).turn_off();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay1).turn_on();
|
||||
}
|
||||
|
||||
# Mimics actual relay status (but not controllable)
|
||||
- platform: template
|
||||
name: "${relay_1_name} Status"
|
||||
lambda: |-
|
||||
return id(relay1).state;
|
||||
on_press:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_topic}/relay1/state"
|
||||
payload: "ON"
|
||||
on_release:
|
||||
- mqtt.publish:
|
||||
topic: "${mqtt_topic}/relay1/state"
|
||||
payload: "OFF"
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 LED is GPIO13
|
||||
#############################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: yes
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Relay 1 control
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay1
|
||||
- topic: "${mqtt_main_topic}/relay1/set"
|
||||
payload: "OFF"
|
||||
then:
|
||||
- switch.turn_off: relay1
|
||||
|
705
esphome/esp-poollightpower.yaml
Normal file
705
esphome/esp-poollightpower.yaml
Normal file
@@ -0,0 +1,705 @@
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# POOL LIGHT POWER AND TIMER
|
||||
# Controlled by a Athom Smart Plug V1
|
||||
#
|
||||
# dashboard_import:
|
||||
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
|
||||
#
|
||||
# V2.4 2025-06-15 Changed back to an Athom V1 (esp8266)
|
||||
# V2.3 2025-06-15 Changed to an Athom V3 (esp32)
|
||||
# V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable
|
||||
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
|
||||
# V2.0 2025-06-05 YAML Tidyups
|
||||
#
|
||||
# INSTRUCTIONS
|
||||
# - It allows the device to work in a standalone timer style operation
|
||||
# - The timer has a morning and evening time (but no weekday/weekend settings)
|
||||
# - Default values are set, but changed values are remembered in flash
|
||||
# - It uses SNTP for time setting (but obviously only if wifi & networking are working)
|
||||
# - It will default to an internal timer if no wifi. To reset internal timer, reboot the device at 12pm (noon)
|
||||
# - If on a network and there is a MQTT server, you can set the on/off times via MQTT (See below commands)
|
||||
# - You can set 4 modes ON/OFF/TIMER/BOOST via MQTT. Setting BOOST gives you a oneshot operation
|
||||
# - Any new timer times set via MQTT will be remembered though a reboot
|
||||
# - On startup, or a reboot, the device will always turn on for the BOOST Duration (BOOST mode, default 2 hours)
|
||||
# - TIMER mode will always be switched on after BOOST mode is complete
|
||||
# - Home Assistant entities are set so that BOOST mode can be pressed with a button and other modes selectable with a dropdown
|
||||
# - If you need it ON continuously with no MQTT, toggle power ON/OFF 4 times within 30 seconds (with ~2 secs in between to allow it to boot)
|
||||
#
|
||||
# MQTT Commands
|
||||
# Values will be set in place on the update_interval time, not immediately
|
||||
# Use 00:00 in 24hr format for time setting. (Note there is no weekday/weekend setting)
|
||||
# mqtt_timer_topic/morning-on/06:00 : Time device will go on
|
||||
# mqtt_timer_topic/morning-off/08:00 : Time device will go off
|
||||
# mqtt_timer_topic/evening-on/09:00 : Time device will go on
|
||||
# mqtt_timer_topic/evening-off/00:00 : Time device will go off
|
||||
# mqtt_timer_topic/boost-time/0000 : Time in minutes device will temporarily go on for (1-1439)
|
||||
# mqtt_timer_topic/operation/ON : Device permanently on
|
||||
# mqtt_timer_topic/operation/OFF : Device permanently off
|
||||
# mqtt_timer_topic/operation/TIMER : Device will obey timer settings
|
||||
# mqtt_timer_topic/operation/BOOST : Turn on for (boost_duration) minutes then BOOST (also on startup)
|
||||
#
|
||||
# operation_mode:
|
||||
# 0 = OFF
|
||||
# 1 = ON
|
||||
# 2 = TIMER
|
||||
# 3 = BOOST
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# 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-poollightpower"
|
||||
friendly_name: "Pool Light Power"
|
||||
description_comment: "Pool Light Power :: Athom Smart Plug Power V1"
|
||||
device_area: "Outside" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Athom Technology.Smart Plug V1" # Project Details
|
||||
project_version: "v2.4" # 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-poollightpower_ip
|
||||
|
||||
# Device Settings
|
||||
log_level: "NONE" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
|
||||
update_interval: "10s" # update time for for general sensors etc
|
||||
|
||||
# Device Settings
|
||||
relay_icon: "mdi:power-socket-au"
|
||||
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
||||
mqtt_timer_topic: "viewroad-commands/poollight-timer" # Topics you will use to change stuff
|
||||
boost_duration_default: "180" # Minutes to stay ON in BOOST mode before reverting to TIMER
|
||||
morning_on_default: "450" # Default in minutes from midnight. Default 07:30 => 450
|
||||
morning_off_default: "450" # Default in minutes from midnight. Default 07:30 => 450 (same as ON as no need for morning schedule)
|
||||
evening_on_default: "1140" # Default in minutes from midnight. Default 19:00 => 1140
|
||||
evening_off_default: "1350" # Default in minutes from midnight. Default 22:30 => 1350 => 1440 is midnight
|
||||
|
||||
##########################################################################################
|
||||
# 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}"
|
||||
|
||||
# Device Specific included packages
|
||||
common_athompowermonV1: !include
|
||||
file: common/athompowermonv1_common.yaml
|
||||
vars:
|
||||
local_friendly_name: "${friendly_name}"
|
||||
local_current_limit: "${current_limit}"
|
||||
|
||||
##########################################################################################
|
||||
# ESPHome
|
||||
# https://esphome.io/components/esphome.html
|
||||
##########################################################################################
|
||||
esphome:
|
||||
name: "${device_name}"
|
||||
friendly_name: "${friendly_name}"
|
||||
comment: "${description_comment}" #Appears on the esphome page in HA
|
||||
area: "${device_area}"
|
||||
name_add_mac_suffix: False
|
||||
min_version: 2024.6.0
|
||||
project:
|
||||
name: "${project_name}"
|
||||
version: "${project_version}"
|
||||
#platformio_options:
|
||||
# build_unflags:
|
||||
# - -std=gnu++20
|
||||
# - -std=gnu++2a
|
||||
# build_flags:
|
||||
# - -std=gnu++11
|
||||
# - -Os
|
||||
# - -Wl,--gc-sections
|
||||
# - -fno-exceptions
|
||||
# - -fno-rtti
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# https://esphome.io/components/esp32.html
|
||||
##########################################################################################
|
||||
esp8266:
|
||||
board: esp8285
|
||||
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
|
||||
#framework:
|
||||
# version: 2.7.4
|
||||
|
||||
preferences:
|
||||
flash_write_interval: 10min
|
||||
|
||||
mdns:
|
||||
disabled: True # binary size saving
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# Global Variables for use in automations etc
|
||||
# https://esphome.io/guides/automations.html?highlight=globals#global-variables
|
||||
##########################################################################################
|
||||
globals:
|
||||
|
||||
# Tracks the time (in seconds from midnight) at the previous boot
|
||||
- id: last_boot_time_s
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
# Counts how many consecutive boots have occurred (within X seconds)
|
||||
- id: boot_count
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
# Morning On time (minutes from midnight),
|
||||
- id: morning_on
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${morning_on_default}"
|
||||
|
||||
# Morning Off time (minutes from midnight),
|
||||
- id: morning_off
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${morning_off_default}"
|
||||
|
||||
# Evening On time (minutes from midnight),
|
||||
- id: evening_on
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${evening_on_default}"
|
||||
|
||||
# Evening Off time (minutes from midnight),
|
||||
- id: evening_off
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${evening_off_default}"
|
||||
|
||||
# Boost Duration (minutes),
|
||||
- id: boost_duration
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "${boost_duration_default}"
|
||||
|
||||
####################################################
|
||||
# operation_mode:
|
||||
# 0 = OFF
|
||||
# 1 = ON
|
||||
# 2 = TIMER
|
||||
# 3 = BOOST
|
||||
####################################################
|
||||
- id: operation_mode
|
||||
type: int
|
||||
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.
|
||||
####################################################
|
||||
- id: current_mins
|
||||
type: int
|
||||
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.
|
||||
####################################################
|
||||
- id: boost_timer
|
||||
type: int
|
||||
restore_value: true
|
||||
initial_value: "0"
|
||||
|
||||
##########################################################################################
|
||||
# Text Sensors
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
##########################################################################################
|
||||
text_sensor:
|
||||
|
||||
############################
|
||||
# MQTT Subscriptions
|
||||
############################
|
||||
####################################################
|
||||
# Subscribe to the Morning On time, format "HH:MM"
|
||||
# We check x.size() == 5 and x[2] == ':',
|
||||
# then parse x.substr(0,2) and x.substr(3,2)
|
||||
# std::string uses 'substr', not 'substring'.
|
||||
####################################################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Morning On Time Setting"
|
||||
id: morning_on_topic
|
||||
topic: "${mqtt_timer_topic}/morning-on" # Stored in the format HH:MM
|
||||
internal: True
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
// Expect "HH:MM" => total length = 5, with ':'
|
||||
if (x.size() == 5 && x[2] == ':') {
|
||||
int hour = atoi(x.substr(0, 2).c_str()); // "HH"
|
||||
int minute = atoi(x.substr(3, 2).c_str()); // "MM"
|
||||
id(morning_on) = hour * 60 + minute;
|
||||
ESP_LOGI("timer","Received new Morning On: %02d:%02d", hour, minute);
|
||||
} else {
|
||||
ESP_LOGW("timer","Invalid Morning On format: %s", x.c_str());
|
||||
}
|
||||
####################################################
|
||||
# Morning Off time => "HH:MM"
|
||||
####################################################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Morning Off Time Setting"
|
||||
id: morning_off_topic
|
||||
topic: "${mqtt_timer_topic}/morning-off" # Stored in the format HH:MM
|
||||
internal: True # No need to show this in Home Assistant as there is a sensor that shows the set value
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.size() == 5 && x[2] == ':') {
|
||||
int hour = atoi(x.substr(0, 2).c_str());
|
||||
int minute = atoi(x.substr(3, 2).c_str());
|
||||
id(morning_off) = hour * 60 + minute;
|
||||
ESP_LOGI("timer","Received new Morning Off: %02d:%02d", hour, minute);
|
||||
} else {
|
||||
ESP_LOGW("timer","Invalid Morning Off format: %s", x.c_str());
|
||||
}
|
||||
####################################################
|
||||
# Evening On time => "HH:MM"
|
||||
####################################################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Evening On Time Setting"
|
||||
id: evening_on_topic
|
||||
topic: "${mqtt_timer_topic}/evening-on" # Stored in the format HH:MM
|
||||
internal: True # No need to show this in Home Assistant as there is a sensor that shows the set value
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.size() == 5 && x[2] == ':') {
|
||||
int hour = atoi(x.substr(0, 2).c_str());
|
||||
int minute = atoi(x.substr(3, 2).c_str());
|
||||
id(evening_on) = hour * 60 + minute;
|
||||
ESP_LOGI("timer","Received new Evening On: %02d:%02d", hour, minute);
|
||||
} else {
|
||||
ESP_LOGW("timer","Invalid Evening On format: %s", x.c_str());
|
||||
}
|
||||
####################################################
|
||||
# Evening Off time => "HH:MM"
|
||||
####################################################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Evening Off Time Setting"
|
||||
id: evening_off_topic
|
||||
topic: "${mqtt_timer_topic}/evening-off" # Stored in the format HH:MM
|
||||
internal: True # No need to show this in Home Assistant as there is a sensor that shows the set value
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (x.size() == 5 && x[2] == ':') {
|
||||
int hour = atoi(x.substr(0, 2).c_str());
|
||||
int minute = atoi(x.substr(3, 2).c_str());
|
||||
id(evening_off) = hour * 60 + minute;
|
||||
ESP_LOGI("timer","Received new Evening Off: %02d:%02d", hour, minute);
|
||||
} else {
|
||||
ESP_LOGW("timer","Invalid Evening Off format: %s", x.c_str());
|
||||
}
|
||||
####################################################
|
||||
# Boost duration => 1 - 1439
|
||||
####################################################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Boost Duration"
|
||||
id: boost_time_topic
|
||||
topic: "${mqtt_timer_topic}/boost-time" # Stored as an integer from 1-1439
|
||||
internal: True # No need to show this in Home Assistant as there is a sensor that shows the set value
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
// parse as integer
|
||||
char *endptr;
|
||||
long v = strtol(x.c_str(), &endptr, 10);
|
||||
|
||||
// invalid if nothing parsed, trailing chars, or out of 0–1439
|
||||
if (endptr == x.c_str() || *endptr != '\0' || v < 0 || v > 1439) {
|
||||
ESP_LOGE("boost_time", "Invalid boost_time '%s'", x.c_str());
|
||||
} else {
|
||||
id(boost_duration) = static_cast<int>(v);
|
||||
}
|
||||
|
||||
####################################################
|
||||
# Subscribe to operation mode:
|
||||
# OFF, ON, TIMER, BOOST
|
||||
# We do case-insensitive compare using strcasecmp
|
||||
# (Requires <strings.h> typically included in ESPHome)
|
||||
####################################################
|
||||
# MQTT subscription: set mode, then immediately re-evaluate relay
|
||||
- platform: mqtt_subscribe
|
||||
id: timer_operation_mode_topic
|
||||
topic: "${mqtt_timer_topic}/operation"
|
||||
internal: True # No need to show this in Home Assistant as there is a sensor that shows the set value
|
||||
on_value:
|
||||
then:
|
||||
- lambda: |-
|
||||
if (strcasecmp(x.c_str(), "TIMER") == 0) {
|
||||
id(operation_mode) = 2;
|
||||
ESP_LOGI("timer","Operation mode set to TIMER");
|
||||
} else if (strcasecmp(x.c_str(), "ON") == 0) {
|
||||
id(operation_mode) = 1;
|
||||
ESP_LOGI("timer","Operation mode set to ON");
|
||||
} else if (strcasecmp(x.c_str(), "OFF") == 0) {
|
||||
id(operation_mode) = 0;
|
||||
ESP_LOGI("timer","Operation mode set to OFF");
|
||||
} else if (strcasecmp(x.c_str(), "BOOST") == 0) {
|
||||
id(operation_mode) = 3;
|
||||
id(boost_timer) = 0;
|
||||
ESP_LOGI("timer","Operation mode set to BOOST");
|
||||
} else {
|
||||
ESP_LOGW("timer","Invalid operation mode: %s", x.c_str());
|
||||
}
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
######################################################
|
||||
# Expose the current operation mode (OFF, ON, TIMER, BOOST)
|
||||
######################################################
|
||||
- platform: template
|
||||
name: "Operation Mode State"
|
||||
lambda: |-
|
||||
// 0=OFF, 1=ON, 2=TIMER, 3=BOOST
|
||||
switch (id(operation_mode)) {
|
||||
case 0: return {"OFF"};
|
||||
case 1: return {"ON"};
|
||||
case 2: return {"TIMER"};
|
||||
case 3: return {"BOOST"};
|
||||
default: return {"UNKNOWN"};
|
||||
}
|
||||
update_interval: 5s
|
||||
|
||||
######################################################
|
||||
# Expose the "Morning On" time as a text (HH:MM)
|
||||
######################################################
|
||||
- platform: template
|
||||
name: "Timeclock: Morning On Time"
|
||||
lambda: |-
|
||||
int hour = id(morning_on) / 60;
|
||||
int minute = id(morning_on) % 60;
|
||||
// Increase to 16 for safety
|
||||
char buff[16];
|
||||
snprintf(buff, sizeof(buff), "%02d:%02d", hour, minute);
|
||||
return { std::string(buff) };
|
||||
update_interval: "${update_interval}"
|
||||
|
||||
######################################################
|
||||
# Expose the "Morning Off" time as a text (HH:MM)
|
||||
######################################################
|
||||
- platform: template
|
||||
name: "Timeclock: Morning Off Time"
|
||||
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);
|
||||
return { std::string(buff) };
|
||||
update_interval: "${update_interval}"
|
||||
|
||||
######################################################
|
||||
# Expose the "Evening On" time as a text (HH:MM)
|
||||
######################################################
|
||||
- platform: template
|
||||
name: "Timeclock: Evening On Time"
|
||||
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);
|
||||
return { std::string(buff) };
|
||||
update_interval: "${update_interval}"
|
||||
|
||||
######################################################
|
||||
# Expose the "Evening Off" time as a text (HH:MM)
|
||||
######################################################
|
||||
- platform: template
|
||||
name: "Timeclock: Evening Off Time"
|
||||
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);
|
||||
return { std::string(buff) };
|
||||
update_interval: "${update_interval}"
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "Power Button"
|
||||
id: power_button
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
on_click:
|
||||
- min_length: 20ms
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay).state) {
|
||||
// Relay is ON: turn it OFF and set mode to 0 (TIMER)
|
||||
id(relay).turn_off();
|
||||
id(operation_mode) = 2;
|
||||
} else {
|
||||
// Relay is OFF: turn it ON and set mode to 3 (BOOST)
|
||||
id(relay).turn_on();
|
||||
id(operation_mode) = 3;
|
||||
}
|
||||
|
||||
- platform: template
|
||||
name: "Relay Status"
|
||||
lambda: |-
|
||||
return id(relay).state;
|
||||
|
||||
##########################################################################################
|
||||
# Sensors
|
||||
# https://esphome.io/components/text_sensor/index.html
|
||||
##########################################################################################
|
||||
sensor:
|
||||
- platform: template
|
||||
name: "Timeclock: Boost Duration"
|
||||
id: boost_duration_time
|
||||
unit_of_measurement: "mins"
|
||||
accuracy_decimals: "0"
|
||||
update_interval: "${update_interval}"
|
||||
lambda: |-
|
||||
return id(boost_duration);
|
||||
|
||||
- platform: template
|
||||
name: "Mins from Midnight"
|
||||
id: mins_from_midnight
|
||||
unit_of_measurement: "mins"
|
||||
accuracy_decimals: "0"
|
||||
update_interval: "${update_interval}"
|
||||
internal: True # No need to show this in Home Assistant
|
||||
lambda: |-
|
||||
return id(current_mins);
|
||||
|
||||
# A value in mins if a timer is running showing how many mins left
|
||||
- platform: template
|
||||
name: "Timer Minutes Remaining"
|
||||
id: timer_minutes_remaining
|
||||
unit_of_measurement: "Mins"
|
||||
update_interval: 5s
|
||||
accuracy_decimals: "0"
|
||||
lambda: |-
|
||||
// always zero if relay is off
|
||||
if (!id(relay).state) {
|
||||
return 0;
|
||||
}
|
||||
int rem = 0;
|
||||
// only calculate for mode 2 (scheduled) or mode 3 (BOOST)
|
||||
if (id(operation_mode) == 2) {
|
||||
int a = id(morning_off) - id(current_mins);
|
||||
int b = id(evening_off) - id(current_mins);
|
||||
// if a is negative, use b; otherwise pick the smaller of a or b
|
||||
rem = (a < 0) ? b : (a < b ? a : b);
|
||||
}
|
||||
else if (id(operation_mode) == 3) {
|
||||
rem = id(boost_duration) - id(boost_timer);
|
||||
}
|
||||
// never return negative
|
||||
return rem > 0 ? rem : 0;
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
#################################################################################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
name: "Power Output"
|
||||
pin: GPIO14
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
icon: "${relay_icon}"
|
||||
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
# https://esphome.io/components/button/index.html
|
||||
#################################################################################################
|
||||
button:
|
||||
- platform: template
|
||||
name: "Boost now"
|
||||
id: boost_button
|
||||
icon: "mdi:play-circle-outline"
|
||||
on_press:
|
||||
# 1) reset BOOST timer and set mode
|
||||
- lambda: |-
|
||||
id(boost_timer) = 0;
|
||||
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
|
||||
# https://esphome.io/components/select/index.html
|
||||
#################################################################################################
|
||||
select:
|
||||
- platform: template
|
||||
name: "Operation Mode"
|
||||
id: operation_mode_select
|
||||
update_interval: 5s
|
||||
options:
|
||||
- "OFF"
|
||||
- "ON"
|
||||
- "TIMER"
|
||||
- "BOOST"
|
||||
|
||||
# show the current mode
|
||||
lambda: |-
|
||||
switch (id(operation_mode)) {
|
||||
case 1: return std::string("ON");
|
||||
case 2: return std::string("TIMER");
|
||||
case 3: return std::string("BOOST");
|
||||
default: return std::string("OFF");
|
||||
}
|
||||
|
||||
# when changed in HA, set mode & re-evaluate
|
||||
set_action:
|
||||
- lambda: |-
|
||||
if (x == "OFF") { id(operation_mode) = 0; }
|
||||
else if (x == "ON") { id(operation_mode) = 1; }
|
||||
else if (x == "TIMER") { id(operation_mode) = 2; }
|
||||
else { // BOOST
|
||||
id(boost_timer) = 0;
|
||||
id(operation_mode) = 3;
|
||||
}
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
#################################################################################################
|
||||
# SCRIPT COMPONENT
|
||||
# https://esphome.io/components/script.html
|
||||
#################################################################################################
|
||||
# Script: evaluate and drive the relay
|
||||
script:
|
||||
- id: evaluate_relay_state
|
||||
then:
|
||||
- lambda: |-
|
||||
int mode = id(operation_mode);
|
||||
|
||||
// BOOST just forces the relay on
|
||||
if (mode == 3) {
|
||||
id(relay).turn_on();
|
||||
return;
|
||||
}
|
||||
|
||||
// OFF → always off
|
||||
if (mode == 0) {
|
||||
id(relay).turn_off();
|
||||
return;
|
||||
}
|
||||
|
||||
// ON → always on
|
||||
if (mode == 1) {
|
||||
id(relay).turn_on();
|
||||
return;
|
||||
}
|
||||
|
||||
// TIMER → follow schedule windows
|
||||
{
|
||||
bool should_on = false;
|
||||
if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off))
|
||||
should_on = true;
|
||||
if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off))
|
||||
should_on = true;
|
||||
if (should_on) id(relay).turn_on();
|
||||
else id(relay).turn_off();
|
||||
}
|
||||
|
||||
#################################################################################################
|
||||
# INTERVAL COMPONENT
|
||||
# https://esphome.io/components/interval.html
|
||||
#################################################################################################
|
||||
# Interval: bumps time (even if no SNTP), then calls the script to evaluate relay state
|
||||
interval:
|
||||
- interval: "1min"
|
||||
then:
|
||||
- lambda: |-
|
||||
// — update current_mins via SNTP or fallback
|
||||
if (!id(sntp_time).now().is_valid()) {
|
||||
id(current_mins)++;
|
||||
if (id(current_mins) >= 1440) id(current_mins) = 0;
|
||||
} else {
|
||||
auto now = id(sntp_time).now();
|
||||
id(current_mins) = now.hour * 60 + now.minute;
|
||||
}
|
||||
|
||||
// — if in BOOST, advance boost_timer and expire when done
|
||||
if (id(operation_mode) == 3) {
|
||||
id(boost_timer)++;
|
||||
if (id(boost_timer) >= id(boost_duration)) {
|
||||
id(operation_mode) = 2;
|
||||
//id(mqtt_client).publish("${mqtt_timer_topic}/operation", "TIMER");
|
||||
}
|
||||
}
|
||||
- script.execute: evaluate_relay_state
|
||||
|
@@ -6,6 +6,7 @@
|
||||
# dashboard_import:
|
||||
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
|
||||
#
|
||||
# V2.3 2025-06-19 Minor changes to remember mode in reboot and to ensure offline functionality
|
||||
# V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable
|
||||
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
|
||||
# V2.0 2025-06-05 YAML Tidyups
|
||||
@@ -81,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
|
||||
@@ -102,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
|
||||
@@ -132,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
|
||||
@@ -182,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}"
|
||||
|
||||
####################################################
|
||||
@@ -218,28 +223,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"
|
||||
|
||||
##########################################################################################
|
||||
@@ -555,7 +558,7 @@ switch:
|
||||
pin: GPIO5
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF # Ensures the relay is restored (or off) at boot
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
#internal: true # Hides the switch from Home Assistant
|
||||
icon: "${relay_icon}"
|
||||
|
||||
#################################################################################################
|
||||
@@ -574,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
|
||||
|
296
esphome/esp-underhouselights.yaml
Normal file
296
esphome/esp-underhouselights.yaml
Normal file
@@ -0,0 +1,296 @@
|
||||
#############################################
|
||||
#############################################
|
||||
# UNDERHOUSE LIGHTS
|
||||
# Controlled by a Sonoff 4Ch R2
|
||||
# https://github.com/jvyoralek/homeassistant-config/blob/master/esphome/sonoff-4ch.yaml
|
||||
#
|
||||
# V1.0 2025-06-18 Initial Version
|
||||
#
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
|
||||
##########################################################################################
|
||||
# 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-underhouselights"
|
||||
friendly_name: "Underhouse Lights"
|
||||
description_comment: "Underhouse Lights Control :: Sonoff 4Ch R2"
|
||||
device_area: "Underhouse" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff 4Ch R2" # Project Details
|
||||
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# 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-underhouselights_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: "ERROR" # 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: "underhouse-lights-control"
|
||||
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"
|
||||
button_1_name: "Button 1"
|
||||
relay_1_icon: "mdi:lightbulb"
|
||||
switch_2_name: "Underhouse Storage Lights"
|
||||
button_2_name: "Button 2"
|
||||
relay_2_icon: "mdi:lightbulb"
|
||||
switch_3_name: "Spare 3"
|
||||
button_3_name: "Button 3"
|
||||
relay_3_icon: "mdi:lightbulb"
|
||||
switch_4_name: "Spare 4"
|
||||
button_4_name: "Button 4"
|
||||
relay_4_icon: "mdi:lightbulb"
|
||||
|
||||
##########################################################################################
|
||||
# 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}"
|
||||
# platformio_options:
|
||||
# build_flags:
|
||||
# - "-Os" # optimize for size
|
||||
# - "-Wl,--gc-sections" # drop unused code/data
|
||||
# - "-fno-exceptions" # strip C++ exceptions
|
||||
# - "-fno-rtti" # strip C++ RTTI
|
||||
|
||||
|
||||
##########################################################################################
|
||||
# ESP Platform and Framework
|
||||
# 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: False
|
||||
|
||||
##########################################################################################
|
||||
# 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
|
||||
|
||||
##########################################################################################
|
||||
# SWITCH COMPONENT
|
||||
# https://esphome.io/components/switch/
|
||||
##########################################################################################
|
||||
# Sonoff 4Ch R2 Relays are GPIO12,05,04,15
|
||||
#############################################
|
||||
switch:
|
||||
- platform: gpio
|
||||
id: relay1
|
||||
name: "${switch_1_name}"
|
||||
pin: GPIO12
|
||||
icon: "${relay_1_icon}"
|
||||
- platform: gpio
|
||||
id: relay2
|
||||
name: "${switch_2_name}"
|
||||
pin: GPIO5
|
||||
icon: "${relay_2_icon}"
|
||||
- platform: gpio
|
||||
id: relay3
|
||||
name: "${switch_3_name}"
|
||||
pin: GPIO4
|
||||
icon: "${relay_3_icon}"
|
||||
- platform: gpio
|
||||
id: relay4
|
||||
name: "${switch_4_name}"
|
||||
pin: GPIO15
|
||||
icon: "${relay_4_icon}"
|
||||
|
||||
##########################################################################################
|
||||
# BINARY SENSORS
|
||||
# https://esphome.io/components/binary_sensor/
|
||||
##########################################################################################
|
||||
# Sonoff 4Ch R2 Buttons are GPIO00,09,10,14
|
||||
#############################################
|
||||
binary_sensor:
|
||||
- platform: gpio
|
||||
id: button1
|
||||
name: "${button_1_name}"
|
||||
pin:
|
||||
number: GPIO0
|
||||
mode: INPUT_PULLUP
|
||||
inverted: True
|
||||
on_press:
|
||||
- switch.toggle: relay1
|
||||
- platform: gpio
|
||||
id: button2
|
||||
name: "${button_2_name}"
|
||||
pin:
|
||||
number: GPIO9
|
||||
mode: INPUT_PULLUP
|
||||
inverted: True
|
||||
on_press:
|
||||
- switch.toggle: relay2
|
||||
- platform: gpio
|
||||
id: button3
|
||||
name: "${button_3_name}"
|
||||
pin:
|
||||
number: GPIO10
|
||||
mode: INPUT_PULLUP
|
||||
inverted: True
|
||||
on_press:
|
||||
- switch.toggle: relay3
|
||||
- platform: gpio
|
||||
id: button4
|
||||
name: "${button_4_name}"
|
||||
pin:
|
||||
number: GPIO14
|
||||
mode: INPUT_PULLUP
|
||||
inverted: True
|
||||
on_press:
|
||||
- switch.toggle: relay4
|
||||
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO03
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "${switch_1_name} Remote Switch"
|
||||
id: light_button_1
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
on_click:
|
||||
- min_length: 20ms
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay1).state) {
|
||||
// Relay is ON: turn it OFF
|
||||
id(relay1).turn_off();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay1).turn_on();
|
||||
}
|
||||
- platform: gpio
|
||||
pin:
|
||||
number: GPIO02
|
||||
mode: INPUT_PULLUP
|
||||
inverted: true
|
||||
name: "${switch_2_name} Remote Switch"
|
||||
id: light_button_2
|
||||
filters:
|
||||
- delayed_on: 20ms
|
||||
on_click:
|
||||
- min_length: 20ms
|
||||
max_length: 500ms
|
||||
then:
|
||||
- lambda: |-
|
||||
if (id(relay2).state) {
|
||||
// Relay is ON: turn it OFF
|
||||
id(relay2).turn_off();
|
||||
} else {
|
||||
// Relay is OFF: turn it ON
|
||||
id(relay2).turn_on();
|
||||
}
|
||||
|
||||
##########################################################################################
|
||||
# STATUS LED
|
||||
# https://esphome.io/components/status_led.html
|
||||
##########################################################################################
|
||||
# Sonoff Basic R1 LED is GPIO13
|
||||
#############################################
|
||||
status_led:
|
||||
pin:
|
||||
number: GPIO13
|
||||
inverted: yes
|
||||
|
||||
##########################################################################################
|
||||
# MQTT COMMANDS
|
||||
# This adds device-specific MQTT command triggers to the common MQTT configuration.
|
||||
##########################################################################################
|
||||
mqtt:
|
||||
on_message:
|
||||
# Relay 1 control
|
||||
- topic: "${mqtt_local_command_topic}/relay1/set"
|
||||
payload: "ON"
|
||||
then:
|
||||
- switch.turn_on: relay1
|
||||
- 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
|
||||
|
||||
|
@@ -1,11 +1,8 @@
|
||||
basement_lights:
|
||||
name: Basement Lights
|
||||
entities:
|
||||
- switch.tasmo_s4chan_4231_underhouselights_a
|
||||
- switch.tasmo_s4chan_4231_underhouselights_b
|
||||
- switch.tasmo_sdual_7681_officelights1_a
|
||||
- switch.tasmo_sdual_7681_officelights1_b
|
||||
- switch.esp_downstkitchlights_relay_1_dining_light
|
||||
- switch.esp_downstkitchlights_relay_2_kitchen_light
|
||||
- switch.esp_officelights_relay_1_nighttime_lights
|
||||
- switch.esp_officelights_relay_2_daytime_lights
|
||||
- switch.esp_underhouselights_underhouse_entrance_lights
|
||||
- switch.esp_underhouselights_underhouse_storage_lights
|
||||
- switch.esp_laundrylights_relay_1_laundry_lights
|
||||
|
14
group/downstairs_flat_lights.yaml
Normal file
14
group/downstairs_flat_lights.yaml
Normal file
@@ -0,0 +1,14 @@
|
||||
downstairs_flat_lights:
|
||||
name: Downstairs Flat Lights
|
||||
# All the lights in the Downstairs flat
|
||||
# Doesn't include the outdoor switch lights, or bedroom wardrobe light
|
||||
entities:
|
||||
- switch.esp_downstloungemain_relay_1_main_lights # Lounge Main Lights
|
||||
- switch.esp_downstloungemain_relay_2_back_wall_lights # Lounge Back Wall Lights
|
||||
- switch.esp_downstmasterbedrmlights_relay_1_main_lights # Main Bedroom, Main Lights
|
||||
- switch.esp_downstbedrm2lights_relay_1_main_lights # Small Bedroom Room Lights
|
||||
- switch.esp_downstkitchlights_relay_2_kitchen_light # Kitchen Lights
|
||||
- switch.esp_downstkitchlights_relay_1_dining_light # Dining Lights
|
||||
- switch.esp_downstbathswitch_relay_1_main_lights # Bathroom main lights
|
||||
- switch.esp_downstbathswitch_relay_2_cabinet_light # Bathroom Cabinet Lights
|
||||
|
@@ -1,13 +0,0 @@
|
||||
foxhole_lights:
|
||||
name: Downstairs Lights
|
||||
# Doesn't include the outdoor switch lights
|
||||
entities:
|
||||
- switch.tasmo_ks811t_0707_downstloun_2a # Lounge Main Lights
|
||||
- switch.tasmo_ks811t_0707_downstloun_2b # Lounge Wall Lights
|
||||
- switch.tasmo_ks811s_3136_downstbed2_1a # Craft Room Lights
|
||||
- switch.tasmo_ks811t_3642_downstbed1_1a # Main Bedroom, Main Lights
|
||||
- switch.tasmo_ks811t_3642_downstbed1_1b # Main Bedroom, Wardrobe Light
|
||||
- switch.tasmo_ks811t_3642_downstbed1_1c # Main Bedroom, Bedside switch
|
||||
- switch.esp_downstkitchlights_relay_1_dining_light
|
||||
- switch.esp_downstkitchlights_relay_2_kitchen_light
|
||||
- switch.esp_downstkitchlights_relay_3_extract_fan
|
36
packages/health_checks.yaml
Normal file
36
packages/health_checks.yaml
Normal file
@@ -0,0 +1,36 @@
|
||||
# ---- HTTP health probe ----
|
||||
binary_sensor:
|
||||
- platform: rest
|
||||
name: Node-RED Panda Up (HTTP)
|
||||
resource: http://192.168.3.200:1880/healthz
|
||||
method: GET
|
||||
device_class: connectivity
|
||||
value_template: "{{ value_json.status == 'ok' }}"
|
||||
timeout: 3
|
||||
scan_interval: 30
|
||||
|
||||
# ---- MQTT Will/Birth probe ----
|
||||
mqtt:
|
||||
binary_sensor:
|
||||
- name: "Node-RED Panda Up (MQTT)"
|
||||
unique_id: "nodered_panda_up_mqtt"
|
||||
state_topic: "nodered/panda/status"
|
||||
payload_on: "online"
|
||||
payload_off: "offline"
|
||||
device_class: connectivity
|
||||
qos: 1
|
||||
# Optional: avoid stale 'online' if no updates arrive
|
||||
expire_after: 180
|
||||
|
||||
# ---- Combine them (true if either is up) ----
|
||||
template:
|
||||
- binary_sensor:
|
||||
- name: "Node-RED Panda Up (HTTP/MQTT)"
|
||||
unique_id: "nodered_panda_up_combined"
|
||||
device_class: connectivity
|
||||
state: >
|
||||
{{ is_state('binary_sensor.node_red_panda_up_http','on')
|
||||
or is_state('binary_sensor.node_red_panda_up_mqtt','on') }}
|
||||
availability: >
|
||||
{{ states('binary_sensor.node_red_panda_up_http') not in ['unknown','unavailable']
|
||||
or states('binary_sensor.node_red_panda_up_mqtt') not in ['unknown','unavailable'] }}
|
370
packages/moonraker_3dprinter copy.yaml.bak
Normal file
370
packages/moonraker_3dprinter copy.yaml.bak
Normal file
@@ -0,0 +1,370 @@
|
||||
rest:
|
||||
scan_interval: 5
|
||||
resource_template: "http://192.168.2.31:7125/server/files/metadata?filename={{ states(('sensor.3d_printer_current_print')) | urlencode }}"
|
||||
sensor:
|
||||
- name: printer_3d_file_metadata
|
||||
unique_id: "192.168.2.315ec44d90-419c-419c-802d-d34071639c08"
|
||||
json_attributes_path: "$.result"
|
||||
json_attributes:
|
||||
- layer_height
|
||||
- object_height
|
||||
- thumbnails
|
||||
value_template: "OK"
|
||||
|
||||
#camera:
|
||||
# Loading generic IP camera via configuration.yaml is deprecated, it will be automatically imported. Once you have confirmed correct operation, please remove 'generic' (IP camera) section(s) from configuration.yaml
|
||||
# Directions in the README.md for how to add the Thumbnail now.
|
||||
# - platform: generic
|
||||
# name: "3D Printer Thumbnail"
|
||||
# still_image_url: http://192.168.2.31:7125/server/files/gcodes/{{ states("sensor.3d_printer_object_thumbnails") }}
|
||||
# verify_ssl: false
|
||||
|
||||
# This no longer works broken in current builds https://www.home-assistant.io/blog/2022/05/04/release-20225/#breaking-changes -> MJPEG IP Camera
|
||||
# Directions in the README.md for how to add the MJPEG IP Camera now.
|
||||
# - platform: mjpeg
|
||||
# name: "3D Printer Camera"
|
||||
# still_image_url: http://192.168.2.31/webcam/?action=snapshot
|
||||
# mjpeg_url: http://192.168.2.31/webcam/?action=stream
|
||||
# verify_ssl: false
|
||||
|
||||
rest_command:
|
||||
3d_printer_emergency_stop:
|
||||
url: "http://192.168.2.31:7125/printer/emergency_stop"
|
||||
method: post
|
||||
3d_printer_firmware_restart:
|
||||
url: "http://192.168.2.31:7125/printer/firmware_restart"
|
||||
method: post
|
||||
3d_printer_cancel:
|
||||
url: "http://192.168.2.31:7125/printer/print/cancel"
|
||||
method: post
|
||||
3d_printer_pause:
|
||||
url: "http://192.168.2.31:7125/printer/print/pause"
|
||||
method: post
|
||||
3d_printer_resume:
|
||||
url: "http://192.168.2.31:7125/printer/print/resume"
|
||||
method: post
|
||||
|
||||
sensor:
|
||||
- platform: rest
|
||||
name: printer_3d_sensor
|
||||
unique_id: "192.168.2.313a0c25fa-297d-4c19-b03c-ddf04840682b"
|
||||
resource: "http://192.168.2.31:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&filament_motion_sensor%20btt_smart_filament&temperature_sensor%20Chamber_Temp"
|
||||
json_attributes_path: "$.result.status"
|
||||
json_attributes:
|
||||
- heater_bed
|
||||
- extruder
|
||||
- print_stats
|
||||
- toolhead
|
||||
- display_status
|
||||
- virtual_sdcard
|
||||
- gcode_move
|
||||
- "filament_motion_sensor btt_smart_filament_sensor"
|
||||
- "temperature_sensor Chamber_Temp"
|
||||
value_template: "OK"
|
||||
force_update: true
|
||||
scan_interval: 1
|
||||
|
||||
- platform: rest
|
||||
name: printer_3d_info
|
||||
unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6943b"
|
||||
scan_interval: 1
|
||||
resource_template: "http://192.168.2.31:7125/printer/info"
|
||||
json_attributes_path: "$.result"
|
||||
json_attributes:
|
||||
- state_message
|
||||
- state
|
||||
value_template: "OK"
|
||||
|
||||
- platform: rest
|
||||
name: printer_3d_server
|
||||
unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6949"
|
||||
scan_interval: 1
|
||||
resource_template: "http://192.168.2.31:7125/server/database/item?namespace=mainsail&key=general"
|
||||
json_attributes_path: "$.result.value"
|
||||
json_attributes:
|
||||
- printername
|
||||
value_template: "OK"
|
||||
|
||||
template:
|
||||
- binary_sensor:
|
||||
- name: 3d_printer_filament
|
||||
unique_id: "192.168.2.315ce32fc9-5e95-49e7-80e7-bfdd2cf1d1fd"
|
||||
device_class: motion
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["filament_switch_sensor Filament"]["filament_detected"] }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:printer-3d-nozzle-alert
|
||||
attributes:
|
||||
friendly_name: "Filament Detected"
|
||||
- sensor:
|
||||
- name: 3d_printer_printername
|
||||
unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796074"
|
||||
state: '{{ states.sensor.printer_3d_server.attributes["printername"]}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_server'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:printer-3d
|
||||
attributes:
|
||||
friendly_name: "Printer Name"
|
||||
- name: 3d_printer_chamber_temp
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f741"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["temperature_sensor Chamber_Temp"]["temperature"] | float(0) | round(1) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
attributes:
|
||||
friendly_name: "Chamber Actual"
|
||||
- name: 3d_printer_hotend_target
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f740"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["target"] | float(0) | round(1) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
attributes:
|
||||
friendly_name: "Hotend Target"
|
||||
- name: 3d_printer_hotend_actual
|
||||
unique_id: "192.168.2.317c2593fb-a7dd-4ed7-a865-2e4dddddbb40"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["temperature"] | float(0) | round(1) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
attributes:
|
||||
friendly_name: "Hotend Actual"
|
||||
- name: 3d_printer_hotend_power
|
||||
unique_id: "192.168.2.31c57a1e35-92fa-403e-b3cf-ec1e97ef94cf"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["power"] | float(0) | round(3) * 100}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:flash
|
||||
attributes:
|
||||
friendly_name: "Hotend Power"
|
||||
- name: 3d_printer_bed_target
|
||||
unique_id: "192.168.2.31eadec415-c281-4814-8fba-17c6c42670ec"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["target"] | float(0) | round(1) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
attributes:
|
||||
friendly_name: "Bed Target"
|
||||
- name: 3d_printer_bed_actual
|
||||
unique_id: "192.168.2.31cb33503c-c5d4-4e06-b79b-c1cd64ca2d7a"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["temperature"] | float(0) | round(1) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
attributes:
|
||||
friendly_name: "Bed Actual"
|
||||
- name: 3d_printer_bed_power
|
||||
unique_id: "192.168.2.31abb2fc5b-8173-4131-a942-fb11e30f4efa"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["power"] | float(0) | round(3) * 100 }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:flash
|
||||
attributes:
|
||||
friendly_name: "Bed Power"
|
||||
- name: 3d_printer_state
|
||||
unique_id: "192.168.2.31758ce84c-3210-4f29-b6b3-38139180de96"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: >
|
||||
{% set val = states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] %}
|
||||
{% if val == 'standby' %}
|
||||
mdi:sleep
|
||||
{% elif val == 'error' %}
|
||||
mdi:alert-circle
|
||||
{% elif val == 'printing' %}
|
||||
mdi:printer-3d-nozzle
|
||||
{% elif val == 'paused' %}
|
||||
mdi:pause-circle
|
||||
{% elif val == 'complete' %}
|
||||
mdi:printer-3d
|
||||
{% else %}
|
||||
mdi:help-circle
|
||||
{% endif %}
|
||||
attributes:
|
||||
friendly_name: "Printer State"
|
||||
- name: 3d_printer_current_print
|
||||
unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796072"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["filename"]}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:file
|
||||
attributes:
|
||||
friendly_name: "Current Print"
|
||||
- name: 3d_printer_current_progress
|
||||
unique_id: "192.168.2.318ec7163b-be00-4a10-8051-48cf9a260a29"
|
||||
state: '{{ ((states.sensor.printer_3d_sensor.attributes["display_status"]["progress"])*100) | round(0, "floor") }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:progress-clock
|
||||
attributes:
|
||||
friendly_name: "Progress"
|
||||
- name: 3d_printer_print_time
|
||||
unique_id: "192.168.2.31e1ac0fac-e8ba-4e05-8fa0-c8d8076f9f63"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] |timestamp_custom("%H:%M:%S", 0)}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:camera-timer
|
||||
attributes:
|
||||
friendly_name: "Time Elapsed"
|
||||
- name: 3d_printer_time_remaining
|
||||
unique_id: "192.168.2.31e12c8def-5ebe-43a4-9f75-605a0c46fc0f"
|
||||
state: '{{ (((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]>0 else 0)) | timestamp_custom("%H:%M:%S", 0)}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:timer-sand
|
||||
attributes:
|
||||
friendly_name: "Time Remaining"
|
||||
- name: 3d_printer_eta
|
||||
unique_id: "192.168.2.31a2b57068-9a32-4d2c-8cc9-57d2389a9082"
|
||||
state: '{{ (as_timestamp(now())+((states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]/states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]>0 else 0)) | timestamp_custom("%H:%M:%S", 1)}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:av-timer
|
||||
attributes:
|
||||
friendly_name: "ETA"
|
||||
- name: 3d_printer_message
|
||||
unique_id: "192.168.2.310c418c0d-e59e-4d4e-aa11-8fae53df58f8"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["display_status"]["message"]}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:message-cog
|
||||
attributes:
|
||||
friendly_name: "Message"
|
||||
- name: 3d_printer_layer_height
|
||||
unique_id: "192.168.2.316cca455d-c327-4567-b886-4d7f99714265"
|
||||
state: '{{ states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-collapse-down
|
||||
attributes:
|
||||
friendly_name: "Layer Height"
|
||||
- name: 3d_printer_object_height
|
||||
unique_id: "192.168.2.316d6d9dc0-9a02-4ce4-a797-c84b42e011a6"
|
||||
state: '{{ (states.sensor.printer_3d_file_metadata.attributes["object_height"] | float(0)) - (states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0)) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-expand-vertical
|
||||
attributes:
|
||||
friendly_name: "Object Height"
|
||||
- name: 3d_printer_current_height
|
||||
unique_id: "192.168.2.31d440e568-d4d1-4b3f-85c4-fdacd68c0e1a"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["gcode_move"]["gcode_position"][2] | float(0) | round(2) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-collapse-down
|
||||
attributes:
|
||||
friendly_name: "Current Height"
|
||||
- name: 3d_printer_current_layer
|
||||
unique_id: "192.168.2.316a77acc1-8134-4354-b2f6-390adab81993"
|
||||
state: '{{ (states("sensor.3d_printer_current_height")|float(0) / states("sensor.3d_printer_layer_height")|float(0))|round(0) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_current_height','sensor.3d_printer_layer_height'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:counter
|
||||
attributes:
|
||||
friendly_name: "Current Layer"
|
||||
- name: 3d_printer_total_layers
|
||||
unique_id: "192.168.2.3153cfe906-28ec-44cd-926a-b08ffb8766e5"
|
||||
state: '{{ (states("sensor.3d_printer_object_height")|float(0) / states("sensor.3d_printer_layer_height")|float(0))|round(0) }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_object_height','sensor.3d_printer_layer_height'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:counter
|
||||
attributes:
|
||||
friendly_name: "Total Layer"
|
||||
- name: 3d_printer_actual_layer
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f742"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["current_layer"] }} / {{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["total_layer"] }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:layers-triple
|
||||
attributes:
|
||||
friendly_name: "Actual Layer"
|
||||
- name: 3d_printer_object_thumbnails
|
||||
unique_id: "192.168.2.3159b37837-b751-4d31-98c2-516a52edf833"
|
||||
state: >
|
||||
{% set dir = states('sensor.3d_printer_current_print') %}
|
||||
{% set thumb = state_attr('sensor.printer_3d_file_metadata','thumbnails') %}
|
||||
{% set img = (thumb | last).relative_path if thumb else 'not available' %}
|
||||
{{ (dir.split('/')[:-1] + [img]) | join('/') }}
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:image
|
||||
attributes:
|
||||
friendly_name: "Object Thumbnails"
|
||||
- name: 3d_printer_state_message
|
||||
unique_id: "192.168.2.319a5184c9-ac5b-44a9-a691-2b67c243d197"
|
||||
state: '{{ states.sensor.printer_3d_info.attributes["state_message"] }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_info'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:message-cog
|
||||
attributes:
|
||||
friendly_name: "State Message"
|
||||
- name: 3d_printer_heaters_power
|
||||
unique_id: "192.168.2.313988e9be-c910-4634-8205-38d53170d5a5"
|
||||
state: '{{ states("sensor.3d_printer_bed_power")|float(0) | round(1) }}% / {{ states("sensor.3d_printer_hotend_power")|float(0) | round(1) }}%'
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_bed_power','sensor.3d_printer_hotend_power'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
icon: mdi:meter-electric-outline
|
||||
attributes:
|
||||
friendly_name: "Bed and Nozzle Power"
|
197
packages/moonraker_3dprinter.yaml
Normal file
197
packages/moonraker_3dprinter.yaml
Normal file
@@ -0,0 +1,197 @@
|
||||
# === Add friendly names, icons, and area for printer controls ===
|
||||
homeassistant:
|
||||
customize:
|
||||
rest_command.3d_printer_emergency_stop:
|
||||
friendly_name: "Emergency Stop (K1C)"
|
||||
area_id: Laundry
|
||||
icon: mdi:alert-octagon
|
||||
|
||||
rest_command.3d_printer_firmware_restart:
|
||||
friendly_name: "Firmware Restart (K1C)"
|
||||
area_id: Laundry
|
||||
icon: mdi:restart
|
||||
|
||||
rest_command.3d_printer_cancel:
|
||||
friendly_name: "Cancel Print (K1C)"
|
||||
area_id: Laundry
|
||||
icon: mdi:cancel
|
||||
|
||||
rest_command.3d_printer_pause:
|
||||
friendly_name: "Pause Print (K1C)"
|
||||
area_id: Laundry
|
||||
icon: mdi:pause-circle
|
||||
|
||||
rest_command.3d_printer_resume:
|
||||
friendly_name: "Resume Print (K1C)"
|
||||
area_id: Laundry
|
||||
icon: mdi:play-circle
|
||||
|
||||
sensor.printer_3d_file_metadata:
|
||||
area_id: Laundry
|
||||
friendly_name: "3D Printer (K1C) Print file data"
|
||||
|
||||
sensor.printer_3d_sensor:
|
||||
area_id: Laundry
|
||||
friendly_name: "3D Printer (K1C) Sensors"
|
||||
|
||||
sensor.printer_3d_info:
|
||||
area_id: Laundry
|
||||
friendly_name: "3D Printer (K1C) State"
|
||||
|
||||
sensor.printer_3d_server:
|
||||
area_id: Laundry
|
||||
friendly_name: "3D Printer (K1C) Print Server"
|
||||
|
||||
sensor.3d_printer_chamber_temp:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_hotend_target:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_hotend_actual:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_hotend_power:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_bed_target:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_bed_actual:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_bed_power:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_state:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_current_print:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_current_progress:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_print_time:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_time_remaining:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_eta:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_message:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_layer_height:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_object_height:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_current_height:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_current_layer:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_total_layers:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_actual_layer:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_object_thumbnails:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_state_message:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_heaters_power:
|
||||
area_id: Laundry
|
||||
|
||||
sensor.3d_printer_printername:
|
||||
area_id: Laundry
|
||||
|
||||
binary_sensor.3d_printer_filament:
|
||||
area_id: Laundry
|
||||
|
||||
# === REST sensor: File metadata for current 3D print ===
|
||||
rest:
|
||||
scan_interval: 5
|
||||
resource_template: "http://192.168.2.31:7125/server/files/metadata?filename={{ states('sensor.3d_printer_current_print') | urlencode }}"
|
||||
sensor:
|
||||
- name: printer_3d_file_metadata
|
||||
unique_id: "192.168.2.315ec44d90-419c-419c-802d-d34071639c08"
|
||||
icon: mdi:file-document-outline
|
||||
json_attributes_path: "$.result"
|
||||
json_attributes:
|
||||
- layer_height
|
||||
- object_height
|
||||
- thumbnails
|
||||
value_template: "OK"
|
||||
|
||||
rest_command:
|
||||
3d_printer_emergency_stop:
|
||||
url: "http://192.168.2.31:7125/printer/emergency_stop"
|
||||
method: post
|
||||
3d_printer_firmware_restart:
|
||||
url: "http://192.168.2.31:7125/printer/firmware_restart"
|
||||
method: post
|
||||
3d_printer_cancel:
|
||||
url: "http://192.168.2.31:7125/printer/print/cancel"
|
||||
method: post
|
||||
3d_printer_pause:
|
||||
url: "http://192.168.2.31:7125/printer/print/pause"
|
||||
method: post
|
||||
3d_printer_resume:
|
||||
url: "http://192.168.2.31:7125/printer/print/resume"
|
||||
method: post
|
||||
|
||||
sensor:
|
||||
# === REST sensor: Full 3D printer status (Klipper printer/objects/query) ===
|
||||
- platform: rest
|
||||
name: printer_3d_sensor
|
||||
unique_id: "192.168.2.313a0c25fa-297d-4c19-b03c-ddf04840682b"
|
||||
icon: mdi:printer-3d-nozzle
|
||||
resource: "http://192.168.2.31:7125/printer/objects/query?heater_bed&extruder&print_stats&toolhead&display_status&virtual_sdcard&gcode_move&filament_motion_sensor%20btt_smart_filament&temperature_sensor%20Chamber_Temp"
|
||||
json_attributes_path: "$.result.status"
|
||||
json_attributes:
|
||||
- heater_bed
|
||||
- extruder
|
||||
- print_stats
|
||||
- toolhead
|
||||
- display_status
|
||||
- virtual_sdcard
|
||||
- gcode_move
|
||||
- "filament_motion_sensor btt_smart_filament_sensor"
|
||||
- "temperature_sensor Chamber_Temp"
|
||||
value_template: "OK"
|
||||
force_update: true
|
||||
scan_interval: 1
|
||||
|
||||
# === REST sensor: Basic printer state and message ===
|
||||
- platform: rest
|
||||
name: printer_3d_info
|
||||
unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6943b"
|
||||
icon: mdi:information-outline
|
||||
scan_interval: 1
|
||||
resource_template: "http://192.168.2.31:7125/printer/info"
|
||||
json_attributes_path: "$.result"
|
||||
json_attributes:
|
||||
- state_message
|
||||
- state
|
||||
value_template: "OK"
|
||||
|
||||
# === REST sensor: Server configuration details (e.g., printer name) ===
|
||||
- platform: rest
|
||||
name: printer_3d_server
|
||||
unique_id: "192.168.2.311cba6677-02bd-4273-9083-b8301bf6949"
|
||||
icon: mdi:server
|
||||
scan_interval: 1
|
||||
resource_template: "http://192.168.2.31:7125/server/database/item?namespace=mainsail&key=general"
|
||||
json_attributes_path: "$.result.value"
|
||||
json_attributes:
|
||||
- printername
|
||||
value_template: "OK"
|
@@ -30,33 +30,33 @@ mqtt:
|
||||
retain: true
|
||||
availability:
|
||||
- topic: "obk/obk-ks811t-006D-garageentry/connected"
|
||||
- unique_id: "Main_Bathroom_Light_Switch_1"
|
||||
name: "Main Bathroom Light Switch 1"
|
||||
state_topic: "obk/obk-ks811t-B1C4-mainbath1/1/get"
|
||||
command_topic: "obk/obk-ks811t-B1C4-mainbath1/1/set"
|
||||
qos: 1
|
||||
payload_on: 1
|
||||
payload_off: 0
|
||||
retain: true
|
||||
availability:
|
||||
- topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
- unique_id: "Main_Bathroom_Light_Switch_2"
|
||||
name: "Main Bathroom Light Switch 2"
|
||||
state_topic: "obk/obk-ks811t-B1C4-mainbath1/2/get"
|
||||
command_topic: "obk/obk-ks811t-B1C4-mainbath1/2/set"
|
||||
qos: 1
|
||||
payload_on: 1
|
||||
payload_off: 0
|
||||
retain: true
|
||||
availability:
|
||||
- topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
- unique_id: "Main_Bathroom_Light_Switch_3"
|
||||
name: "Main Bathroom Light Switch 3"
|
||||
state_topic: "obk/obk-ks811t-B1C4-mainbath1/3/get"
|
||||
command_topic: "obk/obk-ks811t-B1C4-mainbath1/3/set"
|
||||
qos: 1
|
||||
payload_on: 1
|
||||
payload_off: 0
|
||||
retain: true
|
||||
availability:
|
||||
- topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
# - unique_id: "Main_Bathroom_Light_Switch_1"
|
||||
# name: "Main Bathroom Light Switch 1"
|
||||
# state_topic: "obk/obk-ks811t-B1C4-mainbath1/1/get"
|
||||
# command_topic: "obk/obk-ks811t-B1C4-mainbath1/1/set"
|
||||
# qos: 1
|
||||
# payload_on: 1
|
||||
# payload_off: 0
|
||||
# retain: true
|
||||
# availability:
|
||||
# - topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
# - unique_id: "Main_Bathroom_Light_Switch_2"
|
||||
# name: "Main Bathroom Light Switch 2"
|
||||
# state_topic: "obk/obk-ks811t-B1C4-mainbath1/2/get"
|
||||
# command_topic: "obk/obk-ks811t-B1C4-mainbath1/2/set"
|
||||
# qos: 1
|
||||
# payload_on: 1
|
||||
# payload_off: 0
|
||||
# retain: true
|
||||
# availability:
|
||||
# - topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
# - unique_id: "Main_Bathroom_Light_Switch_3"
|
||||
# name: "Main Bathroom Light Switch 3"
|
||||
# state_topic: "obk/obk-ks811t-B1C4-mainbath1/3/get"
|
||||
# command_topic: "obk/obk-ks811t-B1C4-mainbath1/3/set"
|
||||
# qos: 1
|
||||
# payload_on: 1
|
||||
# payload_off: 0
|
||||
# retain: true
|
||||
# availability:
|
||||
# - topic: "obk/obk-ks811t-B1C4-mainbath1/connected"
|
||||
|
@@ -22,12 +22,12 @@ automation:
|
||||
to: "on"
|
||||
condition:
|
||||
condition: state
|
||||
entity_id: switch.esp_poollightspower_power_output
|
||||
entity_id: switch.esp_poollightpower_power_output
|
||||
state: "off"
|
||||
action:
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "viewroad-commands/poollights-timer/operation"
|
||||
topic: "viewroad-commands/poollight-timer/operation"
|
||||
payload: "BOOST"
|
||||
|
||||
- alias: "Pool Lights → send OFF & schedule TIMER when user turns UI switch OFF"
|
||||
@@ -37,12 +37,12 @@ automation:
|
||||
to: "off"
|
||||
condition:
|
||||
condition: state
|
||||
entity_id: switch.esp_poollightspower_power_output
|
||||
entity_id: switch.esp_poollightpower_power_output
|
||||
state: "on"
|
||||
action:
|
||||
- service: mqtt.publish
|
||||
data:
|
||||
topic: "viewroad-commands/poollights-timer/operation"
|
||||
topic: "viewroad-commands/poollight-timer/operation"
|
||||
payload: "OFF"
|
||||
- service: input_boolean.turn_on
|
||||
data:
|
||||
@@ -68,12 +68,12 @@ automation:
|
||||
- alias: "Pool Lights → sync UI switch with real output (no MQTT)"
|
||||
trigger:
|
||||
platform: state
|
||||
entity_id: switch.esp_poollightspower_power_output
|
||||
entity_id: switch.esp_poollightpower_power_output
|
||||
action:
|
||||
- choose:
|
||||
- conditions:
|
||||
- condition: state
|
||||
entity_id: switch.esp_poollightspower_power_output
|
||||
entity_id: switch.esp_poollightpower_power_output
|
||||
state: "on"
|
||||
sequence:
|
||||
- service: input_boolean.turn_on
|
||||
@@ -84,7 +84,7 @@ automation:
|
||||
entity_id: input_boolean.timer_light_midnight_pending
|
||||
- conditions:
|
||||
- condition: state
|
||||
entity_id: switch.esp_poollightspower_power_output
|
||||
entity_id: switch.esp_poollightpower_power_output
|
||||
state: "off"
|
||||
sequence:
|
||||
- service: input_boolean.turn_off
|
||||
|
@@ -1,23 +1,15 @@
|
||||
switch:
|
||||
- platform: group
|
||||
name: Simulation Lights
|
||||
# Lights included in 'away from home' random pattern
|
||||
group:
|
||||
simulation_lights_all:
|
||||
name: Simulation Lights (All)
|
||||
entities:
|
||||
- switch.tasmo_ks811d_1242_entrance_a # Entranceway Main Lights
|
||||
- switch.tasmo_ks811d_0302_entrybath_a # Entranceway Guest Bathroom Lights
|
||||
- switch.tasmo_ks811d_6110_kitchen_a # Main Kitchen, Main Lights
|
||||
- switch.tasmo_ks811d_6110_kitchen_b # Main Kitchen, Bench Lights
|
||||
- switch.main_hallway_lightswitch_tasmo_ks811s_2940_hallway_1a # Hallway Main Lights
|
||||
- switch.tasmo_ks811d_1701_stairs_2a # Stairs, Lower ceiling lights
|
||||
- switch.tasmo_ks811t_0702_lounge_3a # Lounge Main, South
|
||||
- switch.tasmo_ks811t_0702_lounge_3b # Lounge Main, Middle
|
||||
- switch.tasmo_ks811t_0702_lounge_3c # Lounge Main, North (above stairs)
|
||||
- switch.tasmo_ks811t_0707_downstloun_2a # Foxhole Lounge Main Lights
|
||||
- switch.tasmo_ks811t_0707_downstloun_2b # Foxhole Lounge Wall Lights
|
||||
- switch.tasmo_ks811s_3136_downstbed2_1a # Foxhole Craft Room Lights
|
||||
- switch.tasmo_ks811t_3642_downstbed1_1a # Foxhole Main Bedroom, Main Lights
|
||||
- switch.tasmo_s4chan_4231_underhouselights_b # Underhouse Main Lights
|
||||
- switch.esp_downstkitchlights_relay_1_dining_light
|
||||
- switch.esp_downstkitchlights_relay_2_kitchen_light
|
||||
- switch.esp_downstbathswitch_relay_1_main_lights
|
||||
- switch.esp_downstbathswitch_relay_2_cabinet_light
|
||||
- switch.esp_centralstairs_top_relay_2_stair_footer_lights
|
||||
- switch.esp_centralstairs_bottom_relay_1_main_stair_lights_lower
|
||||
- switch.esp_entrancebathrmlights_relay_1_main_lights
|
||||
- group.downstairs_flat_lights # ← now valid here
|
||||
- switch.tasmo_ks811d_1242_entrance_a
|
||||
- switch.tasmo_ks811d_6110_kitchen_a
|
||||
- switch.tasmo_ks811d_6110_kitchen_b
|
||||
- switch.main_hallway_lightswitch_tasmo_ks811s_2940_hallway_1a
|
||||
- switch.tasmo_ks811t_0702_lounge_3a
|
||||
- switch.tasmo_ks811t_0702_lounge_3b
|
||||
- switch.tasmo_ks811t_0702_lounge_3c
|
||||
|
308
templates/moonraker_3dprinter.yaml
Normal file
308
templates/moonraker_3dprinter.yaml
Normal file
@@ -0,0 +1,308 @@
|
||||
- binary_sensor:
|
||||
- name: 3D Printer (K1C) Filament
|
||||
unique_id: "192.168.2.315ce32fc9-5e95-49e7-80e7-bfdd2cf1d1fd"
|
||||
device_class: motion
|
||||
state: >
|
||||
{% set attr = states.sensor.printer_3d_sensor.attributes.get("filament_switch_sensor Filament") %}
|
||||
{{ attr.filament_detected if attr is defined else false }}
|
||||
icon: mdi:printer-3d-nozzle-alert
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Filament Detected"
|
||||
|
||||
- sensor:
|
||||
- name: 3D Printer (K1C) Printer Name
|
||||
unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796074"
|
||||
state: '{{ states.sensor.printer_3d_server.attributes["printername"] }}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_server'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
icon: mdi:printer-3d
|
||||
attributes:
|
||||
friendly_name: "Printer Name"
|
||||
|
||||
# === Sensor: Chamber temperature (actual) ===
|
||||
- name: 3D Printer (K1C) Chamber Temp
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f741"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["temperature_sensor Chamber_Temp"]["temperature"] | float(0) | round(1) }}'
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }}
|
||||
attributes:
|
||||
friendly_name: "Chamber Actual"
|
||||
|
||||
# === Sensor: Hotend target temperature ===
|
||||
- name: 3D Printer (K1C) Hotend Target
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f740"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["target"] | float(0) | round(1) }}'
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }}
|
||||
attributes:
|
||||
friendly_name: "Hotend Target"
|
||||
|
||||
# === Sensor: Hotend actual temperature ===
|
||||
- name: 3D Printer (K1C) Hotend Actual
|
||||
unique_id: "192.168.2.317c2593fb-a7dd-4ed7-a865-2e4dddddbb40"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["temperature"] | float(0) | round(1) }}'
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])|list|count == items|count }}
|
||||
attributes:
|
||||
friendly_name: "Hotend Actual"
|
||||
|
||||
- name: 3D Printer (K1C) Hotend Power
|
||||
unique_id: "192.168.2.31c57a1e35-92fa-403e-b3cf-ec1e97ef94cf"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["extruder"]["power"] | float(0) | round(3) * 100}}'
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable'])
|
||||
|list|count == items|count }}
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:flash
|
||||
attributes:
|
||||
friendly_name: "Hotend Power"
|
||||
|
||||
- name: 3D Printer (K1C) Bed Target
|
||||
unique_id: "192.168.2.31eadec415-c281-4814-8fba-17c6c42670ec"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["target"] | float(0) | round(1) }}'
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Bed Target"
|
||||
|
||||
- name: 3D Printer (K1C) Bed Actual
|
||||
unique_id: "192.168.2.31cb33503c-c5d4-4e06-b79b-c1cd64ca2d7a"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["temperature"] | float(0) | round(1) }}'
|
||||
unit_of_measurement: "°C"
|
||||
icon: mdi:thermometer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Bed Actual"
|
||||
|
||||
- name: 3D Printer (K1C) Bed Power
|
||||
unique_id: "192.168.2.31abb2fc5b-8173-4131-a942-fb11e30f4efa"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["heater_bed"]["power"] | float(0) | round(3) * 100 }}'
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:flash
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items)|rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Bed Power"
|
||||
|
||||
- name: 3D Printer (K1C) Printer State
|
||||
unique_id: "192.168.2.31758ce84c-3210-4f29-b6b3-38139180de96"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] }}'
|
||||
icon: >
|
||||
{% set val = states.sensor.printer_3d_sensor.attributes["print_stats"]["state"] %}
|
||||
{% if val == 'standby' %}
|
||||
mdi:sleep
|
||||
{% elif val == 'error' %}
|
||||
mdi:alert-circle
|
||||
{% elif val == 'printing' %}
|
||||
mdi:printer-3d-nozzle
|
||||
{% elif val == 'paused' %}
|
||||
mdi:pause-circle
|
||||
{% elif val == 'complete' %}
|
||||
mdi:printer-3d
|
||||
{% else %}
|
||||
mdi:help-circle
|
||||
{% endif %}
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Printer State"
|
||||
|
||||
- name: 3D Printer (K1C) Current Print
|
||||
unique_id: "192.168.2.313a0f3144-a801-422f-adb6-e2ed35796072"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["filename"] }}'
|
||||
icon: mdi:file
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Current Print"
|
||||
|
||||
- name: 3D Printer (K1C) Current Progress
|
||||
unique_id: "192.168.2.318ec7163b-be00-4a10-8051-48cf9a260a29"
|
||||
state: '{{ ((states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]) * 100) | round(0, "floor") }}'
|
||||
unit_of_measurement: "%"
|
||||
icon: mdi:progress-clock
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Progress"
|
||||
|
||||
- name: 3D Printer (K1C) Print time
|
||||
unique_id: "192.168.2.31e1ac0fac-e8ba-4e05-8fa0-c8d8076f9f63"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"] | timestamp_custom("%H:%M:%S", 0) }}'
|
||||
icon: mdi:camera-timer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state', 'in', ['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Time Elapsed"
|
||||
|
||||
- name: 3D Printer (K1C) Time Remaining
|
||||
unique_id: "192.168.2.31e12c8def-5ebe-43a4-9f75-605a0c46fc0f"
|
||||
state: >
|
||||
{{
|
||||
(
|
||||
(
|
||||
states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]
|
||||
/ states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]
|
||||
- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]
|
||||
) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] > 0 else 0
|
||||
) | timestamp_custom("%H:%M:%S", 0)
|
||||
}}
|
||||
icon: mdi:timer-sand
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Time Remaining"
|
||||
|
||||
- name: 3d_printer_eta
|
||||
unique_id: "192.168.2.31a2b57068-9a32-4d2c-8cc9-57d2389a9082"
|
||||
state: >
|
||||
{{
|
||||
(
|
||||
as_timestamp(now()) +
|
||||
(
|
||||
(
|
||||
states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]
|
||||
/ states.sensor.printer_3d_sensor.attributes["display_status"]["progress"]
|
||||
- states.sensor.printer_3d_sensor.attributes["print_stats"]["print_duration"]
|
||||
) if states.sensor.printer_3d_sensor.attributes["display_status"]["progress"] > 0 else 0
|
||||
)
|
||||
) | timestamp_custom("%H:%M:%S", 1)
|
||||
}}
|
||||
icon: mdi:av-timer
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "ETA"
|
||||
|
||||
- name: 3D Printer (K1C) Message
|
||||
unique_id: "192.168.2.310c418c0d-e59e-4d4e-aa11-8fae53df58f8"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["display_status"]["message"] }}'
|
||||
icon: mdi:message-cog
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Message"
|
||||
|
||||
- name: 3D Printer (K1C) Layer Height
|
||||
unique_id: "192.168.2.316cca455d-c327-4567-b886-4d7f99714265"
|
||||
state: '{{ states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0) }}'
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-collapse-down
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Layer Height"
|
||||
|
||||
- name: 3D Printer (K1C) Object Height
|
||||
unique_id: "192.168.2.316d6d9dc0-9a02-4ce4-a797-c84b42e011a6"
|
||||
state: '{{ (states.sensor.printer_3d_file_metadata.attributes["object_height"] | float(0)) - (states.sensor.printer_3d_file_metadata.attributes["layer_height"] | float(0)) }}'
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-expand-vertical
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Object Height"
|
||||
|
||||
- name: 3D Printer (K1C) Current Height
|
||||
unique_id: "192.168.2.31d440e568-d4d1-4b3f-85c4-fdacd68c0e1a"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes["gcode_move"]["gcode_position"][2] | float(0) | round(2) }}'
|
||||
unit_of_measurement: "mm"
|
||||
icon: mdi:arrow-collapse-down
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Current Height"
|
||||
|
||||
- name: 3D Printer (K1C) Current Layer
|
||||
unique_id: "192.168.2.316a77acc1-8134-4354-b2f6-390adab81993"
|
||||
state: '{{ (states("sensor.3d_printer_current_height") | float(0) / states("sensor.3d_printer_layer_height") | float(0)) | round(0) }}'
|
||||
icon: mdi:counter
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_current_height','sensor.3d_printer_layer_height'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Current Layer"
|
||||
|
||||
- name: 3D Printer (K1C) Total Layers
|
||||
unique_id: "192.168.2.3153cfe906-28ec-44cd-926a-b08ffb8766e5"
|
||||
state: '{{ (states("sensor.3d_printer_object_height") | float(0) / states("sensor.3d_printer_layer_height") | float(0)) | round(0) }}'
|
||||
icon: mdi:counter
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_object_height','sensor.3d_printer_layer_height'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Total Layers"
|
||||
|
||||
- name: 3D Printer (K1C) Actual Layer
|
||||
unique_id: "192.168.2.31167e5dec-719c-42d3-9560-4f177573f742"
|
||||
state: '{{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["current_layer"] }} / {{ states.sensor.printer_3d_sensor.attributes.print_stats["info"]["total_layer"] }}'
|
||||
icon: mdi:layers-triple
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_sensor'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Actual Layer"
|
||||
|
||||
- name: 3D Printer (K1C) Object Thumbnails
|
||||
unique_id: "192.168.2.3159b37837-b751-4d31-98c2-516a52edf833"
|
||||
state: >
|
||||
{% set dir = states('sensor.3d_printer_current_print') %}
|
||||
{% set thumb = state_attr('sensor.printer_3d_file_metadata','thumbnails') %}
|
||||
{% set img = (thumb | last).relative_path if thumb else 'not available' %}
|
||||
{{ (dir.split('/')[:-1] + [img]) | join('/') }}
|
||||
icon: mdi:image
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_file_metadata'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Object Thumbnails"
|
||||
|
||||
- name: 3D Printer (K1C) State Message
|
||||
unique_id: "192.168.2.319a5184c9-ac5b-44a9-a691-2b67c243d197"
|
||||
state: '{{ states.sensor.printer_3d_info.attributes["state_message"] }}'
|
||||
icon: mdi:message-cog
|
||||
availability: >
|
||||
{% set items = ['sensor.printer_3d_info'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "State Message"
|
||||
|
||||
- name: 3D Printer (K1C) Bed and Nozzle Power
|
||||
unique_id: "192.168.2.313988e9be-c910-4634-8205-38d53170d5a5"
|
||||
state: '{{ states("sensor.3d_printer_bed_power") | float(0) | round(1) }}% / {{ states("sensor.3d_printer_hotend_power") | float(0) | round(1) }}%'
|
||||
icon: mdi:meter-electric-outline
|
||||
availability: >
|
||||
{% set items = ['sensor.3d_printer_bed_power','sensor.3d_printer_hotend_power'] %}
|
||||
{{ expand(items) | rejectattr('state','in',['unknown','unavailable']) | list | count == items | count }}
|
||||
attributes:
|
||||
friendly_name: "Bed and Nozzle Power"
|
Reference in New Issue
Block a user