Build a Multi-Circuit Home Energy Monitor with ESP32-S3 and ESPHome

Monitor six electrical circuits non-invasively using an ESP32-S3, SCT-013-030 current clamps, and ESPHome. Track real-time current, apparent power, and accumulated energy directly in Home Assistant.

Illustration for: Build a Multi-Circuit Home Energy Monitor with ESP32-S3 and ESPHome
AI-generated illustration
Difficulty: IntermediateTime: variesTested on my setup

Tested on: Tested on an ESP32-S3-WROOM-1 (N16R8, 16MB flash / 8MB PSRAM) using ESPHome with the Arduino framework and Home Assistant.

Before you start

Monitoring whole-house electricity consumption from a single utility meter leaves you guessing which individual appliances drive up your power bill. While smart inline breakers exist, using uncertified hardware as the sole point of protection in a main panel introduces serious safety risks.

In this project, you will build a safe, non-invasive six-channel energy monitor using an ESP32-S3 development board, SCT-013-030 current transformer (CT) clamps, and ESPHome. You will assemble a DC bias conditioning circuit, calibrate the sensors against a known load, and feed real-time power and energy metrics into Home Assistant.

What you need

  • 1x ESP32-S3-WROOM-1 development board (N16R8 recommended, with CH343 USB-to-UART bridge)
  • 6x SCT-013-030 current transformer clamps (30A max, internal burden resistor, 0-1 Vrms output)
  • 8x 10kΩ resistors (2 for shared bias rail, 6 for individual channel bias)
  • 7x 10µF electrolytic capacitors (1 for shared bias rail, 6 for channel AC coupling)
  • Solderless breadboard or perfboard and jumper wires
  • Known resistive test load (e.g., a 35W incandescent lamp) for bench calibration
  • Home Assistant installation with the ESPHome integration or CLI
  • Optional: One or two Zigbee smart plugs with voltage reporting for live line voltage tracking

Step 1 · Understand the Analog Bias Circuit

The ESP32-S3 Analog-to-Digital Converter (ADC) only measures positive DC voltages between 0V and 3.3V. However, the SCT-013-030 current transformer outputs an alternating current (AC) signal that swings both positive and negative around 0V (~0 to 1 Vrms).

If connected directly to the ESP32, the negative half of the AC waveform would be clipped and could damage the microcontroller. To solve this, we create a virtual ground reference (BIAS) centered at approximately 1.65V (half of 3.3V).

A shared voltage divider made of two 10kΩ resistors and a 10µF smoothing capacitor establishes this steady 1.65V rail. Each sensor channel then connects its ADC pin to this 1.65V reference through an individual 10kΩ resistor, while a 10µF series capacitor couples the AC signal from the clamp into the pin while blocking DC.

Bias Circuit Schematic Concept
Shared Virtual Ground (BIAS ~1.65V):
  3.3V ---[ 10kΩ ]---+---[ 10kΩ ]--- GND
                     |
                     +---[ 10µF ]--- GND
                     |
                     v (BIAS Rail: ~1.65V)

Per-Channel Circuit (Repeat for Channels 1 to 6):
  BIAS Rail ---[ 10kΩ ]---+---> ESP32 GPIO (ADC1)
                          |
  CT Signal ---[ 10µF ]---+
  CT Return ------------------> GND

Step 2 · Prepare the Current Clamp Leads

The SCT-013-030 typically terminates in a 3.5mm stereo jack. While 3.5mm female breakout sockets can be used, cutting the jack off simplifies breadboard wiring.

Cut off the 3.5mm jack and carefully strip the outer PVC jacket back by about 3 cm. Inside, you will find a coaxial assembly: a braided copper shield surrounding an insulated inner conductor. Untwist the braided copper shield and twist it into a single stranded wire, then strip a short section of the inner insulated wire.

Because the sensor measures alternating current (AC) and ESPHome calculates root-mean-square (RMS) magnitude, polarity does not matter. Reversing the two leads simply inverts the AC phase, yielding the exact same RMS current value.

CT Clamp Wire Identification
Outer Jacket Removed:
  ├── Braided Copper Shield (Twisted into lead A) -> Connect to GND
  └── Inner Insulated Core (Stripped lead B)      -> Connect to 10µF AC coupling capacitor

Step 3 · Assemble the Breadboard Conditioning Circuit

