GPIO meter pulse counting with instant power calculation
Moderator: leecollings
-
- Posts: 112
- Joined: Monday 26 June 2017 21:16
- Target OS: Raspberry Pi / ODroid
- Domoticz version: beta
- Location: Spain
- Contact:
Re: GPIO meter pulse counting with instant power calculation
I'm totaly zero to scripts, so sorry if I say anithing stupid.
As my pi is far from the counter, I would like to use a wemos d1 and send data via mqtt, is it possible to use this script to calculate instant power this way?
Thanks in advance
As my pi is far from the counter, I would like to use a wemos d1 and send data via mqtt, is it possible to use this script to calculate instant power this way?
Thanks in advance
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
I have been using this script successfully for electricity only. I am using the photosensor as described in the OP, together with a dedicated RPi Zero W, sending readings via WiFi to Domoticz. Here's how it looks in my meter cupboard:

I've also amended the script, to show the meter reading, which - over the last 48 hours - has been spot on with the actual meter (never missed a pulse)!

I am very pleased with this script - thank you!



I've also amended the script, to show the meter reading, which - over the last 48 hours - has been spot on with the actual meter (never missed a pulse)!

I am very pleased with this script - thank you!



-
- Posts: 72
- Joined: Friday 11 March 2016 18:23
- Target OS: Raspberry Pi / ODroid
- Domoticz version:
- Location: Essex, UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
You can count pulses on wemos and periodically send number of pulses via mqtt (resetting wemos counter to zero).salvacalatayud wrote: ↑Friday 01 February 2019 12:31 As my pi is far from the counter, I would like to use a wemos d1 and send data via mqtt, is it possible to use this script to calculate instant power this way?
And you will need to change script not to count pulses directly, but rather get them from mqtt message.
Great setup @MikeF, glad its been of help!
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
I've now added a gas counter, using a reed switch version of the optical sensor mentioned in the original post: https://www.ebay.co.uk/itm/Reed-Sensor- ... Sw6CJbEYRS
I've also created a 'smart meter' dashboard, using ImperiHome (via MyDomoAtHome) on an Android tablet:

I've also created a 'smart meter' dashboard, using ImperiHome (via MyDomoAtHome) on an Android tablet:

-
- Posts: 89
- Joined: Friday 15 September 2017 18:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10076
- Location: Germany
- Contact:
Re: GPIO meter pulse counting with instant power calculation
Is there a manual how to use this?
RPi4 Shelly1 Shelly2.5 ESPEasy Tuya Domoticz Beta Dashticz 3.6
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
None, I'm afraid - but there's some very useful information in the original post (OP) on this thread.
Implementation depends entirely on what meters you have - I have a digital electricity meter, with an LED which blinks once per Wh; I use the optical sensor as shown in the original post. My gas meter is a mechanical one, with a magnet in place of the zero digit on the last reel, which rotates once per 1/100 m3; I've used a reed switch sensor as shown in my previous post. Both sensors are connected to the GND, 3.3V (not 5V) and GPIO pins on the RPi (24 for electricity sensor, 17 for gas sensor).
I use a modified version of RidingTheFlow's python script:
- Spoiler: show
I've extended this further, with a dzVents script to display energy and costs, using custom Domoticz sensors:
- Spoiler: show
This gives me the following in my Utilities tab in Domoticz:

Finally, the 'smart meter' display in my previous post was created in ImperiHome on an Android tablet - you'll need MyDomoAtHome for this (see the Domoticz wiki for this).
-
- Posts: 89
- Joined: Friday 15 September 2017 18:54
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 4.10076
- Location: Germany
- Contact:
Re: GPIO meter pulse counting with instant power calculation
Thank you.
My questions is where to put the script and how to autostart it.
I put the script in home directory and ecexuted it, but I get no Data in Domoticz. IDX is right.
But first of all it must start himself.
My questions is where to put the script and how to autostart it.
I put the script in home directory and ecexuted it, but I get no Data in Domoticz. IDX is right.
But first of all it must start himself.
RPi4 Shelly1 Shelly2.5 ESPEasy Tuya Domoticz Beta Dashticz 3.6
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
You can add a line to /etc/rc.local like this:
Code: Select all
python /home/pi/devices/elec_gas_meter.py &
- or you can run it from cron, like this:
Code: Select all
@reboot python /home/pi/elec_gas_meter.py > /dev/null 2>&1 &
- and the domoticz url and GPIO pin numbers are correct?I put the script in home directory and ecexuted it, but I get no Data in Domoticz. IDX is right.
-
- Posts: 157
- Joined: Wednesday 02 October 2019 7:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands
- Contact:
Re: GPIO meter pulse counting with instant power calculation
I am also looking for a solution to read my gasmeter.RidingTheFlow wrote: ↑Tuesday 29 March 2016 14:34 For gas meter I detected a magnet which was located *after* the last digit disk.
Could you post a picture of you gasmeter, so I could determine if my gasmeter also has this magnet?
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
-
- Posts: 350
- Joined: Sunday 19 April 2015 0:36
- Target OS: Raspberry Pi / ODroid
- Domoticz version: V2022.2
- Location: UK
- Contact:
Re: GPIO meter pulse counting with instant power calculation
azonneveld wrote: ↑Thursday 14 May 2020 12:17I am also looking for a solution to read my gasmeter.RidingTheFlow wrote: ↑Tuesday 29 March 2016 14:34 For gas meter I detected a magnet which was located *after* the last digit disk.
Could you post a picture of you gasmeter, so I could determine if my gasmeter also has this magnet?

This is an Actaris G4 meter - as you can see, there is a small silver magnet in place of the 0 digit in the last reel.
I've placed a reed switch in a plastic case underneath (there is a cutout), which is activated as the magnet passes over it. 1 revolution = 1/100 m3.
-
- Posts: 157
- Joined: Wednesday 02 October 2019 7:37
- Target OS: Raspberry Pi / ODroid
- Domoticz version: 2024.4
- Location: Netherlands
- Contact:
Re: GPIO meter pulse counting with instant power calculation
Thnx for the quick reply! Unfortunately my meter is a lot older... I guess my meter doesnt have a magnet...
I have considered installing a Cognex, but the budget is not sufficient

rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
Who is online
Users browsing this forum: No registered users and 0 guests