yaml tidyups and warning removals

This commit is contained in:
root
2026-01-24 14:06:52 +13:00
parent 9bbde16d8d
commit c104187d62
44 changed files with 391 additions and 124 deletions
+33 -45
View File
@@ -1,6 +1,6 @@
##########################################################################################
##########################################################################################
# FLY SPRAYER Sinilink XY-WFUSB (ESP8266/ESP8285) ESPHome
# FLY SPRAYER - Sinilink XY-WFUSB (ESP8266/ESP8285) - ESPHome
#
# V1.0 2025-05-30 Initial Version
#
@@ -12,7 +12,7 @@
# - Sprayer has its own timers, but it fires whenever it is started up, which we utilise here.
# - Enforce a cooldown so it never double-fires too quickly (Sprayer has some memory)
# - Operation window select: Night only / Day only / 24 Hours / On / Off.
# - Randomize each interval by ± a percentage to avoid a perfectly regular pattern.
# - Randomize each interval by +- a percentage to avoid a perfectly regular pattern.
# - Red LED (GPIO14, inverted) pulses slowly when idle; goes solid ON during spray.
# - Green LED (GPIO16) as standard ESPHome status LED.
# - Has a resettable total spray count, and a daily spray count
@@ -26,14 +26,14 @@
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
##########################################################################################
substitutions:
# Device Naming
# Device Naming
device_name: "esp-flysprayer1"
friendly_name: "Fly Sprayer"
description_comment: "Control of generic automatic fly sprayer on a configurable interval"
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
device_area: "Lounge" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
project_name: "Generic ESP8266.XY-WFUSB" # Project Details
project_name: "Generic ESP8266.XY-WFUSB" # Project Details
project_version: "v1.0" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# Passwords & Secrets
@@ -67,8 +67,8 @@ substitutions:
night_start_h: 21 # 21:00 (9pm)
night_end_h: 7 # 07:00 (7am)
# Interval jitter (± percent of selected interval)
interval_jitter_pct: 10 # Default ±10%
# Interval jitter (+- percent of selected interval)
interval_jitter_pct: 10 # Default +-10%
#########################################################################################
# PACKAGES: Included Common Packages
@@ -95,7 +95,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) ####
@@ -142,7 +142,6 @@ esphome:
id(next_spray_in_text).publish_state("Ready");
- script.execute: spray_loop
##########################################################################################
# ESP PLATFORM AND FRAMEWORK
# https://esphome.io/components/esp8266.html
@@ -162,7 +161,7 @@ preferences:
##########################################################################################
globals:
# millisecond tick when we last fired successfully
- id: last_fire_ms
- id: last_fire_ms
type: uint32_t
restore_value: no
initial_value: '0'
@@ -178,34 +177,34 @@ globals:
initial_value: 'false'
# absolute millis() when the next spray countdown ends
- id: next_target_ms
- id: next_target_ms
type: uint32_t
restore_value: no
initial_value: '0'
# total successful sprays (persists across reboots)
- id: spray_count
- id: spray_count
type: uint32_t
restore_value: yes
initial_value: '0'
# total sprays since local midnight
- id: spray_count_today
- id: spray_count_today
type: uint32_t
restore_value: yes
initial_value: '0'
# day-of-month snapshot to detect midnight rollover
- id: last_day
- id: last_day
type: int
restore_value: yes
initial_value: '-1'
##########################################################################################
##########################################################################################
# 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)
@@ -286,7 +285,7 @@ button:
- lambda: |-
id(spray_count) = 0;
id(spray_count_sensor).publish_state(0);
#########################################################################################
# SELECT COMPONENT
# https://esphome.io/components/select/index.html
@@ -310,8 +309,8 @@ select:
on_value:
then:
- logger.log:
format: "Spray Interval changed to %s rescheduling"
args: [ 'id(spray_interval).state.c_str()' ]
format: "Spray Interval changed to %s - rescheduling"
args: [ 'id(spray_interval).current_option().c_str()' ]
- script.execute: spray_loop
- platform: template
@@ -330,8 +329,8 @@ select:
on_value:
then:
- logger.log:
format: "Operation changed to %s rescheduling"
args: [ 'id(spray_operation).state.c_str()' ]
format: "Operation changed to %s - rescheduling"
args: [ 'id(spray_operation).current_option().c_str()' ]
- script.execute: spray_loop
##########################################################################################
@@ -339,7 +338,7 @@ select:
# https://esphome.io/components/binary_sensor/
##########################################################################################
binary_sensor:
# Front panel/local button (GPIO4) single press triggers a Spray Now (honors cooldown)
# Front panel/local button (GPIO4) - single press triggers a Spray Now (honors cooldown)
- platform: gpio
id: btn_local
pin:
@@ -441,20 +440,12 @@ light:
# https://esphome.io/components/number/
##########################################################################################
##########################################################################################
# SCRIPT COMPONENT
# https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call.
##########################################################################################
# SCRIPTS main loop, cooldown-safe trigger, and actual spray action
##########################################################################################
##########################################################################################
# SCRIPT COMPONENT
# https://esphome.io/components/script.html
# Scripts can be executed nearly anywhere in your device configuration with a single call.
##########################################################################################
# SCRIPTS main loop, cooldown-safe trigger, and actual spray action
# SCRIPTS - main loop, cooldown-safe trigger, and actual spray action
##########################################################################################
script:
# Cooldown-checked "Spray Now"
@@ -495,7 +486,7 @@ script:
brightness: 50%
effect: red_idle_pulse
# Scheduler loop waits a randomized interval, updates countdown text, checks window, then tries to spray
# Scheduler loop - waits a randomized interval, updates countdown text, checks window, then tries to spray
- id: spray_loop
mode: restart
then:
@@ -505,7 +496,7 @@ script:
then:
# 1) Compute the base interval and randomized wait
- lambda: |-
auto s = id(spray_interval).state;
auto s = id(spray_interval).current_option();
uint32_t base_sec = 3600; // default 1 hour
if (s == "5 minutes") base_sec = 5 * 60;
else if (s == "10 minutes") base_sec = 10 * 60;
@@ -515,13 +506,13 @@ script:
else if (s == "2 hours") base_sec = 2 * 60 * 60;
else if (s == "4 hours") base_sec = 4 * 60 * 60;
// Jitter ±pct
// Jitter +-pct
const uint32_t pct = ${interval_jitter_pct};
const uint32_t jitter = (base_sec * pct) / 100;
const uint32_t span = (jitter * 2u) + 1u;
const uint32_t rnd = random_uint32() % span; // 0..(2*jitter)
const int32_t delta = (int32_t)rnd - (int32_t)jitter; // -jitter..+jitter
int32_t next_sec = (int32_t)base_sec + delta;
const uint32_t rnd = random_uint32() % span; // 0..(2*jitter)
const int32_t delta = (int32_t) rnd - (int32_t) jitter; // -jitter..+jitter
int32_t next_sec = (int32_t) base_sec + delta;
if (next_sec < 1) next_sec = 1;
ESP_LOGI("spray", "Next interval: base=%u s, jitter=%u%%, wait=%ld s",
@@ -536,11 +527,11 @@ script:
id(next_spray_seconds).publish_state(sec);
uint32_t min = (sec + 59u) / 60u; // minutes, ceiling
char buf[16];
snprintf(buf, sizeof(buf), "%u min", (unsigned)min);
snprintf(buf, sizeof(buf), "%u min", (unsigned) min);
std::string countdown_txt(buf);
// Override text for specific modes
auto op = id(spray_operation).state;
auto op = id(spray_operation).current_option();
char await_buf[16];
if (op == "Off") {
@@ -594,11 +585,11 @@ script:
id(next_spray_seconds).publish_state(sec);
uint32_t min = (sec + 59u) / 60u; // minutes, ceiling
char buf[16];
snprintf(buf, sizeof(buf), "%u min", (unsigned)min);
snprintf(buf, sizeof(buf), "%u min", (unsigned) min);
std::string countdown_txt(buf);
// Override text for specific modes
auto op = id(spray_operation).state;
auto op = id(spray_operation).current_option();
char await_buf[16];
if (op == "Off") {
@@ -659,7 +650,7 @@ script:
# 3) Check operation window; if allowed, attempt spray (cooldown enforced inside)
- lambda: |-
auto op = id(spray_operation).state;
auto op = id(spray_operation).current_option();
bool allowed = false;
if (op == "Off") {
@@ -699,6 +690,3 @@ script:
- script.execute: try_spray_now