Assemble the shared reference and the six sensor channels on a breadboard or prototyping board.

1. Shared Reference: Place two 10kΩ resistors in series between the ESP32 3.3V pin and GND. Connect a 10µF capacitor between their junction and GND (observing capacitor polarity: positive lead to junction, negative lead to GND). This creates the stabilized ~1.65V BIAS node.

2. Channel Conditioning: For each channel, connect a 10kΩ resistor from the shared 1.65V BIAS node to the designated ESP32 ADC pin. Connect the positive leg of a 10µF capacitor to the same ADC pin, and connect its negative leg to the center core lead of your CT clamp. Connect the braided shield lead of the CT clamp directly to GND.

Repeat this configuration for all six channels across GPIO1 through GPIO6.

ESP32-S3 GPIO Mapping
Channel 1 -> GPIO1 (ADC1)
Channel 2 -> GPIO2 (ADC1)
Channel 3 -> GPIO3 (ADC1)
Channel 4 -> GPIO4 (ADC1)
Channel 5 -> GPIO5 (ADC1)
Channel 6 -> GPIO6 (ADC1)

Shared Bias -> Connects to 3.3V, GND, and 10kΩ pull-ups for all channels.

Step 4 · Configure ESPHome Firmware

Create the ESPHome configuration file energy-monitor.yaml.

Key firmware design choices: - Disable Onboard RGB LED: Many ESP32-S3 boards include an addressable WS2812 LED on GPIO48. Leaving this pin floating results in noisy red flickering. We configure it as an esp32_rmt_led_strip with restore_mode: ALWAYS_OFF. - Handling Idle Channels (NaN Fix): ESPHome's ct_clamp component calculates current based on changing sample values. On idle circuits with no current, zero changing samples are recorded, causing the component to output NaN. Home Assistant interprets NaN as entity unavailable. A lambda filter if (std::isnan(x)) return 0.0f; resolves this. - Noise Threshold: Sensor channels have an analog noise floor of ~0.12A without load. A filter sets readings below 0.15A to 0.0A. For compressor loads (like air conditioners), standby noise can fluctuate between 0.15A and 0.17A (16-19W false readings), so a higher threshold of 0.30A is applied to those channels. - Dynamic Grid Voltage: Rather than assuming a constant voltage, the firmware imports live grid voltage from Home Assistant smart plugs (valid between 90V and 140V), falling back to a fixed 113V fallback if unavailable.

Firmware Excerpt: Filters and Voltage Template
substitutions:
  voltaje_red: "113"
  noise_threshold: "0.15"
  noise_threshold_ac: "0.30"

sensor:
  - platform: homeassistant
    id: v_smart_plug_1
    entity_id: sensor.smart_plug_1_voltage
    internal: true
  - platform: homeassistant
    id: v_smart_plug_2
    entity_id: sensor.smart_plug_2_voltage
    internal: true

  - platform: template
    id: voltaje_red_real
    name: "Grid Voltage Used"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 0
    update_interval: 30s
    lambda: |-
      float a = id(v_smart_plug_1).state;
      float b = id(v_smart_plug_2).state;
      if (!std::isnan(a) && a > 90.0f && a < 140.0f) return a;
      if (!std::isnan(b) && b > 90.0f && b < 140.0f) return b;
      return ${voltaje_red}.0f;

Step 5 · Flash the Microcontroller via USB and OTA

Many dual-port ESP32-S3 boards feature one native USB-C port (USB-JTAG) and one serial bridge port (marked COMM, powered by a CH343 chip).

If esptool fails on the native port with 'No serial data received', switch your cable to the COMM port. On Windows, execute the compilation and upload from PowerShell rather than Git Bash.

Note that the ESPHome logger defaults to USB_SERIAL_JTAG. When connected to the CH343 COMM port, serial logs will not print in your terminal even though flashing succeeds. Once the initial flash completes and the device joins your Wi-Fi network, monitor all runtime logs and perform subsequent updates wirelessly via Over-The-Air (OTA).

Flash via ESPHome CLI (PowerShell)
# Initial USB flash via the COMM port
esphome run energy-monitor.yaml

# Wireless OTA updates and log monitoring
esphome run energy-monitor.yaml --device <DEVICE_IP> --no-logs
esphome logs energy-monitor.yaml --device <DEVICE_IP>

