esphome sntp offline fixes

This commit is contained in:
root
2025-06-14 16:39:38 +12:00
parent 362b8119b4
commit 5ef9d0df7d
10 changed files with 611 additions and 858 deletions

View File

@@ -1,14 +1,15 @@
#############################################
#############################################
# Athom Smart Plug Power Monitor ESP32-C3
##########################################################################################
##########################################################################################
# DOWNSTAIRS DISHWASHER POWER MONITOR
# Controlled by a Athom Smart Plug V3
#
# dashboard_import:
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
#
# V1.1 2025-06-12 Tidyups and packages added
#
# based on https://github.com/athom-tech/esp32-configs/blob/main/athom-smart-plug.yaml
#
# SUMMARY
# Smart plug with power monitoring.
#
#############################################
#############################################
##########################################################################################
##########################################################################################
#############################################
@@ -16,21 +17,27 @@
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
#############################################
substitutions:
devicename: "esp-downstdishwasher"
# Device Naming
device_name: "esp-downstdishwasher"
friendly_name: "Downstairs Dishwasher Power"
description_comment: "Downstairs Dishwasher Power, Athom Smart Plug Power Monitor"
room: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
description_comment: "Downstairs Dishwasher Power :: Athom Smart Plug Power V3"
device_area: "Downstairs Kitchen" # Allows ESP device to be automatically linked to an 'Area' in Home Assistant.
# Project Naming
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-downstdishwasher_api_key # unfortunately you can't use substitutions inside secrets names
ota_pass: !secret esp-downstdishwasher_ota_pass # unfortunately you can't use substitutions inside secrets names
static_ip_address: !secret esp-downstdishwasher_ip
# 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
#############################################
# SPECIFIC PROJECT VARIABLE SUBSTITUTIONS
#############################################
project_name: "Athom Technology.Smart Plug V3" # Project Details
project_version: "v1.0.7" # Project V denotes release of yaml file, allowing checking of deployed vs latest version
# 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.
#############################################
@@ -41,33 +48,41 @@ packages:
common_wifi: !include
file: common/network_common.yaml
vars:
local_static_ip_address: ${static_ip_address}
local_ota_pass: ${ota_pass}
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_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}"
# 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
vars:
local_current_limit: "${current_limit}"
#############################################
# ESPHome
# https://esphome.io/components/esphome.html
#############################################
esphome:
name: ${devicename}
friendly_name: ${friendly_name}
comment: ${description_comment} #Appears on the esphome page in HA
area: "${room}"
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:
@@ -87,41 +102,29 @@ esp32:
flash_size: 4MB
variant: ESP32C3
framework:
type: arduino
version: recommended
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
esp32_improv:
authorizer: none
#############################################
# ESPHome Logging Enable
# https://esphome.io/components/logger.html
#############################################
logger:
level: ${log_level} #INFO Level suggested, or DEBUG for testing
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
esp32_improv:
authorizer: none
dashboard_import:
package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
uart:
rx_pin: GPIO20
baud_rate: 4800
data_bits: 8
stop_bits: 1
parity: EVEN
globals:
- id: total_energy
type: float
restore_value: yes
initial_value: '0.0'
##########################################################################################
# BINARY SENSORS
# https://esphome.io/components/binary_sensor/
##########################################################################################
binary_sensor:
- platform: gpio
pin:
@@ -139,9 +142,10 @@ binary_sensor:
lambda: |-
return id(relay).state;
status_led:
pin: GPIO06
#################################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/
#################################################################################################
switch:
- platform: gpio
name: "Power Output"
@@ -149,94 +153,9 @@ switch:
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: "mdi:power-socket-au"
icon: "${relay_icon}"
sensor:
- platform: cse7766
id: athom_cse7766
current:
name: "Current"
icon: mdi:current-ac
filters:
- throttle_average: ${update_interval}
- lambda: if (x < 0.060) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected
on_value_range:
- above: ${current_limit}
then:
- switch.turn_off: relay
voltage:
name: "Voltage"
icon: mdi:sine-wave
filters:
- throttle_average: ${update_interval}
power:
name: "Power"
id: power_sensor
icon: mdi:power
filters:
- throttle_average: ${update_interval}
- lambda: if (x < 3.0) return 0.0; else return x; #For the chip will report less than 3w power when no load is connected
energy:
name: "Energy"
id: energy
icon: mdi:lightning-bolt
unit_of_measurement: kWh
filters:
- throttle: ${update_interval}
# Multiplication factor from W to kW is 0.001
- multiply: 0.001
on_value:
then:
- lambda: |-
static float previous_energy_value = 0.0;
float current_energy_value = id(energy).state;
id(total_energy) += current_energy_value - previous_energy_value;
previous_energy_value = current_energy_value;
id(total_energy_sensor).update();
apparent_power:
name: "Apparent Power"
icon: mdi:power
filters:
- throttle_average: ${update_interval}
reactive_power:
name: "Reactive Power"
icon: mdi:flash
filters:
- throttle_average: ${update_interval}
power_factor:
name: "Power Factor"
icon: mdi:percent-outline
filters:
- throttle_average: ${update_interval}
- platform: template
name: "Total Energy"
id: total_energy_sensor
unit_of_measurement: kWh
device_class: "energy"
state_class: "total_increasing"
icon: mdi:lightning-bolt
accuracy_decimals: 3
lambda: |-
return id(total_energy);
update_interval: ${update_interval}
- platform: total_daily_energy
name: "Total Daily Energy"
restore: true
power_id: power_sensor
unit_of_measurement: kWh
icon: mdi:hours-24
accuracy_decimals: 3
filters:
- multiply: 0.001