303 lines
10 KiB
YAML
303 lines
10 KiB
YAML
##########################################################################################
|
|
##########################################################################################
|
|
# MAIN DISHWASHER POWER
|
|
# Controlled by a Athom Smart Plug V1
|
|
# package_import_url: github://athom-tech/athom-configs/athom-smart-plug.yaml
|
|
#
|
|
# V1.0 2025-06-10 YAML Tidyups
|
|
#
|
|
##########################################################################################
|
|
##########################################################################################
|
|
|
|
##########################################################################################
|
|
# SPECIFIC DEVICE VARIABLE SUBSTITUTIONS
|
|
# If NOT using a secrets file, just replace these with the passwords etc (in quotes)
|
|
##########################################################################################
|
|
substitutions:
|
|
# Device Naming
|
|
device_name: "esp-maindishwasherpower"
|
|
friendly_name: "Main Dishwasher Power"
|
|
description_comment: "Main Dishwasher Power, Athom Smart Plug V1 Power Monitor"
|
|
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
|
|
|
|
# Passwords
|
|
api_key: !secret esp-api_key # unfortunately you can't use substitutions inside secrets names
|
|
ota_pass: !secret esp-ota_pass # unfortunately you can't use substitutions inside secrets names
|
|
static_ip_address: !secret esp-maindishwasherpower_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
|
|
|
|
# Device Settings
|
|
relay_icon: "mdi:dishwasher"
|
|
current_limit : "10" # Current Limit in Amps. AU Plug = 10. IL, BR, EU, UK, US Plug = 16.
|
|
|
|
##########################################################################################
|
|
# PACKAGES
|
|
# https://esphome.io/components/esphome.html
|
|
##########################################################################################
|
|
packages:
|
|
common_wifi: !include
|
|
file: common/network_common.yaml
|
|
vars:
|
|
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
|
|
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}"
|
|
|
|
##########################################################################################
|
|
# ESPHome
|
|
# https://esphome.io/components/esphome.html
|
|
##########################################################################################
|
|
esphome:
|
|
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:
|
|
name: "${project_name}"
|
|
version: "${project_version}"
|
|
on_boot:
|
|
priority: 200
|
|
then:
|
|
- switch.turn_on: "relay"
|
|
|
|
##########################################################################################
|
|
# ESP Platform and Framework
|
|
# https://esphome.io/components/esp32.html
|
|
##########################################################################################
|
|
esp8266:
|
|
board: esp8285
|
|
restore_from_flash: true # mainly for calculating cumulative energy, but not that important here
|
|
|
|
preferences:
|
|
flash_write_interval: 5min
|
|
|
|
mdns:
|
|
disabled: false
|
|
|
|
#dashboard_import:
|
|
# package_import_url: github://athom-tech/esp32-configs/athom-smart-plug.yaml
|
|
|
|
##########################################################################################
|
|
# ESPHome LOGGING
|
|
# 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)
|
|
#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
|
|
##########################################################################################
|
|
status_led:
|
|
pin:
|
|
number: GPIO13
|
|
inverted: True
|
|
|
|
##########################################################################################
|
|
# BINARY SENSORS
|
|
# https://esphome.io/components/binary_sensor/
|
|
##########################################################################################
|
|
binary_sensor:
|
|
- platform: gpio
|
|
pin:
|
|
number: 3
|
|
mode: INPUT_PULLUP
|
|
inverted: true
|
|
name: "Power Button"
|
|
id: power_button
|
|
filters:
|
|
- delayed_on: 20ms
|
|
on_click:
|
|
- min_length: 20ms
|
|
max_length: 500ms
|
|
then:
|
|
- switch.toggle:
|
|
id: relay
|
|
|
|
- platform: template
|
|
name: "Relay Status"
|
|
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/
|
|
#################################################################################################
|
|
switch:
|
|
- platform: gpio
|
|
name: "Power Output"
|
|
pin: GPIO14
|
|
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: "${relay_icon}"
|
|
|