Step 6 · Calibrate Channels with a Known Load

Before clipping the sensors inside an electrical panel, calibrate them on your workbench using a known resistive load.

1. Clamp Channel 1 around one conductor of a split power cord connected to a known resistive load (for example, a 35W incandescent bulb running at ~108V, drawing an expected ~0.32A). 2. With a generic placeholder calibration in ESPHome (1.0 -> 30.0), observe the reported current. In our tests, the raw reading under the 0.32A load reported 0.63A. 3. Calculate the raw ADC point: 0.63 / 30.0 = 0.021. 4. Update the linear calibration filter in your configuration: 0.0 -> 0.0 and 0.021 -> 0.32. 5. Flash the update via OTA. Verify that the sensor now measures 0.32A - 0.33A.

Repeat or duplicate this calibration across channels 2 through 6. In bench testing, applying this calibration to identical SCT-013-030 clamps yielded consistency within ±7%.

Calibrate Linear Filter
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold}) ? 0.0 : x;'

Step 7 · Install the Clamps (Qualified Person Only)

This is the only step that happens inside your electrical panel, and it is the one I do NOT walk you through. If you are not a qualified electrician, ask a licensed electrician to clip the clamps for you, and show them what the sensors are: clip-on current sensors that go around insulated wires and never touch the metal.

What you need to tell them: each clamp goes around exactly ONE insulated conductor of the circuit you want to measure, never around both wires of a cable together, and its thin signal cable must stay away from any bare metal. The clamps should already be wired to your conditioning board and calibrated on the bench (step 6) before they go anywhere near the panel.

Mains voltage can kill. If you are not sure, do not open the panel.

Step 8 · Configure Home Assistant Energy and Utility Meters

ESPHome streams current (A) and apparent power (W) to Home Assistant. To convert instantaneous watts into accumulated kilowatt-hours (kWh) and track utility billing cycles, create a package file packages/energy_monitor.yaml in your Home Assistant configuration directory.

Important configuration details: - max_sub_interval: 5 min: When a circuit stays at 0W for hours (such as an idle appliance or air conditioner), Riemann sum integration sensors will stop updating and fall into an 'unknown' state unless max_sub_interval is explicitly defined. - utility_meter: Tracks accumulated energy across billing periods. If your billing cycle uses an offset (for instance, starting on a specific day of the month), define offset: {days: N}.

Home Assistant Package Excerpt
sensor:
  - platform: integration
    source: sensor.circuit_1_power
    name: "Circuit 1 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

utility_meter:
  bimonthly_circuit_1:
    source: sensor.circuit_1_energy
    name: "Circuit 1 Bimonthly"
    cycle: bimonthly

Troubleshooting

Flashing fails via USB with 'No serial data received' in esptool.

Switch your USB-C cable from the native USB-JTAG port to the secondary port labeled COMM (driven by the CH343 chip). In Windows, run ESPHome through PowerShell instead of Git Bash.

Current sensor periodically reports 'unknown' or 'unavailable' in Home Assistant.

The ESPHome ct_clamp component only counts changing samples. On an idle circuit with zero load, 0 changing samples cause it to output NaN. Add a lambda filter converting NaN to 0.0f prior to calibration.

Air conditioner or heavy appliance circuits report phantom power (16-19W) while turned off.

Idle electronic circuitry and line noise can cause the sensor to hover between 0.15A and 0.17A, just above the general 0.15A noise threshold. Increase the noise cutoff substitution noise_threshold_ac to 0.30A on those specific channels.

Onboard RGB LED glows solid red or flickers continuously.

Add an esp32_rmt_led_strip platform entry for the WS2812 LED on GPIO48 with restore_mode: ALWAYS_OFF in your ESPHome configuration to prevent the pin from floating.

No serial output appears in the console after flashing.

The ESPHome runtime logger defaults to USB_SERIAL_JTAG. When plugged into the CH343 COMM port, logs do not route to serial. Inspect live logs over Wi-Fi/API instead using esphome logs energy-monitor.yaml --device <IP>.

