Monitor Belgian watermeter and gasmeter with Pi GPIO

Moderator: leecollings

sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Hi everyone

Tnx to this forum, I succeeded in integrating my Belgian water and gasmeter into Domoticz.
The watermeter is a V100 (Kent / Elster) and the gasmeter is an Elster BK-G6M. Both send out pulses while running.
The V100 watermeter sends out 1 pulse per 0.5 liter
The Elster BK-G6M send out 1 pulse per 0,01m³ (10 liter) (edit the script for this).
These pulses can be detected by a REED sensor/contact.
Al of the information was spread thru different forums and different topics, so I decided to write a little how to...
Special tnx to pvangorp and markiemark

What do you need?
- Raspberry Pi running Domoticz (my Pi is only running as a "slave" Domoticz. My Synology NAS runs the master Domoticz.
- a KY 025 module (0,5 euro on Aliexpress, ...)
- soldering equipment
- 3x dupont cables female-female
- piece of UTP cable (not stranded) to put between the KY 025 and the desoldered REED contact so you can put the reedcontact in ront of the GAS meter or inside the hole of the watermeter.

This is a quick sketch of what the hardware looks like:
Image

Guide!

I'm assuming your Pi is installed with Raspbian and "apt-get update" and "apt-get upgrade" have recently been run. Domoticz is also already installed on the Pi.
  • Create a utility sensor on your Domoticz by executing in your browser:

    Code: Select all

    http://YOUR_PI_IP_ADRESS:YOUR_DOMOTICZ_PORT/json.htm?type=createvirtualsensor&idx=29&sensorname=Watermeter&sensortype=113
    
  • In Domoticz, SETUP > DEVICES and look for the IDX of your newly created sensor
  • Execute in browser (edit IP, PORT and IDX from previous step!)

    Code: Select all

    http://YOUR_PI_IP_ADRESS:YOUR_DOMOTICZ_PORT/json.htm?type=setused&idx=IDX_HERE&name=RFXMeter&switchtype=2&used=true
  • In Domoticz SETUP > MORE > USER VARIABLES create a User Variable "WaterMeter" (Case sensitive!) as type integer and with value 0
  • SSH to your Pi using Putty, terminal, ... (Google if you need help howto) and execute the following commands one by one. I've used GPIO pin 21 (board 40) as pulse input:

    Code: Select all

    sudo -i
    echo 21 > /sys/class/gpio/export
    echo in > /sys/class/gpio/gpio21/direction
    echo 0 > /sys/class/gpio/gpio21/active_low
    echo both > /sys/class/gpio/gpio21/edge
    raspi-gpio set 21 pd
    Important: These commands get reset with a Pi reboot. We will add this code to the domoticz.sh file in /etc/init.d later!
  • Test GPIO pulse with the command

    Code: Select all

    sudo raspi-gpio get 21
    Level=0 when no contact, Level=1 when contact. You can use a magnetic screwdriver to test the reedcontact/sensor (do this!!!).
  • In Domoticz add the hardware "Generic sysfs GPIO" in SETUP > HARDWARE with the name GPIO. Your log should say: Sysfs GPIO: Startup - polling:no interrupts:yes debounce:50msec inputs:1 outputs:0. Otherwise, check your connections or restart
  • Trigger your sensor a couple of times so it should popup under SETUP > DEVICES
  • Add this new device by clicking the green arrow at the right side. Name it GPIO Watermeter
  • In Domoticz, open the SWITCHES tab and edit the GPIO Watermeter. Edit the switchtype to On/Off and change the icon to Water.
  • Go to SETUP > MORE> EVENTS and create a new LUA script, triggered by DEVICE.
  • Clear the code and insert (tnx to pvangorp!)

    Code: Select all

    commandArray = {}
    
    -- Set IDX of Watermeter
    iIDX = 1
    
    -- Set Watermeter based on user variable "WaterMeter"
    if ( uservariables["WaterMeter"] > 0 ) then
        print("Water usage is set to " .. uservariables["WaterMeter"] / 1000 .. "m3 by user")
        commandArray['UpdateDevice'] = ''..iIDX..'|0|'..uservariables["WaterMeter"]..''
        -- os.execute('curl "http://192.168.1.XXX:8080/json.htm?param=udevice&type=command&idx=91&svalue='.. uservariables["WaterMeter"] / 1000 ..'"')
        commandArray['Variable:WaterMeter'] = tostring(0)
    end
    
    -- Water usage
    -- Retrieve value from water meter device:
    sWaterUsage = otherdevices_svalues['Watermeter']
    
    -- To have a better readable format, divide number by 1000:
    sWaterUsagePrint = (tonumber(sWaterUsage) / 1000);
    
    -- calculation is done with the unmodified water value
    sWaterUsage = tonumber(sWaterUsage);
    
    -- For Debuging
    -- print("Water usage until now is " .. sWaterUsagePrint .. "m3 ")
    -- print('GPIO Watermeter = '..otherdevices['GPIO Watermeter'])
    
    function timedifference(s)
       year = string.sub(s, 1, 4)
       month = string.sub(s, 6, 7)
       day = string.sub(s, 9, 10)
       hour = string.sub(s, 12, 13)
       minutes = string.sub(s, 15, 16)
       seconds = string.sub(s, 18, 19)
       t1 = os.time()
       t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
       difference = os.difftime (t1, t2)
       return difference
    end
    
    if (devicechanged['GPIO Watermeter'] == 'Off')
    then
    	sWaterUsageTot = (sWaterUsage + 0.5)
    	
    	print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ")
    	commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsageTot..''
    	-- os.execute('curl "http://192.168.1.190:8084/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsageTot..'"')
    else
        -- Keep alive device
        if (timedifference(otherdevices_lastupdate["Watermeter"]) > 3600)
        then
          print("Keep alive - Water usage is still " .. sWaterUsage / 1000 .. "m3 ")
          commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsage..''   
          -- os.execute('curl "http://192.168.1.XXX:8080/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsage..'"')
        end
    end
    
    return commandArray
  • Change "iIDX = X" where X is the IDX from step 2.
  • If you have Domoticz running on another machine like me, you can use the os.execute commands in the script to also send the values to your master Domoticz. Don't forget to create a virtual sensor on that Domoticz, look up the IDX and change the IDX and IP+PORT in the os.execute commands!
  • Enable the script and save it
  • SETUP > SETTINGS > OTHER - set RFXMeter/Counter Dividers: Water to 1000
  • SETUP > SETTINGS > OTHER - set Sensor Timeout: to 10000 (important!). Otherwise, when you're on a holiday and no water is used for a day, the "Watermeter" will turn red (inactive) and you will receive log errors!
  • Edit the file domoticz.sh on your Pi in /etc/init.d/ (using Putty+nano command or use WinSCP, ...) and add the following lines after the last line saying ":"

    Code: Select all

    sudo sh -c 'echo 21 > /sys/class/gpio/export'
    sudo sh -c 'echo in > /sys/class/gpio/gpio21/direction'
    sudo sh -c 'echo 0 > /sys/class/gpio/gpio21/active_low'
    sudo sh -c 'echo both > /sys/class/gpio/gpio21/edge'
    sudo sh -c 'raspi-gpio set 21 pd'
    Now the GPIO is always set correctly on Pi's reboot!
  • Profit (but probably, start debugging :D :D :D )!
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Can you add pictures how you installed this on the meters?
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Image
You can put it in a small hole next to the counter. Sometimes you have to remove a black cap.
Image
I soldered it like this to get it in the small hole of the watermeter. Be careful when bending a reed contact! The glass breaks very easy!
Image
The gasmeter I attached the reed contact like this. This works better than putting it in the premade hole in the bottom.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Crap, I have other meters.
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Egregius wrote: Thursday 07 December 2017 22:34 Crap, I have other meters.
What types?
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

I've got these, the watermeter just got replaced some weeks ago:

Image
Image
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Egregius wrote:I've got these, the watermeter just got replaced some weeks ago:

Image
Image
No problem at all! For your watermeter, use an inductive sensor. Check https://www.domoticz.com/forum/viewtop ... 28&t=17123. For your gasmeter, use a TCRT5000 sensor. One of the numbers should be reflective?


Verzonden vanaf mijn iPhone met Tapatalk
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Thank you :)

I ordered a inductive sensor.
About the TCRT5000: can that be connected directly to GPIO or do I need something else?
And why not use a TCRT5000 also for the water meter? It's also reflective, the weel that turns around.
https://www.benl.ebay.be/sch/i.html?_fr ... 0&_sacat=0
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Egregius wrote:Thank you :)

I ordered a inductive sensor.
About the TCRT5000: can that be connected directly to GPIO or do I need something else?
And why not use a TCRT5000 also for the water meter? It's also reflective, the weel that turns around.
https://www.benl.ebay.be/sch/i.html?_fr ... 0&_sacat=0
Some use it for the watermeter too indeed. Try as you like. Most Dutch watermeters are like yours so check the forum. I believe in Nederland it's called an Elster watermeter.


Verzonden vanaf mijn iPhone met Tapatalk
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Thanks for the info.
Could you just tell me how to connect the TCRT5000?
And maybe choose one from the link in my previous post?
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Egregius wrote: Friday 08 December 2017 16:38 Thanks for the info.
Could you just tell me how to connect the TCRT5000?
And maybe choose one from the link in my previous post?
Just order one from eg. Aliexpress, eBay, ...
It should look like this:
Image

Connect VCC to +3.3V, GND to GROUND and DO (digital output) to a GPIO pin of your choice.
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Thanks 8-)
Items ordered, busy now trying to get controlpi up and running do set up the scripts before the items arrive :)
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Benneton »

