esphome pelmet LEDs, lounge scenes and other fixes

This commit is contained in:
root
2025-10-12 19:54:03 +13:00
parent e96344e3ad
commit bcf514a041
19 changed files with 951 additions and 1542 deletions
+65 -35
View File
@@ -34,20 +34,21 @@ substitutions:
# MQTT LOCAL Controls
mqtt_device_name: "atto-battery"
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_command_topic: "${mqtt_command_main_topic}/${mqtt_device_name}" # Topic we will use to command this locally without HA
mqtt_status_topic: "${mqtt_status_main_topic}/${mqtt_device_name}" # Topic we will use to view status locally without HA
# Device Settings
#relay_icon: "mdi:lightbulb-group"
log_level: "DEBUG" # Define logging level: NONE, ERROR, WARN, INFO, DEBUG (Default), VERBOSE, VERY_VERBOSE
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
wake_interval: "20s"
sleep_interval: "300s"
mqtt_fail_sleep: "1h" # If MQTT is unavailable after boot wait, sleep this long
##########################################################################################
# PACKAGES: Included Common Packages
# https://esphome.io/components/packages.html
##########################################################################################
# Comment some of these out where not needed, eg MQTT, Web portal, SNTP, General Sensors
##########################################################################################
packages:
#### WIFI, Network (Static/DHCP/IPV6 etc), Fallback AP, Safemode ####
common_wifi: !include
@@ -74,12 +75,12 @@ packages:
common_webportal: !include common/webportal_common.yaml
#### SNTP (Only use if you want/need accurate timeclocks) ####
common_sntp: !include common/sntp_common.yaml
#common_sntp: !include common/sntp_common.yaml
#### DIAGNOSTICS Sensors ####
diag_basic: !include common/include_basic_diag_sensors.yaml
diag_more: !include common/include_more_diag_sensors.yaml
diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_debug: !include common/include_debug_diag_sensors.yaml
#diag_resetcount: !include common/include_resetcount_diag_sensors.yaml
##########################################################################################
@@ -91,6 +92,29 @@ esphome:
friendly_name: ${friendly_name}
comment: ${description_comment} #appears on the esphome page in HA
min_version: 2024.6.0
on_boot:
priority: 600
then:
# Default: do NOT deep sleep until explicitly enabled via MQTT
- deep_sleep.prevent: deep_sleep_1
- logger.log: "Deep sleep prevented by default on boot."
# Fail-safe: wait up to 30s for MQTT; if not connected, sleep longer (backoff)
- wait_until:
condition:
mqtt.connected:
timeout: 30s
- if:
condition:
not:
mqtt.connected:
then:
- logger.log: "MQTT unreachable after 30s -> entering FALLBACK sleep for ${mqtt_fail_sleep}."
- deep_sleep.enter:
id: deep_sleep_1
sleep_duration: ${mqtt_fail_sleep} # override only this cycle
else:
- logger.log: "MQTT connected; awaiting '${mqtt_command_topic}/deepsleep' command."
##########################################################################################
# ESP Platform and Framework
@@ -124,58 +148,51 @@ ota:
# This adds device-specific MQTT command triggers to the common MQTT configuration.
##########################################################################################
mqtt:
# Availability Topic
birth_message:
topic: ${mqtt_local_status_topic}/availability
topic: ${mqtt_status_topic}/availability
payload: online
will_message:
topic: ${mqtt_local_status_topic}/availability
topic: ${mqtt_status_topic}/availability
payload: offline
# A way to prevent deep sleep using MQTT command
# Control deep sleep over MQTT
on_message:
- topic: ${mqtt_local_command_topic}/deepsleep
- topic: ${mqtt_command_topic}/deepsleep
payload: "ON"
then:
- deep_sleep.allow: deep_sleep_1
- logger.log: "Deep sleep ALLOWED via MQTT. Device will sleep when run_duration elapses."
- topic: ${mqtt_command_topic}/deepsleep
payload: "OFF"
then:
- deep_sleep.prevent: deep_sleep_1
- topic: ${mqtt_local_command_topic}/deepsleep
payload: "ON"
then:
- deep_sleep.enter: deep_sleep_1
- logger.log: "Deep sleep PREVENTED via MQTT."
##########################################################################################
##########################################################################################
# Deep Sleep
# https://esphome.io/components/deep_sleep.html
##########################################################################################
##########################################################################################
deep_sleep:
run_duration: 20s
sleep_duration: 5min
id: deep_sleep_1
run_duration: ${wake_interval}
sleep_duration: ${sleep_interval}
##########################################################################################
# SENSOR COMPONENT
# https://esphome.io/components/sensor/
##########################################################################################
sensor:
#Quality of Wifi in dBm
- platform: wifi_signal
name: "WiFi Signal"
update_interval: ${update_interval}
retain: true #Retain this as you'll have no value between sleeps otherwise
#Analog sensor for voltage reading (A0)
- platform: uptime
name: "Uptime"
update_interval: ${update_interval}
retain: true #Retain this as you'll have no value between sleeps otherwise
- platform: adc
pin: A0
name: "Battery Voltage"
update_interval: ${update_interval}
retain: true #Retain this as you'll have no value between sleeps otherwise
id: battery_voltage
update_interval: 4s
retain: true
filters:
- multiply: 3.3 #D1 mini V divider, 3.3V -> 1V on esp8266
- calibrate_linear: #Read values with voltmeter and bench supply
- multiply: 3.3
- calibrate_linear:
- 3.11 -> 14.00
- 3.00 -> 13.50
- 2.89 -> 13.00
@@ -187,3 +204,16 @@ sensor:
- 2.22 -> 10.00
- 2.11 -> 09.50
- 2.00 -> 09.00
- delta: 0.05 # publish immediately if change >= 0.05 V
- throttle: 2s # avoid bursts if noisy
on_value:
then:
- mqtt.publish:
topic: "${mqtt_status_topic}/batteryvoltage"
qos: 1
retain: true
payload: !lambda |-
char buf[10];
snprintf(buf, sizeof(buf), "%.2f", x);
return std::string(buf);