yaml tidyups for esphome
This commit is contained in:
@@ -3,15 +3,16 @@
|
||||
# MASTER BATHROOM HEATED TOWEL RAIL
|
||||
# Controlled by a Sonoff Basic
|
||||
#
|
||||
# V2.2 2025-06-14 Fixes to offline time when sntp/network unavailable
|
||||
# V2.2 2026-01-30 Added Morning/Evening Timer enable switches (gate timer windows)
|
||||
# V2.1 2025-06-12 Added select and button to chose modes, added countdown & startup to boost
|
||||
# V2.0 2025-06-05 YAML Tidyups
|
||||
# V1.1 2025-04-12 Fixes to timers and offline modes
|
||||
# V1.0 2025-02-14 Initial Version
|
||||
#
|
||||
#
|
||||
# INSTRUCTIONS
|
||||
# - It allows the device to work in a standalone timer style operation
|
||||
# - The timer has a morning and evening time (but no weekday/weekend settings)
|
||||
# - Morning Timer Enable / Evening Timer Enable switches gate their timer windows (default ON and restored on reboot)
|
||||
# - 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)
|
||||
@@ -23,7 +24,7 @@
|
||||
# - 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
|
||||
# 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
|
||||
@@ -54,12 +55,12 @@ substitutions:
|
||||
device_name: "esp-masterbathtowelrail"
|
||||
friendly_name: "Master Bathroom Towelrail"
|
||||
description_comment: "Sonoff Basic controlling ON/OFF/Timer for the Heated Towel Rail in the Master Bathroom"
|
||||
device_area: "Main Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
device_area: "Main Bathroom" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
|
||||
|
||||
# Project Naming
|
||||
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
|
||||
project_version: "v2.1" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
project_name: "Sonoff Technologies.Sonoff Basic V1" # Project Details
|
||||
project_version: "v2.2" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
|
||||
|
||||
# Passwords
|
||||
api_key: !secret esp-masterbathtowelrail_api_key # unfortunately you can't use substitutions inside secrets names
|
||||
ota_pass: !secret esp-masterbathtowelrail_ota_pass # unfortunately you can't use substitutions inside secrets names
|
||||
@@ -103,7 +104,7 @@ packages:
|
||||
file: common/mqtt_common.yaml
|
||||
vars:
|
||||
local_device_name: "${device_name}"
|
||||
|
||||
|
||||
#### WEB PORTAL ####
|
||||
#common_webportal: !include common/webportal_common.yaml
|
||||
#### SNTP (Only use if you want/need accurate timeclocks) ####
|
||||
@@ -188,10 +189,10 @@ preferences:
|
||||
mdns:
|
||||
disabled: true
|
||||
|
||||
##########################################################################################
|
||||
##########################################################################################
|
||||
# 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)
|
||||
@@ -209,7 +210,34 @@ switch:
|
||||
pin: GPIO12
|
||||
id: relay
|
||||
restore_mode: RESTORE_DEFAULT_OFF
|
||||
icon: "${relay_icon}"
|
||||
icon: "${relay_icon}"
|
||||
|
||||
####################################################
|
||||
# Timer Enable Switches
|
||||
# These gate the schedule windows in TIMER mode only.
|
||||
# Default and restored state is ON.
|
||||
####################################################
|
||||
- platform: template
|
||||
name: "Morning Timer Enable"
|
||||
id: morning_timer_enable
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
icon: "mdi:timer-outline"
|
||||
optimistic: true
|
||||
on_turn_on:
|
||||
- script.execute: evaluate_relay_state
|
||||
on_turn_off:
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
- platform: template
|
||||
name: "Evening Timer Enable"
|
||||
id: evening_timer_enable
|
||||
restore_mode: RESTORE_DEFAULT_ON
|
||||
icon: "mdi:timer-outline"
|
||||
optimistic: true
|
||||
on_turn_on:
|
||||
- script.execute: evaluate_relay_state
|
||||
on_turn_off:
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
##########################################################################################
|
||||
# Global Variables for use in automations etc
|
||||
@@ -367,7 +395,7 @@ text_sensor:
|
||||
}
|
||||
|
||||
############################
|
||||
# Boost duration => integer minutes (1–1439)
|
||||
# Boost duration => integer minutes (1-1439)
|
||||
############################
|
||||
- platform: mqtt_subscribe
|
||||
name: "Boost Duration"
|
||||
@@ -398,12 +426,12 @@ text_sensor:
|
||||
- lambda: |-
|
||||
// Check only the first character for mode
|
||||
char c = x.c_str()[0];
|
||||
if (c == 'T') { // “TIMER”
|
||||
if (c == 'T') { // "TIMER"
|
||||
id(operation_mode) = 2;
|
||||
} else if (c == 'O') { // “ON” or “OFF”
|
||||
// second letter N→ON, F→OFF
|
||||
} else if (c == 'O') { // "ON" or "OFF"
|
||||
// second letter N->ON, F->OFF
|
||||
id(operation_mode) = (x.size() > 1 && x[1] == 'N') ? 1 : 0;
|
||||
} else if (c == 'B') { // “BOOST”
|
||||
} else if (c == 'B') { // "BOOST"
|
||||
id(operation_mode) = 3;
|
||||
id(boost_timer) = 0;
|
||||
} else {
|
||||
@@ -495,13 +523,13 @@ number:
|
||||
- platform: template
|
||||
name: "Operation Mode Number"
|
||||
id: operation_mode_number
|
||||
internal: true # ← hides it from HA
|
||||
internal: true # <- hides it from HA
|
||||
min_value: 0
|
||||
max_value: 3
|
||||
step: 1
|
||||
set_action:
|
||||
- lambda: |-
|
||||
// x holds the incoming value (0–3)
|
||||
// x holds the incoming value (0-3)
|
||||
id(operation_mode) = int(x);
|
||||
|
||||
##########################################################################################
|
||||
@@ -532,7 +560,7 @@ binary_sensor:
|
||||
id(relay).turn_on();
|
||||
id(operation_mode) = 3;
|
||||
}
|
||||
|
||||
|
||||
- platform: template
|
||||
name: "Relay Status"
|
||||
lambda: |-
|
||||
@@ -551,7 +579,7 @@ sensor:
|
||||
update_interval: "${update_interval}"
|
||||
lambda: |-
|
||||
return id(boost_duration);
|
||||
|
||||
|
||||
- platform: template
|
||||
name: "Mins from Midnight"
|
||||
id: mins_from_midnight
|
||||
@@ -588,7 +616,6 @@ sensor:
|
||||
// never return negative
|
||||
return rem > 0 ? rem : 0;
|
||||
|
||||
|
||||
#################################################################################################
|
||||
# BUTTON COMPONENT
|
||||
# https://esphome.io/components/button/index.html
|
||||
@@ -605,6 +632,7 @@ 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
|
||||
@@ -621,6 +649,9 @@ button:
|
||||
id(operation_mode)= 2;
|
||||
id(boost_timer) = 0;
|
||||
ESP_LOGI("timer","Default timer settings applied");
|
||||
# Restore timer enable switches to ON (defaults)
|
||||
- switch.turn_on: morning_timer_enable
|
||||
- switch.turn_on: evening_timer_enable
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
#################################################################################################
|
||||
@@ -676,25 +707,36 @@ script:
|
||||
return;
|
||||
}
|
||||
|
||||
// OFF → always off
|
||||
// OFF -> always off
|
||||
if (mode == 0) {
|
||||
id(relay).turn_off();
|
||||
return;
|
||||
}
|
||||
|
||||
// ON → always on
|
||||
// ON -> always on
|
||||
if (mode == 1) {
|
||||
id(relay).turn_on();
|
||||
return;
|
||||
}
|
||||
|
||||
// TIMER → follow schedule windows
|
||||
// TIMER -> follow schedule windows (gated by enable switches)
|
||||
{
|
||||
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;
|
||||
|
||||
// Morning window only applies when Morning Timer Enable is enabled
|
||||
if (id(morning_timer_enable).state) {
|
||||
if (id(current_mins) >= id(morning_on) && id(current_mins) < id(morning_off)) {
|
||||
should_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Evening window only applies when Evening Timer Enable is enabled
|
||||
if (id(evening_timer_enable).state) {
|
||||
if (id(current_mins) >= id(evening_on) && id(current_mins) < id(evening_off)) {
|
||||
should_on = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (should_on) id(relay).turn_on();
|
||||
else id(relay).turn_off();
|
||||
}
|
||||
@@ -708,7 +750,7 @@ interval:
|
||||
- interval: "1min"
|
||||
then:
|
||||
- lambda: |-
|
||||
// — update current_mins via SNTP or fallback
|
||||
// - 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;
|
||||
@@ -717,7 +759,7 @@ interval:
|
||||
id(current_mins) = now.hour * 60 + now.minute;
|
||||
}
|
||||
|
||||
// — if in BOOST, advance boost_timer and expire when done
|
||||
// - if in BOOST, advance boost_timer and expire when done
|
||||
if (id(operation_mode) == 3) {
|
||||
id(boost_timer)++;
|
||||
if (id(boost_timer) >= id(boost_duration)) {
|
||||
@@ -726,4 +768,3 @@ interval:
|
||||
}
|
||||
}
|
||||
- script.execute: evaluate_relay_state
|
||||
|
||||
|
||||
Reference in New Issue
Block a user