What I learned

  • ct_clamp requires changing samples: A completely idle channel can output zero changing samples, producing NaN. A simple lambda filter returning 0.0f when std::isnan(x) is true prevents entities from becoming unavailable in Home Assistant.
  • Dual USB-C ports on ESP32-S3 boards behave differently: The native USB-JTAG port may fail initial flashing with esptool, while the CH343 COMM port flashes reliably but does not output default logger streams.
  • Floating pins cause WS2812 noise: The onboard RGB LED on GPIO48 must be explicitly configured and held off in firmware to avoid glowing red from stray electrical noise.
  • Apparent power vs real power: Calculating power by multiplying current by grid voltage yields apparent power (VA). It matches true watts on resistive heaters, but overestimates inductive compressor and motor loads by 10% to 20% due to power factor.
  • Riemann sum integration requires max_sub_interval: In Home Assistant, integrating power to kWh without max_sub_interval: 5 min leaves sensors in an 'unknown' state whenever a monitored circuit sits at 0W for extended periods.

Next steps

  • Calibrate overall power factor against an official utility bill once you receive a full billing cycle of data.
  • Sub-meter specific high-power appliances on a branch circuit using Zigbee monitoring plugs to calculate residual circuit consumption.
  • Expand the board to monitor up to 10 channels by using the remaining free ADC1 pins (GPIO7, GPIO8, GPIO9, and GPIO10).

Get the code

ESPHome configuration, Home Assistant package, and example secrets for a 6-circuit ESP32-S3 home energy monitor using SCT-013-030 clamps.

View the code on GitHub →

Files in the repository (4)

README.md

README.md
# Multi-Circuit Home Energy Monitor (ESP32-S3 + ESPHome)

A non-invasive, 6-channel home energy monitor built with an ESP32-S3 development board, SCT-013-030 current transformer (CT) clamps, and ESPHome.

## Hardware Overview

- **Microcontroller**: ESP32-S3-WROOM-1 (N16R8, 16MB Flash, 8MB PSRAM)
- **Sensors**: 6x SCT-013-030 Current Transformers (30A max, internal burden resistor, 0-1 Vrms output)
- **Conditioning Circuit**:
  - Shared Virtual Ground: 2x 10kΩ resistors + 1x 10µF capacitor (creates ~1.65V BIAS)
  - Per-Channel: 1x 10kΩ resistor (pull-up to BIAS) + 1x 10µF capacitor (AC coupling)
- **ADC Pins Used**: GPIO1, GPIO2, GPIO3, GPIO4, GPIO5, GPIO6 (all on ADC1)

## Repository Contents

- `energy-monitor.yaml`: ESPHome firmware configuration.
- `secrets.yaml.example`: Template for Wi-Fi, OTA, and API credentials.
- `packages/energy_monitor.yaml`: Home Assistant package defining Riemann sum energy integration sensors (W → kWh), template power sensors, and bimonthly utility meters.

## Setup Instructions

### 1. Circuit Assembly

1. Construct the shared 1.65V reference rail using two 10kΩ resistors between 3.3V and GND, stabilized with a 10µF capacitor to GND.
2. For each CT clamp, connect the inner core lead through a 10µF capacitor to the channel's ADC pin, tie that ADC pin to the 1.65V reference via a 10kΩ resistor, and connect the outer braided shield to GND.
3. Connect the channel signal lines to GPIO1 through GPIO6 on the ESP32-S3.

### 2. Flashing ESPHome

1. Copy `secrets.yaml.example` to `secrets.yaml` and configure your Wi-Fi SSID, password, OTA password, and API encryption key.
2. Connect the ESP32-S3 via the CH343 COMM port.
3. Flash the firmware using the ESPHome CLI:
   ```bash
   esphome run energy-monitor.yaml
   ```
4. For subsequent updates over your local network:
   ```bash
   esphome run energy-monitor.yaml --device <DEVICE_IP> --no-logs
   ```

### 3. Bench Calibration

1. Place a CT clamp around a single conductor powering a known resistive load (e.g., a 35W incandescent bulb).
2. Note the reported current with the placeholder calibration (`1.0 -> 30.0`).
3. Calculate the raw ratio (`measured / 30.0`) and set the `calibrate_linear` filter values accordingly.
4. Upload the calibrated configuration via OTA.

### 4. Home Assistant Integration

1. Place `packages/energy_monitor.yaml` in your Home Assistant `packages/` directory.
2. Ensure `configuration.yaml` includes packages:
   ```yaml
   homeassistant:
     packages: !include_dir_named packages
   ```
3. Restart Home Assistant to load the energy integration and utility meter sensors.

