188 lines
5.6 KiB
YAML
188 lines
5.6 KiB
YAML
##########################################################################################
|
|
# GLOBAL VARIABLES
|
|
# https://esphome.io/guides/automations.html#global-variables
|
|
##########################################################################################
|
|
globals:
|
|
# total_energy: cumulative power (restored across reboots)
|
|
- id: total_energy
|
|
type: float
|
|
restore_value: yes
|
|
initial_value: '0.0'
|
|
|
|
##########################################################################################
|
|
# UART
|
|
# https://esphome.io/components/uart/
|
|
##########################################################################################
|
|
uart:
|
|
# Needed for cse776. Set logging baud to 0 also.
|
|
id: cse_uart
|
|
rx_pin: RX # GPIO3 on ESP8266
|
|
baud_rate: 4800
|
|
parity: EVEN # CSE7766 requires EVEN
|
|
|
|
##########################################################################################
|
|
# SENSORS
|
|
# https://esphome.io/components/sensor/
|
|
##########################################################################################
|
|
sensor:
|
|
#############################################
|
|
# CSE7766 POWER SENSOR
|
|
# https://esphome.io/components/sensor/cse7766.html
|
|
#############################################
|
|
- platform: cse7766
|
|
id: athom_cse7766
|
|
uart_id: cse_uart
|
|
|
|
current:
|
|
name: "Current"
|
|
id: plug_current
|
|
icon: mdi:current-ac
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
- lambda: if (x < 0.060) return 0.0; else return x;
|
|
|
|
voltage:
|
|
name: "Voltage"
|
|
id: plug_voltage
|
|
icon: mdi:sine-wave
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
|
|
power:
|
|
name: "Power"
|
|
id: power_sensor
|
|
icon: mdi:power
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
- lambda: if (x < 3.0) return 0.0; else return x;
|
|
|
|
energy:
|
|
name: "Energy"
|
|
id: energy
|
|
icon: mdi:lightning-bolt
|
|
unit_of_measurement: kWh
|
|
internal: ${hide_energy_sensor}
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle: ${sensor_update_interval}
|
|
- multiply: 0.001 # Wh -> kWh
|
|
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
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
|
|
reactive_power:
|
|
name: "Reactive Power"
|
|
icon: mdi:flash
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
|
|
power_factor:
|
|
name: "Power Factor"
|
|
icon: mdi:percent-outline
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- throttle_average: ${sensor_update_interval}
|
|
|
|
#############################################
|
|
# Total Energy (All Time)
|
|
#############################################
|
|
- 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: "60s"
|
|
|
|
#############################################
|
|
# 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
|
|
|
|
#############################################
|
|
# Energy Statistics (Dentra)
|
|
#############################################
|
|
- platform: energy_statistics
|
|
total: total_energy_sensor
|
|
|
|
energy_today:
|
|
name: "Energy Today"
|
|
id: total_energy_today
|
|
accuracy_decimals: 3
|
|
icon: mdi:hours-24
|
|
|
|
energy_yesterday:
|
|
name: "Total Energy Yesterday"
|
|
id: total_energy_yesterday
|
|
accuracy_decimals: 3
|
|
|
|
energy_week:
|
|
name: "Total Energy Week"
|
|
id: total_energy_week
|
|
accuracy_decimals: 3
|
|
|
|
energy_month:
|
|
name: "Total Energy Month"
|
|
id: total_energy_month
|
|
accuracy_decimals: 3
|
|
|
|
##########################################################################################
|
|
# Dentra Components - Adds 'Platform - Energy Statistics'
|
|
# https://github.com/dentra/esphome-components/tree/master/components/energy_statistics
|
|
##########################################################################################
|
|
external_components:
|
|
- source: github://dentra/esphome-components
|
|
|
|
##########################################################################################
|
|
# 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: 5
|
|
mode: INPUT_PULLUP
|
|
inverted: true
|
|
id: power_button
|
|
name: "Power Button"
|
|
disabled_by_default: true
|
|
|
|
# No relay hardware on this device; leaving the switch section out intentionally.
|