OpenEnergyMonitor Community

ESP32 and Optical Pulse Counter

Hi there,

Out of curiosity, is it possible to interface the Optical Pulse Counter with an ESP32 or ESP8266 using the likes of esphome, espurna or another binary?

Many thanks.

The output is what it says, a pulse. You will need software inside whatever is receiving the pulses on a digital input pin to count the pulses and convert them to a number - either an accumulated count (if it’s the pulse output from an energy meter, that count will represent the total energy) or a rate, which in that case would indicate power.

Hi Robert,

Thanks for the response, reason I ask is that I have a LIDR attached to an ESP32 with an appropriate pullup resistor and esphome counting pulses, converting to watts & kwh and sending I guess via MQTT to Home Assistant. I’ve a couple of the OPC’s and they are more robust than my homebrew.

Regards, Michael

One thing to be aware of with our optical pulse detector is, the green LED on the back doesn’t always tell the truth. There’s a thread about it: First try with EmonPi - Pulsecount stuck at 1 - #16 by Robert.Wall

Hi Michael,

I am thinking of running something similar, did you try the pulse counter ? I have read that reading the pulse will not give an instant reading like the clamp sensor would ?

I run an esp/Arduino code and blynk to show pool temperature and the sensor battery voltage.

What I want to do now with another esp is grab the solar panel KW value and when high enough and stable, switch on my pool heat pump for a time or until the KW value drops past a threshold and stays in a low stable state.

The heat pump is connected to a smart life plug via a relay and can also be controlled via ifttt. At the moment I manually switch it by looking at the solar edge monitor app reading and smart life !

Do you share your pulse code to home assistant as a starter ? Maybe we can work with it ?

Welcome, @merc07 to OEM.

That indeed is correct. Your meter only emits a pulse when a quantum of energy has passed - normally but not necessarily, that’s about 1 Wh. And that makes it very difficult to know the power especially when the usage is low, because it’s zero (as far as you can tell) between pulses. At best, you can know that you used (or generated) one unit of energy between the last pulse and the present one that’s just been detected.

A current transformer will give a continuous measure of current.

I’d caution the use of an ESP to actually measure current and voltage - the ADC is not the best and won’t give you accurate values. If you’re only interested in the value being above or below a threshold, then it might suffice.

Thanks !

So if it pulses once for each 1wh of power passed, what would the pulse rate be ?
I would need to know when the power is above say 2kw free.
I have a generation meter in one building with the led and essentially the same meter for my standard usage in the main house.
Do they both work the same way?
If I am using less power than my solar is generating, the light on the main meter is always on to the eye ?
Are we talking pulses per second.

My other esp works very well for temperature and battery voltage, it is very accurate…
What else would you recommend ?

Just had a look at my generation meter, roughly 7 secs for 520 watts, 4.5 secs for 810watts.

So 3600/secs = watts as other information shows.

I think this should work perfectly well with algorithms used to make sure its stable sun and not just a spike…

Hi Merc07,

I did try the OPC on an ESP32 , unfortunately it didn’t work, I guess the internal electronics are better suited to a RPI GPIO rather than hooking up to an ESP32.

As I said on my second post, I have homebrew OPC’s which work very well counting the pulses on my supply meter, but it is a homebrew effort and is kind of held together with shrink wrap and bluetak!

RE Pulses, 1 pulse represents 60w (on a 1000 pulse KW meter) and as Robert rightly mentions it is not a good measure of actual generation or usage. The reason behind my request was so I could accurately see the consumption/generation per day/week/month rather than looking at the current generation which was available using the CT Clamps.

I managed to use Node Red in conjunction with EmonCMS and Grafana and found that the CT Clamp is exceptionally accurate, possible due to the fact that the sample rate is every 5 seconds where the likes of an OWL Meter would update every 60 seconds produce varying results.


The OWL doesn’t sample the mains voltage, but rather assumes a fixed voltage value. That yields
an approximation of apparent power, (measured in Volt-Amps) the value of which will always be greater than real power (measured in Watts) which is what you get billed for. The only instance where an apparent power measurement will be equal to a real power measurement is when the load is 100% resistive. e.g. an electric kettle or heater that has no fan motor. The typical household contains a “mix” of resistive and reactive loads. It’s the reactive loads that cause the OWL to yield a measurment that doesn’t reflect the true energy consumption of the load.

I have mega 2560 around somewhere, I’ll use that to start with to see if I can get an accurate enough reading using the optical sensor when I get hold of one.
I really only need an average of the previous 20 mins and latest generated power to know power is stable and to switch on an appliance.
I am surprised there is nothing out there that can do this already ?
Everything tells you the available solar power but then you have to switch things on/off manually ?
Or am I missing something ?

I think you might be. Look at ‘Learn’ and “PV Diversion”. There are two designs there, but they’re both intended for water heating and to accurately balance the consumption against generation so that there’s no nett power flow to or from the supply (while it’s possible to achieve a balance). You could very easily adapt either design to switch one or more loads in a priority sequence according to the amount of surplus available.

Or you could use an emonPi in conjunction with the Wi-Fi MQTT Relay I believe - but I’m not an expert in that area.

But I don’t know of a commercial unit that might do what you require.

They will do - but the pulse rate might well be different. The rate is usually printed on the front of the meter.

Yes, that is the way it works. And of course it means that the pulses are useless on the Grid meter when energy is being exported. The meter pulses will only record imported energy.

1 Like

Yes I have seen the PV diversion systems but they would not be compatible with anything other than immersion heater elements.
The relay looks good but expensive and over complicated with the rest of the setup.

I’ll have to look a little more into the emonPi but it seems to be just a monitoring system which I already have with the solaredge app…

In that case I will just use the generation meter, I’ll build a simple datalogger and test system and go from there.

My heater is already connected via a £5 smart plug, ifttt, Google assistant etc, just need an automated way to turn it on when power is available so I don’t have to keep looking at the app every 5 mins…

What does everyone else do, do they keep having to get out their chair to turn things on ?

No, they use an emonPi to send a command to the relay. I’m quite sure that there are many users here who have a much more complicated system than you envisage, but I’m not an expert in that field so I can’t advise you in detail. You’ve already rejected my suggestion that you could adapt either design to suit your needs, so I can’t really help you any further.

Not rejected yet, I just don’t understand what emonPi is apart from a monitoring system ?

It hosts (in my almost non-existent understanding of Nodered and MQTT) the decision-making process and can also send the commands via Wi-Fi to the relay. At the risk of repeating myself, this is an area where I have no expertise.