Files
Home-Assistant-Dev/YAML Examples/IPEM SIX/ipem-six-c5-single-phase-six-channel.yaml
T
Dave Williams | DitroniX | G8PUO f422bba286 IPEM SIX 1.00.04
Cosmetic stuff
2026-06-21 03:13:51 +01:00

1213 lines
32 KiB
YAML

# Dave Williams, DitroniX 2019-2026 (ditronix.net)
# IPEM SIX - ESP32-C5 | ATM90E32 | WiFi 2.4/5GHz | Zigbee | Bluetooth | SIX Channel IoT Mains Power Energy Monitor
# June 2026: Example Code, to demonstrate and test the IPEM SIX
# Remember!
# - Set the BOARD to Use ESP32C5 Dev Module (or similar).
# - You can also set the BAUD rate up to 921600 to speed up flashing.
# - The SDK does NOT need external power to flash. It will take Power from the USB 5V.
# - The Serial Monitor is configured for BAUD 115200
# The purpose of this test code is to cycle through the various main functions of the board as part of bring up testing.
# This test code is OPEN SOURCE and formatted for easier viewing. Although is is not intended for real world use, it may be freely used, or modified as needed.
# It is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# For board configuration, see github.com/DitroniX/IPEM-SIX-ESP32C5-ATM90E32-IoT-Mains-Power-Energy-Monitor/wiki/Arduino-IDE
# Further information, details and examples can be found on our website or github.com/DitroniX
# * ditronix.net
# * github.com/DitroniX
# * github.com/DitroniX/IPEM-SIX-ESP32C5-ATM90E32-IoT-Mains-Power-Energy-Monitor
# * github.com/DitroniX/IPEM-SIX-ESP32C5-ATM90E32-IoT-Mains-Power-Energy-Monitor/wiki
# * hackster.io/DitroniX/ipem-six-esp32c5-atm90e32-iot-mains-power-energy-monitor-e323bd
# This YAML code has been created to show the features and functionality of IPEM SIX. This code has expanded to become an all encompassing ESPHome applicaition.
# IPEM SIX C5 is a professional 6-channel dual-bank energy monitoring device based on the ESP32-C5 platform and dual ATM90E32 energy measurement ICs.
# Initial code is for single phase and six current clamps. Multi-phase and Rogorski Coil integrations to flow.
esphome:
name: ipem-six-c5
friendly_name: IPEM SIX C5
on_boot:
priority: -100
then:
- delay: 2s
- light.turn_on:
id: heartbeat_led
effect: "Green Heartbeat"
esp32:
board: esp32-c5-devkitc-1
variant: esp32c5
framework:
type: esp-idf
################################## ESPHOME ##################################
# ======================== ESPHome - Enter Below our Key/pasaword ===========================
api:
encryption:
key: "xxxx"
ota:
- platform: esphome
wifi:
ssid: !secret wifi_ssid
password: !secret wifi_password
ap:
ssid: IPEM SIX C5 Fallback Hotspot
password: "xxxx"
################################## SUBSTITUTIONS ##################################
substitutions:
# ======================== Current Input Names ===========================
author: "DitroniX - Dave Williams"
firmware_version: "1.00.04"
release_date: "2026-06-21"
board_name: "IPEM SIX"
board_mcu: "ESP32-C5"
board_rev: "1.2606.102"
# ======================== Current Input Names ===========================
bank_a_1_name: "CTA-1"
bank_a_2_name: "CTA-2"
bank_a_3_name: "CTA-3"
bank_b_1_name: "CTB-1"
bank_b_2_name: "CTB-2"
bank_b_3_name: "CTB-3"
# ======================== MAINS CONFIG ===========================
# For UK/Europe/Eastern Japan/Most of World etc.
line_frequency: "50Hz"
line_voltage: "230V"
# For US/Canada/Western Japan/etc.
# line_frequency: "60Hz"
# line_voltage: "110"
# ===============================================================
# ======================== BOARD CONFIG ===========================
phases_inputs: 1 # Baseline of this version of firmware. For later use.
current_inputs: 6 # Baseline of this version of firmware. For later use.
current_type:
"CT" # Baseline of this version of firmware. For later use. CT / Rogowski
# ===============================================================
# ==================== ATM90E32 Registers ========================
gain_voltage_baseline: 38300 # Baseline for 240V 38300
gain_current_baseline: 64800 # Baseline for CT
gain_pga_baseline: 2X # Baseline for CT
# ===============================================================
# ========================= MISC ================================
tmp102_name: "Temperature"
tmp102_update_interval: 30s
# ===============================================================
project:
name: "ditronix.ipem_six"
version: "${firmware_version}"
captive_portal:
logger:
level: WARN
# =====================================================
# SPI BUS
# =====================================================
spi:
clk_pin: GPIO10
mosi_pin: GPIO8
miso_pin: GPIO9
# =====================================================
# I2C TMP102
# =====================================================
i2c:
id: i2c_bus
sda: GPIO2
scl: GPIO3
frequency: 400kHz
scan: true
# =====================================================
# ADS1115 16-bit ADC
# Address 0x49
# =====================================================
ads1115:
address: 0x49
# =====================================================
# ADS1115 USER CALIBRATION VALUES
# =====================================================
globals:
- id: average_samples
type: int
initial_value: "50"
- id: dc_voltage_factor
type: float
initial_value: "9.0588235"
- id: adc_voltage_factor
type: float
initial_value: "24.105"
- id: dc_voltage_drop
type: float
initial_value: "0.54"
################################## LIGHT ##################################
light:
# =====================================================
# HEARTBEAT
# =====================================================
- platform: esp32_rmt_led_strip
id: heartbeat_led
# name: "Heartbeat LED"
pin: GPIO27
num_leds: 1
chipset: WS2812
rgb_order: GRB
effects:
- addressable_lambda:
name: "Green Heartbeat"
update_interval: 50ms
lambda: |-
static uint8_t step = 0;
uint8_t b = 0;
if(step == 0 || step == 2)
b = 30;
else if(step == 1 || step == 3)
b = 10;
it[0] = Color(0,b,0);
step++;
if(step > 20)
step = 0;
################################## NUMBER ##################################
number:
# =====================================================
# USER ADJUSTMENTS
# =====================================================
- platform: template
name: "CT Activity Threshold"
id: ct_activity_threshold
min_value: 0.100
max_value: 5.00
step: 0.100
unit_of_measurement: A
optimistic: true
restore_value: true
initial_value: 0.100
- platform: template
name: "High Load Threshold"
id: high_load_threshold
min_value: 1
max_value: 100
step: 1
unit_of_measurement: A
optimistic: true
restore_value: true
initial_value: 10
################################## TEXT ##################################
text:
################################## TEXT SENSOR ##################################
text_sensor:
# =====================================================
# IPEM SIX FIRMWARE METADATA
# =====================================================
- platform: template
name: "Author"
entity_category: diagnostic
lambda: |-
return {"${author}"};
- platform: template
name: "Firmware Version"
entity_category: diagnostic
lambda: |-
return {"${firmware_version}"};
- platform: template
name: "Release Date"
entity_category: diagnostic
lambda: |-
return {"${release_date}"};
- platform: template
name: "Board Name"
entity_category: diagnostic
lambda: |-
return {"${board_name}"};
- platform: template
name: "Board MCU"
entity_category: diagnostic
lambda: |-
return {"${board_mcu}"};
- platform: template
name: "Board Build"
entity_category: diagnostic
lambda: |-
return {"${board_rev}"};
- platform: template
name: "Line Voltage Setting"
entity_category: diagnostic
lambda: |-
return {"${line_voltage}"};
- platform: template
name: "Line Frequency Setting"
entity_category: diagnostic
lambda: |-
return {"${line_frequency}"};
- platform: template
name: "Gain Voltage"
entity_category: diagnostic
lambda: |-
return {"${gain_voltage_baseline}"};
- platform: template
name: "Gain Current"
entity_category: diagnostic
lambda: |-
return {"${gain_current_baseline}"};
- platform: template
name: "Gain PGA"
entity_category: diagnostic
lambda: |-
return {"${gain_pga_baseline}"};
- platform: template
name: "Current Phase Voltage"
icon: mdi:current-ac
entity_category: diagnostic
update_interval: 60s
lambda: |-
std::string config = "${phases_inputs}";
if (config == "1") {
return {"Single"};
} else if (config == "2") {
return {"Split/Dual (1+3)"};
} else if (config == "3") {
return {"3-Phase (3)"};
}
return {"Unknown"};
- platform: template
name: "Current Inputs"
entity_category: diagnostic
lambda: |-
return {"${current_inputs}"};
- platform: template
name: "Current Type"
entity_category: diagnostic
lambda: |-
return {"${current_type}"};
- platform: template
name: "Product"
icon: mdi:information
entity_category: diagnostic
update_interval: 60s
lambda: |-
return {"Professional Energy Monitor"};
- platform: template
name: "Hardware"
entity_category: diagnostic
icon: mdi:information
update_interval: 60s
lambda: |-
return {"ESP32-C5 Dual ATM90E32"};
- platform: template
name: "Configuration"
icon: mdi:information-outline
entity_category: diagnostic
update_interval: 60s
lambda: |-
return {"6 Channel Dual Bank CT Meter"};
- platform: template
name: "Mains Voltage Test Status"
icon: mdi:heart-pulse
lambda: |-
if(id(mains_voltage).state < 90)
return {"Voltage Fault"};
if(id(mains_voltage).state > 250)
return {"Voltage Warning"};
if(id(bank_a_total_current).state > 99 || id(bank_b_total_current).state > 99)
return {"Warning: Over Current"};
if(id(wifi_signal_db).state < -80)
return {"Signal Warning"};
return {"Healthy"};
update_interval: 15s
- platform: template
name: "WiFi Signal Quality"
id: wifi_signal_quality
entity_category: diagnostic
update_interval: 30s
lambda: |-
if (!id(wifi_signal_db).has_state()) {
return {"No Signal"};
}
int rssi = abs((int)id(wifi_signal_db).state);
if (rssi <= 30) {
return {"Signal Very Strong"};
} else if (rssi <= 50) {
return {"Signal Excellent"};
} else if (rssi <= 60) {
return {"Signal Healthy"};
} else if (rssi <= 70) {
return {"Signal Very Good"};
} else if (rssi <= 80) {
return {"Signal Good"};
} else if (rssi <= 90) {
return {"Signal Poor - Try Moving Position"};
} else if (rssi <= 100) {
return {"Signal Very Low - Move Position"};
} else {
return {"No Signal"};
}
# =====================================================
# VOLTAGE INFORMATION
# =====================================================
# Example Mains Voltage range in the UK.
# 230V -6% / +10%
# Low < 216V
# Normal 216V - 253V
# High > 253V
- platform: template
name: "Mains Voltage Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float volt = id(mains_voltage).state;
if (volt <= 10.0) return {"No Signal"};
std::string nom = "${nominal_voltage}";
if (nom == "230V") {
if (volt < 200.0) return {"Low"};
if (volt > 260.0) return {"High"};
if (volt < 210.0 || volt > 250.0) return {"Warning"};
}
else if (nom == "120V") {
if (volt < 100.0) return {"Low"};
if (volt > 135.0) return {"High"};
if (volt < 108.0 || volt > 127.0) return {"Warning"};
}
return {"Normal"};
# =====================================================
# FREQUENCY INFORMATION
# =====================================================
# Mains Frequency ranges.
# Europe and UK which typically is 230 V @ 50 Hz
# With ranges around 216 V to 253 V
# USA and Canada which typically is 120 V or 230 V @ 60 Hz
# With ranges around 114 V to 126 V
# Japan which typically is 100 V @ 50 Hz or 60 Hz
# Eastern Japan is 50 Hz, and Western Japan is 60 Hz
# World typically is 220V-240 V @ 50 Hz
# Based on 50 Hz
# Low <49 Hz
# Normal 49-51 Hz
# High >51 Hz
- platform: template
name: "Mains Frequency Status"
icon: mdi:waves-arrow-right
update_interval: 10s
lambda: |-
float freq = id(mains_frequency).state;
if (freq <= 0.0) return {"No Signal"};
if ("${line_frequency}" == "50Hz") {
if (freq < 49.0) return {"Low"};
if (freq > 51.0) return {"High"};
} else if ("${line_frequency}" == "60Hz") {
if (freq < 59.0) return {"Low"};
if (freq > 61.0) return {"High"};
}
return {"Normal"};
- platform: template
name: "Meter Type"
entity_category: diagnostic
lambda: |-
return {"IPEM SIX - Dual ATM90E32 / 6 Channel"};
# =====================================================
# HEALTH
# =====================================================
- platform: uptime
name: "Uptime"
# =====================================================
# CT CHANNEL ACTIVITY STATUS
# =====================================================
# ====================== BANK A STATUS ======================
- platform: template
id: bank_a_1_status
name: "${bank_a_1_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_a_1_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
- platform: template
id: bank_a_2_status
name: "${bank_a_2_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_a_2_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
- platform: template
id: bank_a_3_status
name: "${bank_a_3_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_a_3_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
# ====================== BANK B STATUS ======================
- platform: template
id: bank_b_1_status
name: "${bank_b_1_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_b_1_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
- platform: template
id: bank_b_2_status
name: "${bank_b_2_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_b_2_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
- platform: template
id: bank_b_3_status
name: "${bank_b_3_name} Status"
icon: mdi:flash
update_interval: 10s
lambda: |-
float current = id(bank_b_3_current).state;
if (current >= id(high_load_threshold).state) return {"High Load"};
if (current >= id(ct_activity_threshold).state) return {"Active"};
return {"Idle"};
- platform: template
name: "${tmp102_name} Status"
icon: mdi:thermometer
entity_category: diagnostic
lambda: |-
float t = id(tmp102_temp_c).state;
if (t < 0) return {"Very Cold"};
if (t < 15) return {"Cold"};
if (t < 30) return {"Normal"};
if (t < 30) return {"Normal"};
if (t < 36) return {"Quiet Warm"};
if (t < 45) return {"Warm"};
if (t < 55) return {"Hot"};
if (t < 65) return {"Very Hot"};
return {"Hot"};
update_interval: 30s
################################## SENSOR ##################################
sensor:
# ================================================================================
# TMP102 PCB Board Ambient Temperature - Will always be warmer than actual Ambient
# ================================================================================
- platform: tmp102
name: "${tmp102_name} °C"
id: tmp102_temp_c
i2c_id: i2c_bus
address: 0x4A # As used in your Arduino code
update_interval: ${tmp102_update_interval}
accuracy_decimals: 2
device_class: "temperature"
state_class: "measurement"
entity_category: diagnostic
unit_of_measurement: "°C"
icon: "mdi:thermometer"
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 3
- platform: template
name: "${tmp102_name} °F"
id: tmp102_temp_f
# device_class: "temperature"
state_class: "measurement"
entity_category: diagnostic
unit_of_measurement: "°F"
update_interval: ${tmp102_update_interval}
accuracy_decimals: 2
icon: "mdi:thermometer"
lambda: |-
return (id(tmp102_temp_c).state * 9.0 / 5.0) + 32.0;
filters:
- sliding_window_moving_average:
window_size: 5
send_every: 3
# =====================================================
# BANK A
# CS GPIO6
# =====================================================
- platform: atm90e32
id: bank_a
cs_pin: GPIO6
gain_pga: ${gain_pga_baseline}
line_frequency: ${line_frequency}
phase_a:
voltage:
name: "Mains Voltage"
id: mains_voltage
current:
name: "${bank_a_1_name} Current"
id: bank_a_1_current
power:
name: "${bank_a_1_name} Power"
id: bank_a_1_power
reactive_power:
name: "${bank_a_1_name} Reactive Power"
power_factor:
name: "${bank_a_1_name} Power Factor"
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
phase_b:
current:
name: "${bank_a_2_name} Current"
id: bank_a_2_current
power:
name: "${bank_a_2_name} Power"
id: bank_a_2_power
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
phase_c:
current:
name: "${bank_a_3_name} Current"
id: bank_a_3_current
power:
name: "${bank_a_3_name} Power"
id: bank_a_3_power
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
frequency:
name: "Mains Frequency"
id: mains_frequency
chip_temperature:
name: "Bank A Temperature"
update_interval: 2s
# =====================================================
# BANK B
# CS GPIO7
# =====================================================
- platform: atm90e32
id: bank_b
cs_pin: GPIO7
gain_pga: ${gain_pga_baseline}
line_frequency: ${line_frequency}
phase_a:
current:
name: "${bank_b_1_name} Current"
id: bank_b_1_current
power:
name: "${bank_b_1_name} Power"
id: bank_b_1_power
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
phase_b:
current:
name: "${bank_b_2_name} Current"
id: bank_b_2_current
power:
name: "${bank_b_2_name} Power"
id: bank_b_2_power
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
phase_c:
current:
name: "${bank_b_3_name} Current"
id: bank_b_3_current
power:
name: "${bank_b_3_name} Power"
id: bank_b_3_power
gain_voltage: ${gain_voltage_baseline}
gain_ct: ${gain_current_baseline}
chip_temperature:
name: "Bank B Temperature"
update_interval: 2s
# =====================================================
# BANK A IMPORT POWER
# =====================================================
- platform: template
name: "Bank A Import Power"
id: bank_a_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
lambda: |-
float t = 0;
if(id(bank_a_1_power).state > 0)
t += id(bank_a_1_power).state;
if(id(bank_a_2_power).state > 0)
t += id(bank_a_2_power).state;
if(id(bank_a_3_power).state > 0)
t += id(bank_a_3_power).state;
return t;
update_interval: 10s
# =====================================================
# BANK B IMPORT POWER
# =====================================================
- platform: template
name: "Bank B Import Power"
id: bank_b_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
lambda: |-
float t = 0;
if(id(bank_b_1_power).state > 0)
t += id(bank_b_1_power).state;
if(id(bank_b_2_power).state > 0)
t += id(bank_b_2_power).state;
if(id(bank_b_3_power).state > 0)
t += id(bank_b_3_power).state;
return t;
update_interval: 10s
# =====================================================
# BANK A ENERGY
# =====================================================
- platform: integration
name: "Bank A Import Energy"
sensor: bank_a_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: template
name: "${bank_a_1_name} Import Power"
id: bank_a_1_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_a_1_power).state > 0 ?
id(bank_a_1_power).state : 0;
- platform: template
name: "${bank_a_2_name} Import Power"
id: bank_a_2_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_a_2_power).state > 0 ?
id(bank_a_2_power).state : 0;
- platform: template
name: "${bank_a_3_name} Import Power"
id: bank_a_3_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_a_3_power).state > 0 ?
id(bank_a_3_power).state : 0;
- platform: integration
name: "${bank_a_1_name} Energy"
sensor: bank_a_1_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "${bank_a_2_name} Energy"
sensor: bank_a_2_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "${bank_a_3_name} Energy"
sensor: bank_a_3_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "${bank_b_1_name} Energy"
sensor: bank_b_1_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "${bank_b_2_name} Energy"
sensor: bank_b_2_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "${bank_b_3_name} Energy"
sensor: bank_b_3_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
# =====================================================
# BANK B ENERGY
# =====================================================
- platform: integration
name: "Bank B Import Energy"
sensor: bank_b_import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: template
name: "${bank_b_1_name} Import Power"
id: bank_b_1_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_b_1_power).state > 0 ?
id(bank_b_1_power).state : 0;
- platform: template
name: "${bank_b_2_name} Import Power"
id: bank_b_2_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_b_2_power).state > 0 ?
id(bank_b_2_power).state : 0;
- platform: template
name: "${bank_b_3_name} Import Power"
id: bank_b_3_import_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return id(bank_b_3_power).state > 0 ?
id(bank_b_3_power).state : 0;
# =====================================================
# BANK TOTAL CURRENT
# =====================================================
- platform: template
name: "Bank A Total Current"
id: bank_a_total_current
unit_of_measurement: A
device_class: current
state_class: measurement
accuracy_decimals: 2
lambda: |-
return id(bank_a_1_current).state +
id(bank_a_2_current).state +
id(bank_a_3_current).state;
update_interval: 10s
- platform: template
name: "Bank B Total Current"
id: bank_b_total_current
unit_of_measurement: A
device_class: current
state_class: measurement
accuracy_decimals: 2
update_interval: 10s
lambda: |-
return id(bank_b_1_current).state +
id(bank_b_2_current).state +
id(bank_b_3_current).state;
# =====================================================
# BANK TOTAL POWER
# =====================================================
- platform: template
name: "Bank A Total Power"
id: bank_a_total_power
unit_of_measurement: W
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 10s
lambda: |-
return id(bank_a_1_power).state +
id(bank_a_2_power).state +
id(bank_a_3_power).state;
- platform: template
name: "Bank B Total Power"
id: bank_b_total_power
unit_of_measurement: W
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 10s
lambda: |-
return id(bank_b_1_power).state +
id(bank_b_2_power).state +
id(bank_b_3_power).state;
# =====================================================
# TOTAL POWER
# =====================================================
- platform: template
name: "Total Power"
id: total_power
unit_of_measurement: W
device_class: power
state_class: measurement
update_interval: 10s
lambda: |-
return
id(bank_a_1_power).state +
id(bank_a_2_power).state +
id(bank_a_3_power).state +
id(bank_b_1_power).state +
id(bank_b_2_power).state +
id(bank_b_3_power).state;
# =====================================================
# NET POWER
# =====================================================
- platform: template
name: "Net Power"
id: ipem_net_power
unit_of_measurement: W
device_class: power
state_class: measurement
accuracy_decimals: 1
update_interval: 10s
lambda: |-
return id(import_power).state -
id(export_power).state;
# =====================================================
# IMPORT EXPORT
# =====================================================
- platform: template
name: "Import Power"
id: import_power
unit_of_measurement: W
device_class: power
lambda: |-
float t=0;
if(id(bank_a_1_power).state>0)t+=id(bank_a_1_power).state;
if(id(bank_a_2_power).state>0)t+=id(bank_a_2_power).state;
if(id(bank_a_3_power).state>0)t+=id(bank_a_3_power).state;
if(id(bank_b_1_power).state>0)t+=id(bank_b_1_power).state;
if(id(bank_b_2_power).state>0)t+=id(bank_b_2_power).state;
if(id(bank_b_3_power).state>0)t+=id(bank_b_3_power).state;
return t;
- platform: template
name: "Export Power"
id: export_power
unit_of_measurement: W
device_class: power
lambda: |-
float t=0;
if(id(bank_a_1_power).state<0)t+=abs(id(bank_a_1_power).state);
if(id(bank_a_2_power).state<0)t+=abs(id(bank_a_2_power).state);
if(id(bank_a_3_power).state<0)t+=abs(id(bank_a_3_power).state);
if(id(bank_b_1_power).state<0)t+=abs(id(bank_b_1_power).state);
if(id(bank_b_2_power).state<0)t+=abs(id(bank_b_2_power).state);
if(id(bank_b_3_power).state<0)t+=abs(id(bank_b_3_power).state);
return t;
# =====================================================
# ENERGY DASHBOARD
# =====================================================
- platform: integration
name: "Import Energy"
sensor: import_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: integration
name: "Export Energy"
sensor: export_power
time_unit: h
integration_method: trapezoid
unit_of_measurement: kWh
device_class: energy
state_class: total_increasing
- platform: template
name: "Total Current"
id: total_current
unit_of_measurement: A
device_class: current
state_class: measurement
update_interval: 5s
lambda: |-
float t = 0;
if (id(bank_a_total_current).has_state())
t += abs(id(bank_a_total_current).state);
if (id(bank_b_total_current).has_state())
t += abs(id(bank_b_total_current).state);
return t;
# =====================================================
# OTHER SENSORS
# =====================================================
- platform: wifi_signal
name: "WiFi Signal"
id: wifi_signal_db
unit_of_measurement: "dBm"
device_class: signal_strength
state_class: measurement
entity_category: diagnostic
update_interval: 30s
# --------------------------------------
# ADC0 - ADC Scaled Voltage from VDC
# --------------------------------------
- platform: ads1115
multiplexer: A0_GND
gain: 4.096
id: adc0_raw
update_interval: 1s
filters:
- sliding_window_moving_average:
window_size: 50
send_every: 50
- platform: template
name: "ADC Scaled Voltage VDC"
entity_category: diagnostic
unit_of_measurement: "V"
accuracy_decimals: 2
lambda: |-
float voltage;
voltage =
(id(adc0_raw).state *
id(dc_voltage_factor))
+
id(dc_voltage_drop);
if (voltage < 0.010)
voltage = 0;
return voltage;
# -----------------------------------------
# ADC1 - ADC Scaled Voltage from ADC1 Input
# -----------------------------------------
- platform: ads1115
multiplexer: A1_GND
gain: 4.096
id: adc1_raw
update_interval: 1s
filters:
- sliding_window_moving_average:
window_size: 50
send_every: 50
- platform: template
name: "ADC Scaled Voltage ADC1"
entity_category: diagnostic
unit_of_measurement: "V"
accuracy_decimals: 3
lambda: |-
float voltage =
(id(adc1_raw).state *
id(adc_voltage_factor))
+
id(dc_voltage_drop);
if (voltage < 0.65)
voltage = 0;
return voltage;