CircuitSetup / Expandable-6-Channel-ESP32-Energy-Meter

Hardware & Software documentation for the CircuitSetup Expandable 6 Channel ESP32 Energy Meter. Works with ESPHome and Home Assistant.
https://circuitsetup.us/product/expandable-6-channel-esp32-energy-meter/
MIT License
510 stars 102 forks source link
energy-monitor energymeter esp32 esphome home-assistant homeassistant

Expandable 6 Channel ESP32 Energy Meter v1.3 Main Board

CircuitSetup Expandable 6 Channel ESP32 Energy Meter

The Expandable 6 Channel ESP32 Energy Meter can read 6 current channels and 2 voltage channels at a time. Much like our Split Single Phase Energy Meter, the 6 channel uses current transformers and an AC transformer to measure voltage and power the board(s)/ESP32. The main board includes a buck converter to power the electronics and ESP32 dev board, which plugs directly into the board. Up to 6 add-on boards can stack on top of the main board to allow you to monitor up to 42 current channels in 16-bit resolution, in real time, all at once!

Usage:

Features:

What you'll need:

Setting up the Meter

Expandable 6 Channel ESP32 Energy Meter Diagram Expandable 6 Channel ESP32 Energy Meter Back Diagram

Plugging in the ESP32

The Expandable 6 Channel ESP32 Energy Meter is made so that an ESP32 dev board can be plugged directly into the meter. See the list above for compatible ESP32 dev boards. Always insert the ESP32 with the 3V3 pin in the upper left of the meter. The bottom pins are used to connect the voltage signal (from the power plug) to add-on boards. If the ESP32 is inserted into the bottom pins it will more than likely short the ESP32.

Communicating with the ESP32

The Expandable 6 Channel ESP32 Energy Meter uses SPI to communicate with the ESP32. Each board uses 2 CS pins.

The main board uses the following SPI pins:

The version of EmonESP available here has all of these pins set by default.

For examples of how to set up your config in ESPHome, see here and here.

Add-on Boards

Add-on boards (up to 6) can expand the main energy meter up to 42 current channels & 8 voltage channels. The add-on boards plug directly into the main board as seen here.

The add-on board allows the CS pin to be selected based on the jumper settings at the bottom of the board. This is so multiple add-on boards can be used - up to 6 maximum. Do NOT select more than one CS pin per bank. The CS pins can be:

Expandable 6 Channel ESP32 Energy Meter Add-on Diagram

Calibrating Current Sensors & Voltage (AC Transformer)

See here for the calibration procedure, or here for a video

Common Calibration Values

Measuring Power & Other Metering Values

The Expandable 6 Channel ESP32 Energy Meter uses 2 ATM90E32AS ICs. Each IC has 3 voltage channels and 3 current channels. In order for power metering data to be calculated internally, each current channel must have a reference voltage. If the voltage is out of phase with the current, then the current and power will read as negative, affecting the power factor and power calculations. If you have a split single phase or dual phase setup, the solution is to turn around the current transformer on the wire.

v1.1 of the meter used 1 of the voltage channels for each IC. This means that power and metering data would have to be calculated in software, or voltage channels would have to be mapped via changing registers on the IC to get power and metering data from CT2, CT3, CT5, CT6.

v1.2 & v1.3 have JP8-JP11 on the back of the board, that would allow all voltage channels to be connected together, which would allow power and other metering values to be calculated. Most of v1.3 came soldered together.

v1.4 removed JP8-JP11, and has voltage channels connected internally on the pcb.

Measuring Dual Pole (240V) Circuits

For split single phase applications, dual pole circuits have 2 hot wires that total 240V (usually red and black in newer buildings). In most cases both poles are used equally, but in others there may be electronics in the applicance that use only 1 pole. There are 3 different options for measuring these circuits:

Measuring A Second Voltage

The holes labelled VA2 next to the power plug on the meter main board, and in the bottom right of the add-on board are for measuring a second voltage. To do this you must:

When voltage jumpers are severed, the voltage reference for CT4-CT6 will be from VA2. This means that current transformers for CT4-CT6 should be hooked up to circuits that are on the same phase as VA2, and CT1-CT3 should be hooked up to circuits that are in phase with the primary voltage. If a CT is not in phase with the voltage its current and power readings will be negative. If, for example, you have 4 circuits in phase with the primary, and 2 in phase with VA2, you can reverse the current transformer on the wire to put it in phase with the voltage (assuming split single phase or dual phase)

For add-on boards, the primary voltage will come from the main board. The optional secondary voltage measurement (also VA2 pins), will be in phase with CT4-CT6.

Measuring 3-Phase Electricity

What you'll need to measure all 3 phases properly:

The transformers should be calibrated individually for greater accuracy.

Alternately, you can use 2 add-on boards and connect 1 transformer to to each board:

On 3-phase systems, a current transformer that's connected to a phase not in phase with the voltage reference will always result in near-zero active power and power factor.

Setting Up Software

EmonESP/EmonCMS

EmonESP is used to send energy meter data to a local install of EmonCMS, or emoncms.org. Data can also be sent to a MQTT broker through this. EmonCMS has Android and IOS apps. The ESP32 sofware for EmonESP is located here, and can be flash to an ESP32 using the Arduino IDE or PlatformIO. See details on setup here.

