Super Simple DIY House Electricity Meter

This project will not include any advanced stuff, but instead it aims to provide a simple description for how to make a simple DIY project — from start to finish. Maybe the first DIY project!? How to become a “maker”. :slight_smile:

Background
A large portion of all energy meters display consumption by blinking (like 1,000 blinks every kWh).

There are many projects out there showing how to make an energy meter reading these blinks. But I thought I would share mine because every other instruction I found were a little bit too complicated for my liking, many involved Arduoni that I am not familiar with and so forth. And none described using the really easy ESPhome add on in Home Assistant and a ESP32 board.

If you have Home Assistant set up, this project shouldn’t take more than an hour to set up — max. And the result is pretty great, you will get an instant accurate electricity meter in your phone which will allow you to monitor your consumption.

Gear:
Any ESP32 development board
A micro USB to USB-a cable that can carry data communication (many are just for charging)
Dollatek Photoresistor (https://www.amazon.co.uk/DollaTek-Digital-Intensity-Resistor-Photoresistor/dp/B07DJ4C2SN)
Small breadbord
Cables
One hinge of any type
A piece of wood
A saw
(From one hinge… to here can be replaced with ducktape)

(A) ESPhome settings etc

  1. Install ESPhome.

  2. Connect the ESP32 to the RPI with the cable

  3. Add a board, chose board type, and make the easiest possible upload with your WiFi details. After this is done you can uploaded over the air (OTA).

Warning: Press the boot button on the ESP32 when uploading, hold it, press and release EN and then let go of boot after the upload to the board have started (after compiling etc is done). This can be a little tricky at first, but after a while you get a hang of it, it is easy.

Create and upload the following settings:


esphome:
  name: bleel
  platform: ESP32
  board: esp32dev

wifi:
  ssid: "passwordis1234”
  password: "1234"

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Blebrygga Fallback Hotspot"
    password: "ea0QLTX9C8bV"

captive_portal:

# Enable logging
logger:

api:

ota:

sensor:
  - platform: pulse_counter
    pin: GPIO14
    unit_of_measurement: 'kW'
    name: 'Power Meter'
    filters:
      - multiply: 0.06
    
    total:
      unit_of_measurement: 'kWh'
      name: 'Energy Meter House'
      filters:
        - multiply: 0.001

(B) Wire the ESP32

  1. Draw a cable from ground (gnd) pin on the ESP32 board to ground on the Photoresistor (Google the symbol).
  2. Draw a cable from the 3v pin to vcc pin on the Photoresistor.
  3. Draw a cable from a suitable GIPO pin on your ESP32 to the data pin on the Photoresistor (the one left). Find which pin that is suitable by googling pinout for your ESP32 brand and model. In short — if a GIPO has no specific function it should do the trick. Some are needed for rebooting etc and then it will create problems/conflicts if that pin is chosen. State the GIPO/PIN number chosen by you in the setting (where I have pin: GPIO14).

(c )Mounting

  1. I used a hinge and a piece of wood to get the Photoresistor mounted immediately against the blinking light.
  2. I.e. just attach the hinge with screws next to the electricity meter (be careful with this if there could be cables behind the wall, glue can be used instead). Attach the piece of wood to the hinge. Then carefully apply the small breadboard (they usually have double mounted tape at the bottom) so that the head of the Photoresistor goes against the blinking light.
  3. Provide the ESP32 with power over a USB cable.

For me it looks like this:

When the meter blinks, so does the Photoresistor so that you can see that it works:

It’s of course possible to not use a breadboard and tape everything into place.

(D) Daily consumption meter

Add this to your configuration.yaml to get a second “sensor” measuring your daily consumption:

utility_meter:
  energy:
    source: sensor.power_meter
    cycle: daily

(E) Install InfluxDB, IDE and Grafana in 15 minutes
Follow these instructions:

(F) Create a Lovelace card

  1. First create a new dashboard in Grafana.
  2. Chose measurement as Kw:
  3. FROM shall be identityid = power_meter
    1-3b. Do the same for the energy meter created by editing configuration.yaml
  4. For now, just select Vizulation and Timeline
  5. Select Share for the dashboard by hitting the four boxes below and do NOT select Use current timeframe:
  6. Create a Lovelace card using the Website alternative.

Paste the copied link from Grafana to the website. Add “&kiosk&fullscreen” to the url!
7. Now we have two editable electricity meters in a Lovelace card.

They are of course not pretty, but making improvements to the layout in Grafana is for another topic and easy for everyone to play around with.

It’s also possible to improve the energy metering to remove the spikes. I will revert to this in replies in this thread later.

Hope this helps!

And please — any tips, tricks or suggestions for improvements are greatly appreciated!!!

10 Likes

Great write up!

I really suggest you to add the support for total pulses as well: https://esphome.io/components/sensor/pulse_counter.html?highlight=pulse#counting-total-pulses

1 Like

Many thanks!

I have added it above.

Do you also have a pulse counter?

1 Like

Yes, I have an old pr on how the calculations are made and an example on how to hook up directly to the S0 port of the meter too.

1 Like

That is awsome, I am going to look at getting some read on my district heating (Swe. fjärrvärme) soon. Just need to figure out the whole optical reader first. I am sure it’s like everything else, it’s easy once you understand what you are doing or at least get your bearings of what is up and what is down… :wink:

It’s maybe for another topic, but I’ve seen some discussions if precision could be improved. But as I understand, ESPhome’s pulse counters are as precise as they get — right? Sure every update per minute will not be exact since there is a set interval, but it’s just a fraction of a pulse, which of course always get compensated the following pulse. If you have 20-30 pulses per minute it’s very marginal. Roughly 1.5% +/- accuracy on a minute to minute basis and 100% over time.

Do you have an optical sensor and does your meter report energy with pulses? [quote=“Messier1994, post:7, topic:291197”]
I understand, ESPhome’s pulse counters are as precise as they get — right? Sure every update per minute will not be exact since there is a set interval, but it’s just a fraction of a pulse, which of course always get compensated the following pulse. If you have 20-30 pulses per minute it’s very marginal. Roughly 1.5% +/- accuracy on a minute to minute basis and 100% over time.
[/quote]

Well, it counts the pulses. If you use the total_pulses you will not only get derived power (Watt) but also the elapsed energy (kWh). Whee the latter is exact.

P.s. Electrokit in Sweden have pretty decent prices if you need an phototransistor.

1 Like

I think I will need something like these:

image

It basically has a port with what looks to be two lamps. As I’ve understood, one is a IR light and one is kind of an IR receiver. They are in any event clearly designed for non-invasive communication with the meter. I don’t know if they send out IR regularly, or in pulses, or if you like have to wake it up with a signal and ask it to deliver info from the meter that is otherwise displayed on the display. I’ve seen some discussions at different places were people have been able to dump info from them that looks great.

But it seems like a bit of a high risk project. Ie the hardware is a little bit more costly and since I can’t see the signals, it’s hard to know what it takes to get them or when they are made and what it takes to read them.

One guy that done it:
https://elektronikforumet.com/forum/viewtopic.php?f=2&t=79853

1 Like

I’m going to be attempting to do this in the next few days. a few months on for you, have you changed the way you are doing anything?
Is the light sensor you have linked to any good or are there better ones?

Also do you ‘have’ to install all of the other stuff ( InfluxDB, IDE and Grafana) or can it be done with HA and a MQTT server? (i don’t have HA supervised so i can’t do the addon stuff… although i can do docker stuff separately, its just a bit of a faff)

2 Likes

Good luck! Let me know if you need any help with anything.

Everything has worked better than I expected even. I could however improve my display of it. It became summer here in Sweden and I’ve redone the entire garden so haven’t spent much time indoors. I don’t have any good like last 7 days, 12 months and so forth.

The light sensor has been perfect too. I expected interference if I put on the lamp and opened the door but it haven’t had any issue like that.

I have not used that particular optical reading head, but you might have a look at my post here as I just did a similar project using a ESP32 / Lora Dev Board to interact with the meter: [Energy] Read IEC-62056 based electricity meter and send data using Lorawan, WebHook and Template Sensors

Pavax did you try it? Let me know if there is any part you want to discuss!

Hi! Did anyone manage to read the data from the optical port using a diy probe and esphome?

1 Like

I did. I got the esp and a small photoresistor board from aliexpress. The only problem was that the included indicator led was misleading. When I adjusted the resistor so that the led blinked correctly, I got readings like 1500kW. I managed to tune it correctly watching the raw pulses in the esphome log output.

1 Like

Seems that will be my first DIY project :grinning:

Looking at these photoresistors, could the XH-M131 5V (Xh-m131 Dc 5v 12v 24v 10a Light Control Switch Photoresistor Relay Module Detection Sensor Brightness Automatic Control Module - Integrated Circuits - AliExpress) be used with an esp32 ?

If so :

  • ground (gnd) pin on the ESP32 board to ground on the Photoresistor (3 wires seen 3 Photoresistors)

  • the 5v pin on the ESP32 board to vcc pin on the Photoresistor (3 wires seen 3 Photoresistors)

  • suitable GIPO pin on the ESP32 board to the data pin on the Photoresistor…where is that ?

1 Like