I’ve got an ESP32 running the pulse width sensor on a light detector module attached to the blinking light on my electricity meter. I’m using it to detect the time between pulses so I can accurately calculate my power consumption.
However when the pulse become very spaced out (low power consumption), the ESP reports a width of zero. I’m assuming it does this because it reaches its maximum value and resets before a new pulse is detected. So my question is: what’s the maximum value it can report? And can I increase it some way, by say by changing the resolution from microseconds to milliseconds etc?
Hi Dave,
Mind sharing details on the sensor you use and how you set it up? I hadn’t thought of it, but its a great idea that I might want to explore myself.
Thanks!
The Pulse Width reports the time in seconds, and my meter flashes 1000 times per kWh (once per watt hour). There are 3600 seconds in one hour. So if you take 3600 and then divide it by the number of seconds, it tells you the average amount of watts that were flowing through the meter between those two pulses.
However, until I find out how to increase the maximum value of pulse width, when consumption drops below a certain amount, the sensor reads zero…and 3600 / 0 = infinite…so my Home Assistant dashboard is currently displaying a consumption of 470 megawatts…
That will eliminate the crazy readings, but I was actually after a solution to count the longer gaps between pulse widths, and this measure power consumption when very low.
I’m not understanding the issue. If you have 0 pulses over your interval, usage is 0 and should be reported as 0. The lower the interval, the more detailed a graph you can make for when you do have a lot of usage being reported.
I monitor pulses from my power meter in the same manner (optical sensor over emitter on meter) but I use a Raspberry Pi and a python script I created. I measure pulses over 10 seconds, convert to watts (watts = curr_pulsecount * 360) then send the value to my mqtt broker. I then have an mqtt sensor in home assistant that gets updated with this value.
If I have 0 pulses over 10 seconds, total watts used is 0 and 0 gets reported to the mqtt broker. it’s entirely possible that watts could get reported as 0 over several intervals and that’s perfectly valid.
Why not use the pulse_counter sensor instead? I’m doing the same as you, with the sensor magnetically attached to the meter watching the LED which flashes once for every Wh consumed.
That gives me two sensors in HA, which I show like this:
(ignore yesterday’s low reading: I had the device apart to add a temperature sensor)
The power reading has a resolution of 60W, which is one pulse per minute. Long-term average is “perfect” down to zero power as it counts every flash from the meter, but if you’re only drawing 6W (one flash every ten minutes) it’ll return 0W for nine of the minutes and 60W for the minute that the flash happened in. You can see the 60W resolution as the “steps” in the low-power areas, but that resolution is fine for me.