secrets.yaml.example

secrets.yaml.example
# ESPHome Secrets Template
# Copy this file to secrets.yaml and populate with your network credentials.

wifi_ssid: "YOUR_WIFI_SSID"
wifi_password: "YOUR_WIFI_PASSWORD"
wifi_ap_password: "YOUR_FALLBACK_HOTSPOT_PASSWORD"

api_encryption_key: "GENERATE_A_BASE64_KEY_HERE="
ota_password: "YOUR_OTA_PASSWORD"

energy-monitor.yaml

energy-monitor.yaml
substitutions:
  voltaje_red: "113"      # Fallback line voltage (V) if smart plug reports are unavailable
  noise_threshold: "0.15"    # General noise cutoff threshold (A); below this reports 0.0
  noise_threshold_ac: "0.30" # Noise cutoff threshold (A) for compressor/AC circuits to prevent idle drift

esphome:
  name: home-energy-monitor
  friendly_name: "Home Energy Monitor"

esp32:
  board: esp32-s3-devkitc-1
  variant: esp32s3
  framework:
    type: arduino

logger:

# Turn off onboard WS2812 RGB LED on GPIO48 to eliminate floating-pin noise/flicker
light:
  - platform: esp32_rmt_led_strip
    id: rgb_led_onboard
    pin: GPIO48
    num_leds: 1
    rgb_order: GRB
    chipset: ws2812
    name: "Onboard RGB LED"
    internal: true
    restore_mode: ALWAYS_OFF

api:
  encryption:
    key: !secret api_encryption_key

ota:
  - platform: esphome
    password: !secret ota_password

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "Energy-Monitor-Fallback-AP"
    password: !secret wifi_ap_password

sensor:
  # --- Real Grid Voltage Tracking ---
  # Imports line voltage reported by smart plugs in Home Assistant.
  # Falls back to ${voltaje_red} if values are out of range (90V - 140V) or unavailable.
  - platform: homeassistant
    id: v_smart_plug_1
    entity_id: sensor.smart_plug_1_voltage
    internal: true
  - platform: homeassistant
    id: v_smart_plug_2
    entity_id: sensor.smart_plug_2_voltage
    internal: true
  - platform: template
    id: voltaje_red_real
    name: "Grid Voltage Used"
    unit_of_measurement: V
    device_class: voltage
    state_class: measurement
    accuracy_decimals: 0
    update_interval: 30s
    lambda: |-
      float a = id(v_smart_plug_1).state;
      float b = id(v_smart_plug_2).state;
      if (!std::isnan(a) && a > 90.0f && a < 140.0f) return a;
      if (!std::isnan(b) && b > 90.0f && b < 140.0f) return b;
      return ${voltaje_red}.0f;

  # --- Circuit 1: General Main Level ---
  - platform: adc
    pin: GPIO1
    id: adc_circuit_1
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_1
    id: corr_c1
    name: "Circuit 1 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c1
    id: pot_c1
    name: "Circuit 1 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

  # --- Circuit 2: Kitchen & Utility ---
  - platform: adc
    pin: GPIO2
    id: adc_circuit_2
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_2
    id: corr_c2
    name: "Circuit 2 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.0207 -> 0.31
      - lambda: 'return (x < ${noise_threshold}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c2
    id: pot_c2
    name: "Circuit 2 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

  # --- Circuit 3: Upper Level ---
  - platform: adc
    pin: GPIO3
    id: adc_circuit_3
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_3
    id: corr_c3
    name: "Circuit 3 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c3
    id: pot_c3
    name: "Circuit 3 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

  # --- Circuit 4: Refrigerator & Microwave ---
  - platform: adc
    pin: GPIO4
    id: adc_circuit_4
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_4
    id: corr_c4
    name: "Circuit 4 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c4
    id: pot_c4
    name: "Circuit 4 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

  # --- Circuit 5: AC Zone 1 ---
  - platform: adc
    pin: GPIO5
    id: adc_circuit_5
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_5
    id: corr_c5
    name: "Circuit 5 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold_ac}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c5
    id: pot_c5
    name: "Circuit 5 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

  # --- Circuit 6: AC Zone 2 ---
  - platform: adc
    pin: GPIO6
    id: adc_circuit_6
    attenuation: 12db
    update_interval: never
  - platform: ct_clamp
    sensor: adc_circuit_6
    id: corr_c6
    name: "Circuit 6 Current"
    update_interval: 30s
    sample_duration: 200ms
    filters:
      - lambda: |-
          if (std::isnan(x)) return 0.0f;
          return x;
      - calibrate_linear:
          - 0.0 -> 0.0
          - 0.021 -> 0.32
      - lambda: 'return (x < ${noise_threshold_ac}) ? 0.0 : x;'
  - platform: copy
    source_id: corr_c6
    id: pot_c6
    name: "Circuit 6 Power"
    unit_of_measurement: W
    device_class: power
    state_class: measurement
    accuracy_decimals: 0
    filters:
      - lambda: |-
          float v = id(voltaje_red_real).state;
          return x * (std::isnan(v) ? ${voltaje_red}.0f : v);

