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

@@ -4,6 +4,7 @@
# Controlled by a Athom Smart Plug V1
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml
#
# V1.1 2025-06-12 package added for energy entities
# V1.0 2025-06-10 YAML Tidyups
#
##########################################################################################
@@ -17,12 +18,12 @@ substitutions:
# Device Naming
device_name: "esp-maindishwasherpower"
friendly_name: "Main Dishwasher Power"
description_comment: "Main Dishwasher Power, Athom Smart Plug V1 Power Monitor"
description_comment: "Main Dishwasher Power Monitor :: Athom Smart Plug Power Monitor V1"
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_version: "v1.0" # 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
# Passwords
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
@@ -51,10 +52,6 @@ packages:
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
@@ -63,6 +60,20 @@ 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
vars:
local_friendly_name: "${friendly_name}"
local_current_limit: "${current_limit}"
##########################################################################################
# ESPHome
# https://esphome.io/components/esphome.html
@@ -109,32 +120,6 @@ logger:
#esp8266_store_log_strings_in_flash: false
#tx_buffer_size: 64
##########################################################################################
# GLOBAL VARIABLES
# 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"
####################################################
# total_energy: cumulative power
# Restored, so keeps counting up.
####################################################
- id: total_energy
type: float
restore_value: yes
initial_value: "0.0"
##########################################################################################
# STATUS LED
# https://esphome.io/components/status_led.html
@@ -170,123 +155,6 @@ binary_sensor:
lambda: |-
return id(relay).state;
##########################################################################################
# Sensors
# https://esphome.io/components/text_sensor/index.html
##########################################################################################
sensor:
- 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}"
#############################################
# CSE7766 POWER SENSOR
# https://esphome.io/components/sensor/cse7766.html
#############################################
- platform: hlw8012
id: athom_hlw8012
sel_pin:
number: GPIO12
inverted: True
cf_pin: GPIO4
cf1_pin: GPIO5
voltage_divider: 780
current:
name: "Current"
id: current
unit_of_measurement: A
accuracy_decimals: 2
icon: mdi:current-ac
filters:
- calibrate_linear:
- 0.0000 -> 0.0110 # Relay off no load
- 0.0097 -> 0.0260 # Relay on no load
- 0.9270 -> 0.7570
- 2.0133 -> 1.6330
- 2.9307 -> 2.3750
- 5.4848 -> 4.4210
- 8.4308 -> 6.8330
- 9.9171 -> 7.9830
# Normalize for plug load
- lambda: if (x < 0.0260) return 0; else return (x - 0.0260);
on_value_range:
- above: ${current_limit}
then:
- switch.turn_off: relay
voltage:
name: "Voltage"
id: voltage
unit_of_measurement: V
accuracy_decimals: 1
icon: mdi:sine-wave
filters:
- skip_initial: 2
power:
name: "Power"
id: power_sensor
unit_of_measurement: W
accuracy_decimals: 1
icon: mdi:power
filters:
- calibrate_linear:
- 0.0000 -> 0.5900 # Relay off no load
- 0.0000 -> 1.5600 # Relay on no load
- 198.5129 -> 87.8300
- 434.2469 -> 189.5000
- 628.6241 -> 273.9000
- 1067.0067 -> 460.1000
- 1619.8098 -> 699.2000
- 2043.0282 -> 885.0000
# Normalize for plug load
- lambda: if (x < 1.5600) return 0; else return (x - 1.5600);
change_mode_every: 1
update_interval: 5s
# Shows the Energy kWh since the device was last started
energy:
name: "Energy (Since Restart)"
id: energy
icon: mdi:lightning-bolt
unit_of_measurement: kWh
accuracy_decimals: 3
filters:
# 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();
# internal: ${hide_energy_sensor}
#############################################
# Total Daily Energy
# https://esphome.io/components/sensor/total_daily_energy.html
#############################################
- 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
#################################################################################################
# SWITCH COMPONENT
# https://esphome.io/components/switch/