How to Build a DIY Household Energy Monitor Using ESP8266

2022-04-02 09:39:07 By : Ms. Jenny Lu

Learn how to build a smart IoT-based energy monitoring device to see real-time energy usage right on your smartphone.

An IoT (Internet of Things) based smart energy monitoring system allows you to track energy usage at your home or office in real-time. The system collects the data in logs and displays it in a meaningful manner that you can further use to perform actions, such as sound an alert or send notifications on your smartphone or Alexa/Google Assistant for high power usage or when energy usage reaches a certain threshold. Besides, it also helps you conserve power and prevent wastage.

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.

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

This DIY project involves AC voltage/current, which is lethal. If you are not experienced, stop right here or continue at your own risk.

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

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.

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.

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

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.

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,

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.

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.

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.

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.

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.

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.

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.

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.

Ravi is an expert tech explainer, an IoT enthusiast and Linux lover with a background in big data and app development. He spends most of his weekends working with IoT devices and playing games on the Xbox. He is also a solo traveler who loves hiking and exploring new trails.

Join our newsletter for tech tips, reviews, free ebooks, and exclusive deals!