packages/energy_monitor.yaml

packages/energy_monitor.yaml
# Home Assistant Package: Energy Monitor Integrations & Utility Meters

template:
  - sensor:
      # Individual circuit power in kW for gauge dashboards
      - name: "Circuit 1 Power kW"
        unique_id: circuit_1_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_1_power') | float(0) / 1000) | round(2) }}
      - name: "Circuit 2 Power kW"
        unique_id: circuit_2_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_2_power') | float(0) / 1000) | round(2) }}
      - name: "Circuit 3 Power kW"
        unique_id: circuit_3_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_3_power') | float(0) / 1000) | round(2) }}
      - name: "Circuit 4 Power kW"
        unique_id: circuit_4_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_4_power') | float(0) / 1000) | round(2) }}
      - name: "Circuit 5 Power kW"
        unique_id: circuit_5_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_5_power') | float(0) / 1000) | round(2) }}
      - name: "Circuit 6 Power kW"
        unique_id: circuit_6_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (states('sensor.circuit_6_power') | float(0) / 1000) | round(2) }}

      # Total house monitored power
      - name: "Total House Monitored Power kW"
        unique_id: total_house_monitored_power_kw
        unit_of_measurement: "kW"
        device_class: power
        state: >-
          {{ (
            (states('sensor.circuit_1_power') | float(0) +
             states('sensor.circuit_2_power') | float(0) +
             states('sensor.circuit_3_power') | float(0) +
             states('sensor.circuit_4_power') | float(0) +
             states('sensor.circuit_5_power') | float(0) +
             states('sensor.circuit_6_power') | float(0)) / 1000
          ) | round(2) }}

sensor:
  # --- Riemann Sum Energy Integration (W -> kWh) ---
  # max_sub_interval ensures sensors do not fall to 'unknown' during 0W periods
  - platform: integration
    source: sensor.circuit_1_power
    name: "Circuit 1 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

  - platform: integration
    source: sensor.circuit_2_power
    name: "Circuit 2 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

  - platform: integration
    source: sensor.circuit_3_power
    name: "Circuit 3 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

  - platform: integration
    source: sensor.circuit_4_power
    name: "Circuit 4 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

  - platform: integration
    source: sensor.circuit_5_power
    name: "Circuit 5 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

  - platform: integration
    source: sensor.circuit_6_power
    name: "Circuit 6 Energy"
    unit_prefix: k
    round: 3
    method: left
    max_sub_interval: 5 min

utility_meter:
  # --- Bimonthly Utility Billing Trackers ---
  # Provides current cycle totals and a 'last_period' attribute for prior billing cycle
  bimonthly_circuit_1:
    source: sensor.circuit_1_energy
    name: "Circuit 1 Bimonthly"
    cycle: bimonthly

  bimonthly_circuit_2:
    source: sensor.circuit_2_energy
    name: "Circuit 2 Bimonthly"
    cycle: bimonthly

  bimonthly_circuit_3:
    source: sensor.circuit_3_energy
    name: "Circuit 3 Bimonthly"
    cycle: bimonthly

  bimonthly_circuit_4:
    source: sensor.circuit_4_energy
    name: "Circuit 4 Bimonthly"
    cycle: bimonthly

  bimonthly_circuit_5:
    source: sensor.circuit_5_energy
    name: "Circuit 5 Bimonthly"
    cycle: bimonthly

  bimonthly_circuit_6:
    source: sensor.circuit_6_energy
    name: "Circuit 6 Bimonthly"
    cycle: bimonthly