Hi

I have ths working for my Gas Meter, problem I have accuracy it misses lots of liters of gas.
Tried to set sensitivity with POT meter, but eiter indicator light is always on (2 green light) or every so often second light on, that is what is required to count. Unfortunately it does not count it all :(

Any one an idea.

By the way for the watermeter I use the proximity meter, works super :) 2 liters off in 7 weeks.

Regards,
Bernard
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Benneton wrote: Wednesday 20 December 2017 13:27 Hi

I have ths working for my Gas Meter, problem I have accuracy it misses lots of liters of gas.
Tried to set sensitivity with POT meter, but eiter indicator light is always on (2 green light) or every so often second light on, that is what is required to count. Unfortunately it does not count it all :(

Any one an idea.

By the way for the watermeter I use the proximity meter, works super :) 2 liters off in 7 weeks.

Regards,
Bernard
Are you using a reed contact or an IR type sensor (TCR5000)?
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Benneton »

Hi,

I use the TRC5000. not sure the gas meter has capabilityt to be checked with reed contact.
Gas meter is Itron G4 RF1

Bernard
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Can you post a picture? Normaly you can try with a reed contact on the digits or above them in the gap.
The TCR5000 needs to be covered enough so it doesn't get affected by surrounding light...
User avatar
Egregius
Posts: 2589
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: v2024.7
Location: Beitem, BE
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by Egregius »

Guess I ordered the wrong sensors, they're always on :?
Image

Now ordered these:
Image
freak53
Posts: 1
Joined: Wednesday 14 March 2018 13:15
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by freak53 »

Sammeke007

ik ben met net hetzelfde bezig als u, mijn vraag is hoe krijg ik nu een deftige grafiek in domoticz?
ik wil mijn KY-025 aansluiten op GPIO .
Welk hardware system moet ik dan gebruiken?
sammyke007
Posts: 204
Joined: Monday 08 May 2017 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.1
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by sammyke007 »

Ik heb deze aangesloten op de GPIO pinnen van een RPI 3
User avatar
capman
Posts: 153
Joined: Friday 12 July 2013 20:48
Target OS: Raspberry Pi / ODroid
Domoticz version: Beta
Location: Belgium
Contact:

Re: Monitor Belgian watermeter and gasmeter with Pi GPIO

Post by capman »

@sammyke007
I have the same water and gasmeter. But what I asking myself is , how do you use 2 reed switches ?
Do I have 2 KY 025 modules and attach them to the pi like on your drawing ? Or do I need other gpio pins
for the second module ? Can you explain how you did this ?
Thanks.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests