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:

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:
Important: These commands get reset with a Pi reboot. We will add this code to the domoticz.sh file in /etc/init.d later!
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
- Test GPIO pulse with the command Level=0 when no contact, Level=1 when contact. You can use a magnetic screwdriver to test the reedcontact/sensor (do this!!!).
Code: Select all
sudo raspi-gpio get 21
- 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 ":"
Now the GPIO is always set correctly on Pi's reboot!
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'
- Profit (but probably, start debugging
)!