203 lines
5.0 KiB
YAML
203 lines
5.0 KiB
YAML
substitutions:
|
|
friendly_name: "Home Energy Monitor"
|
|
device_name: home-energy-monitor
|
|
update_time: 59s
|
|
# SCT-013-000 (100A/50mA) calibration value
|
|
current_cal: '27518'
|
|
# Jameco 9VAC Transformer (board v1.3+)
|
|
voltage_cal: '7305'
|
|
|
|
esphome:
|
|
name: ${device_name}
|
|
friendly_name: ${friendly_name}
|
|
|
|
esp32:
|
|
board: nodemcu-32s
|
|
framework:
|
|
type: esp-idf
|
|
|
|
# Enable logging
|
|
logger:
|
|
level: INFO
|
|
|
|
# Enable Home Assistant API
|
|
api:
|
|
encryption:
|
|
key: !secret api_encryption_key
|
|
|
|
# Enable OTA updates
|
|
ota:
|
|
- platform: esphome
|
|
|
|
wifi:
|
|
ssid: !secret wifi_iot_ssid
|
|
password: !secret wifi_password
|
|
|
|
# Fallback hotspot if Wi-Fi fails
|
|
ap:
|
|
ssid: ${device_name}
|
|
password: !secret wifi_password
|
|
|
|
# Prevents aggressive reconnection attempts
|
|
power_save_mode: none # Use 'light' for battery devices
|
|
|
|
# Slower but more reliable connection
|
|
fast_connect: true
|
|
|
|
# Handle connection failures gracefully
|
|
on_connect:
|
|
- logger.log: "Wi-Fi connected!"
|
|
on_disconnect:
|
|
- logger.log: "Wi-Fi disconnected!"
|
|
|
|
# Reduce mDNS traffic
|
|
mdns:
|
|
disabled: true # Set to true if using static IPs and don't need discovery
|
|
|
|
#captive_portal:
|
|
|
|
web_server:
|
|
port: 80
|
|
# SPI bus configuration
|
|
spi:
|
|
clk_pin: 18
|
|
miso_pin: 19
|
|
mosi_pin: 23
|
|
|
|
sensor:
|
|
# ──────────────────────────────────
|
|
# IC1: Channels 1-3 (CS pin 5)
|
|
# ──────────────────────────────────
|
|
- platform: atm90e32
|
|
cs_pin: 5
|
|
phase_a:
|
|
voltage:
|
|
name: ${device_name} Volts
|
|
id: ic1Volts
|
|
accuracy_decimals: 1
|
|
current:
|
|
name: ${device_name} CT1 Amps
|
|
id: ct1Amps
|
|
power:
|
|
name: ${device_name} CT1 Watts
|
|
id: ct1Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
phase_b:
|
|
current:
|
|
name: ${device_name} CT2 Amps
|
|
id: ct2Amps
|
|
power:
|
|
name: ${device_name} CT2 Watts
|
|
id: ct2Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
phase_c:
|
|
current:
|
|
name: ${device_name} CT3 Amps
|
|
id: ct3Amps
|
|
power:
|
|
name: ${device_name} CT3 Watts
|
|
id: ct3Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
frequency:
|
|
name: ${device_name} Frequency
|
|
line_frequency: 60Hz
|
|
gain_pga: 1X
|
|
update_interval: ${update_time}
|
|
|
|
# ──────────────────────────────────
|
|
# IC2: Channels 4-6 (CS pin 4)
|
|
# ──────────────────────────────────
|
|
- platform: atm90e32
|
|
cs_pin: 4
|
|
phase_a:
|
|
current:
|
|
name: ${device_name} CT4 Amps
|
|
id: ct4Amps
|
|
power:
|
|
name: ${device_name} CT4 Watts
|
|
id: ct4Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
phase_b:
|
|
current:
|
|
name: ${device_name} CT5 Amps
|
|
id: ct5Amps
|
|
power:
|
|
name: ${device_name} CT5 Watts
|
|
id: ct5Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
phase_c:
|
|
current:
|
|
name: ${device_name} CT6 Amps
|
|
id: ct6Amps
|
|
power:
|
|
name: ${device_name} CT6 Watts
|
|
id: ct6Watts
|
|
gain_voltage: ${voltage_cal}
|
|
gain_ct: ${current_cal}
|
|
line_frequency: 60Hz
|
|
gain_pga: 1X
|
|
update_interval: ${update_time}
|
|
|
|
# ──────────────────────────────────
|
|
# Calculated: Total Home Power
|
|
# (CT1 = Main Leg 1, CT2 = Main Leg 2)
|
|
# ──────────────────────────────────
|
|
- platform: template
|
|
name: ${device_name} Total Watts
|
|
id: totalWatts
|
|
lambda: "return id(ct1Watts).state + id(ct2Watts).state;"
|
|
accuracy_decimals: 1
|
|
unit_of_measurement: W
|
|
device_class: power
|
|
update_interval: ${update_time}
|
|
|
|
- platform: total_daily_energy
|
|
name: ${device_name} Total Daily Energy
|
|
power_id: totalWatts
|
|
unit_of_measurement: kWh
|
|
accuracy_decimals: 2
|
|
filters:
|
|
- multiply: 0.001
|
|
|
|
# Diagnostic sensors
|
|
- platform: wifi_signal
|
|
name: "${device_name} WiFi Signal"
|
|
update_interval: 60s
|
|
|
|
- platform: uptime
|
|
name: "${device_name} Uptime"
|
|
update_interval: 60s
|
|
|
|
time:
|
|
- platform: homeassistant
|
|
id: homeassistant_time
|
|
|
|
text_sensor:
|
|
- platform: wifi_info
|
|
ip_address:
|
|
name: "${device_name} IP Address"
|
|
ssid:
|
|
name: "${device_name} Connected SSID"
|
|
bssid:
|
|
name: "${device_name} BSSID"
|
|
|
|
# Watchdog to auto-reboot if things go wrong
|
|
interval:
|
|
- interval: 5min
|
|
then:
|
|
- if:
|
|
condition:
|
|
and:
|
|
- lambda: 'return millis() > 300000;' # >5 min uptime
|
|
- not:
|
|
wifi.connected:
|
|
then:
|
|
- logger.log: "Wi-Fi not connected for 5 min, rebooting..."
|
|
- delay: 10s
|
|
- lambda: 'App.safe_reboot();'
|