In this guide, you will learn to build a smart energy monitoring device or smart electricity meter from scratch using an ESP8266 module, such as NodeMCU, ESP32, or D1 Mini, and SCT013—a non-invasive AC current sensor.

Things You’ll Need

To build this smart energy monitoring device, you need the following,

A NodeMCU, D1 Mini, or ESP32 Microcontroller. For this project, we have used NodeMCU (ESP8266). An SCT013 30A 1V Non-Invasive AC Current Clamp Sensor. You may also use a 5A 1V, 10A 1V, 15A 1V, 20A 1V, 50A 1V, or 100A 1V rated SCT013 sensor as per your requirement. MicroUSB Cable A general-purpose PCB A 10µf 16V capacitor Two 10K resistors (1/4 watt) One 33 Ohm resistor (1/4 watt)

Steps to Build Smart Energy Monitoring Device

Below are the steps you may follow to build an IoT-based smart energy monitoring device to track power consumption.

Step 1: Install and Setup Home Assistant

Follow our previous DIY guide to install and set up home assistant on Raspberry Pi. If you don’t have a Raspberry Pi, you may also use your old laptop. However, the laptop will have a larger energy footprint and consume more power than the Raspberry Pi 3 or Raspberry Pi 4.

Step 2: Install ESPHome Add-On in Home Assistant (HA)

ESPHome is an add-on available in the Home Assistant that will be used to create custom firmware and flash it on the ESP32, NodeMCU, or D1Mini microcontroller. Follow these steps to install the ESPHome add-on in HA.

In Home Assistant, go to Configuration and click on Add-ons, Backups & Supervisor.

Click Add-On Store.

In the search bar, type ESPHome and then click on ESPHome listed under Home Assistant Community Add-Ons.

Click Install.

This will install the ESPHome Dashboard in your Home Assistant. After the installation, click Start.

Also enable Watchdog, Auto-update, and Show in the sidebar. Then click Open Web UI to launch ESPHome Dashboard.

Click +New Device > Continue.

Enter the name for the configuration, such as smart-power-meter, and click Next.

Select the ESP32 for ESP32 MCU or ESP8266 if you are using D1 Mini or NodeMCU and click Next.

Click Skip.

Find the newly created project and click Edit.

In the smart-power-meter.yaml file, copy and paste this YAML code.

Now make the following changes before saving,

Change the Wi-Fi credential and passwords. We have added a lambda function to calculate power consumption for a 230 Volt supply. But some countries have 110V or 120V as standard supply, such as the United States. If you live in those countries, make sure to change the value from 230 to 110 or 120.

Click Save and then click Install. Choose Plug into this computer.

The ESPHome will compile the code and create a binary or .bin firmware file, such as smart-power-meter.bin. This may take a while to complete.

Once the firmware is compiled, click Download Project. This will download the .bin firmware file on your PC.

Connect the NodeMCU, ESP32, or D1 Mini board to your PC or Mac using a micro USB cable.

Download the ESPHome-Flasher tool and launch it. It is available for Windows, macOS, and Ubuntu.

Select the COM port, browse to the .bin firmware file and then click Flash ESP.

After flashing the firmware, the device ESP MCU will connect to the Wi-Fi network and will be online in the ESPHome Dashboard.

Step 3: Connect SCT013 AC Current Clamp Sensor to ESP

To connect the SCT013 to ESP32 or NodeMCU, you can buy this module on eBay to interface or connect the SCT013 sensor with D1 Mini, NodeMCU, or ESP32. You may also build one, like I did, by following this circuit diagram.

You may buy a 3.5MM female audio jack to connect the SCT013 AC current clam sensor with ESP or strip the 3.5mm SCT013 jack wire and then connect them to the circuit.

Once done, turn on NodeMCU by connecting it to a micro USB power supply. Any smartphone charger with 5V output will work.

Step 4: Calibrate the SCT013 Sensor Values

To measure the current and calibrate the sensor, you need to clamp it on the phase wire (usually red color) coming from the electricity meter to your house distribution box.

Go to ESPHome Dashboard and click Logs under smart-power-meter.

The logs will display the Wi-Fi strength and connection status.

Note down the ‘Measured Current’: Sending state x.xxxx A with value.

It should be similar with minute fluctuation if you have no new load ON in your home. Collect at least 10 values and then take out the average.

Then add the following code in the smart-power-meter.yaml file under Sensor:

Here 0.00807 is the average value and 1.2228 is the actual current drawn into our house. You can get this real value from your electricity meter.

If your electricity meter doesn’t display a current value, or you don’t have access to the meter, follow the next method to calibrate the sensor values. Alternate Way to Calibrate Sensor Values You may strip off the outer covering from an extension board cable and expose the internal wires.

Then clamp the SCT013 sensor on the exposed phase wire (red wire) and then run a load, such as a microwave or a fan. Be careful while stripping off the extension board cable. Do not cut the cable or pierce through the internal wires.

Check the logs and then replace the values. Save it and then click Install.

Since smart-power-meter is connected and online, you can upload the code Wirelessly.

The new firmware will be compiled and uploaded wirelessly. Once done, you can see the actual current values.

For more accurate values, we recommend you use a multimeter to measure the current drawn by an appliance and reported by the SCT013 sensor. Then replace those in the filters values as described above.

Step 5: Configure the Energy Dashboard in Home Assistant

To configure the energy dashboard in Home Assistant, you need to add the sensor to Home Assistant. The steps are as follows.

Go to Configuration> Devices and Services > Add Integration.

Search and click ESPHome.

Enter the IP address of the sensor (you can find this in the logs) and click Submit.

Choose the area and click Finish.

Click smart-power-meter and then click 1 device.

Click Add to lovelace.

Select a Room (select the default one if you haven’t created any rooms yet) and click Next.

This will add the entities.

You may further customize the cards in your room to add a gauge showing current demand.

You may also add beautiful graphs, using mini-graph card integration.

Step 6: Track Daily/Monthly/Yearly Energy Usage with Home Assistant

Energy dashboard was introduced in Home Assistant with the release of HA 2021.8, which makes it easy to get insightful information on your daily, monthly, or yearly energy usage. You can quickly access the dashboard from the sidebar and check how much energy is being used today. You can also break down usage in hours.

To learn more, refer to the energy management section of Home Assistant documentation.

Be Smart, Save Energy

Besides monitoring the power usage by the entire house, you can build multiple smart energy monitoring sensors using SCT013 or PZEM-004T sensor to actively and accurately track power usage by the individual or specific home appliances, such as HVAC, electric heaters, motors, geysers, etc. This also lets you know the appliance activity status, i.e. if it’s ON or OFF.

You can then use this information as events in the Home Assistant to create automation, such as sending you notifications on your smartphone or via Alexa or Google Assistant.