ESPHome/Home Assistant

ESPHome can be loaded on an ESP32 to seamlessly integrate energy data into Home Assistant. Energy data can then be saved in InfluxDB and displayed with Grafana. At the same time, the energy data can also be used for automations in Home Assistant.

A new feature in Home Assistant allows you to monitor electricity usage directly in Home Assistant. You can also track usage of individual devices and/or solar using the 6 channel meter!

Flashing ESPHome

ESPHome add-on

ESPHome Download Binary

ESPHome Flasher

Loading the Energy Meter Config

yaml config edit

ESPHome node

Getting Data in InfluxDB

Getting Data in the Home Assistant Energy Dashboard

Home Assistant Energy Config

To display data in the Home Assistant Energy Dashboard you must be using ESPHome v1.20.4 or higher, and have at least one total_daily_energy platform configured in your ESPHome config. time is also needed.

For Total Energy Consumption
#Total kWh
  - platform: total_daily_energy
    name: ${disp_name} Total kWh
    power_id: totalWatts
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh
time:
  - platform: sntp
    id: sntp_time 

Where totalWatts is the sum of all watt calculations on the meter. See an example of this here. In the example, this was done with a lambda template.

For Solar Panels

The same can be done as above to track solar panel use and export. The current channels on the meter that are tracking solar usage must have their own lambda template calculation.

See this example for how you could set this up with the 6 Channel Meter.

For Individual Device/Circuit Tracking

To do this you must have power calulated by the meter, or a lambda template that calculates watts per circuit. Then can use a kWh platform for each of the current channels on the 6 channel energy meter. For example:

#CT1 kWh
  - platform: total_daily_energy
    name: ${disp_name} CT1 Watts Daily
    power_id: ct1Watts
    filters:
      - multiply: 0.001
    unit_of_measurement: kWh

ct1Watts references the id of the watt calculation. In the example config, this is:

      power:
        name: ${disp_name} CT1 Watts
        id: ct1Watts
Setup in Home Assistant

FAQ

Q: I am getting a low reading, or nothing at all for one CT - what is wrong?

A: Sometimes the jack for the CT is a bit stiff, and you may need to push in the CT connector into the board jack until it clicks. If it is definitely all the way in, it's possible the connector or somewhere else has a loose connection, and we will replace the meter for free.

Q: Does the 6 channel energy meter work in my country?

A: Yes! There is a setting to set the meter to 50Hz or 60Hz power. You will need to purchase an AC transformer that brings down the voltage to between 9-12V AC. Transformers for the US are for sale in the circuitsetup.us store.

Q: I'm getting a negative value on one current channel. What is going on?

A: This usually means that the CT is on the wire backwords - just turn it around!

Q: I'm getting a small negative value when there is no load at all, but a positive value otherwise. What is going on?

A: This is caused by variances in resistors and current transformers. You can either calibrate the current transformers to the meter, or add this lambda section to only allow positive values for a current channel:

  - platform: template
    name: ${disp_name} CT1 Watts Positive
    id: ct1WattsPositive
    lambda: |-
      if (id(ct1Watts).state < 0) {
        return 0;
      } else {
        return id(ct1Watts).state ;
      }
    accuracy_decimals: 2
    unit_of_measurement: W
    icon: "mdi:flash-circle"
    update_interval: ${update_time}

Then for your total watts calculation, use ct1WattsPositive

Q: The CT wires are not long enough. Can I extend them?

A: Yes, you absolutely can! Something like a headphone extension or even an ethernet wire can be used (if you don't mind doing some wiring). It is recommended to calibrate the CTs after adding any particularly long entension.

Q: Can I use this CT with the 6 channel meter?

A: More than likely, yes! As long as the output is rated at less than 720mV RMS, or 33mA.

Q: Can I use SCT-024 200A CTs with the 6 channel meter?

A: If you need to measure up to 200A, then this is not recommended. At 200A, our newest SCT-024's will output 50mA. That means, the max you should measure with the SCT-024 plugged into the 6 channel meter is 132A. In a residential setting with 200A service, it is highly unlickly that you will use more than 132A per phase sustained. In fact, unless you have your own dedicated transformer, and a very large house, it is impossible.

Q: How do I know if my CT has a burden resistor?

A: There is a built in burden resistor if the output is rated in volts. In this case the corresponding jumper on the rear of the meter should be severed.

Q: When using more than 3 add-on boards, ESPHome does not work.

A: ESPHome will run out of stack memory after using more than 15 sensors, or so. You will have to increase the stack memory size before compiling. See details here.

UPDATE: You can replace the esphome: definition in your ESPHome config to solve this issue with the following:

esphome:
  name: 6chan_energy_meter
  platformio_options:
    build_flags: 
      - -DCONFIG_ARDUINO_LOOP_STACK_SIZE=32768

esp32:
  board: nodemcu-32s
  variant: esp32
  framework:
    type: arduino
    version: 2.0.2
    source: https://github.com/espressif/arduino-esp32.git#2.0.2
    platform_version: https://github.com/platformio/platform-espressif32.git#feature/arduino-upstream

More resources: