Page 9 of 20
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Monday 30 October 2017 14:23
by philchillbill
Instead of toying with zeners and resistors, has anybody used a proper level-shifter for this project? For example, this one from Adafruit (model 757) can be bought for about EUR 4 and actually has 4 level shifters implemented with MOSFETs. You can use up to 10V on the high-side (to supply the inductive-sensor) and down to 1.8V on the low-side for the pi. In other words, anything from 5-10V on the high side ('HV') is automatically taken care of and will always result in 3v3 logic levels for the pi - no need to worry about calculating anything (just connect the 3v3 from the pi board to the 'LV' pin on this thing). Sure you could solder up a pull-up and a BSS138 yourself for less money but for EUR 4 this is a rather neat solution.

Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Monday 30 October 2017 15:03
by pvangorp
I used a zener because I had one. I mentioned a logic level converter. They are even cheaper
https://www.tinytronics.nl/shop/nl/span ... arch=Level
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Monday 30 October 2017 16:56
by LouiS22
pvangorp wrote: ↑Monday 30 October 2017 4:32
I created a test environment for your situation.
As you can see in your dump something goes wrong!!!
Code: Select all
2017-10-13 21:29:06.049 LUA: Water usage is still 173.005m3
2017-10-13 21:29:06.050 LUA: wget http://192.168.1.94:8080/json.htm?type=command¶m=udevice&idx=157&svalue=173005 -O /dev/null
2017-10-13 21:29:06.067 EventSystem: Script event triggered: /home/pi/domoticz/scripts/lua/script_device_Watermeter.lua
I looked into it and ¶m is translated wrong by Domoticz.
(type=command¶m=udevice)
Change the order of the url parameters and use:
Code: Select all
json.htm?param=udevice&type=command&idx=......
and it will work.
And that's it, really!
Update: not, it's still not the right one: it's just doubled the actual value (142 is the acutal, but it's 284 at the Master PI).
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Monday 30 October 2017 18:05
by pvangorp
I created your situation and tested it today. Mine is working fine. Please validate your code again. It will work if your code is correct! Do you use the correct IP’s!
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Monday 30 October 2017 22:57
by philchillbill
Sure, that one will work fine if using 5V as the HV level but not sure if it's spec'd for up to 10V like the Adafruit one is in case anybody is using a higher voltage for the sensor (it is after all spec'd for 6V+ operation). Either way, I'd much rather be doing level conversion with a FET.
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 10 November 2017 15:32
by djreesing
I've got my setup working with pvangorp's lua script. However my watermeter device shows the wrong number, it's off by one decimal. With every liter the actual watermeter changes, the virtual one changes by 10 liters.
Any idea what I'm doing wrong here? The output from the lua script in the logfile shows the correct amount.

- Schermafbeelding 2017-11-10 om 15.27.08.png (32.18 KiB) Viewed 3387 times
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 10 November 2017 16:06
by pvangorp
Go to settings, meters and set the RFXMeter for water to 1000. Thats all
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 10 November 2017 16:41
by djreesing
Thanks, problem solved!
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Tuesday 14 November 2017 18:41
by LouiS22
Guys, I still haven't solved my inital issue, namely sending data from Slave PI to my Master PI. Please help me, it drives me crazy.
Here's the code from the slave:
Code: Select all
commandArray = {}
-- 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['Watermeter GPIO'])
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['Watermeter GPIO'] == 'Off')
then
sWaterUsageTot = (sWaterUsage + 1)
print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
print('wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue='..sWaterUsageTot..' -O /dev/null')
commandArray['UpdateDevice'] = '6|0|'..sWaterUsageTot..''
else
-- Keep a live device
if (timedifference(otherdevices_lastupdate["Watermeter"]) > 300)
then
print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ");
commandArray['UpdateDevice'] = '6|0|'..sWaterUsage..''
print('wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue='..sWaterUsage..' -O /dev/null')
end
end
return commandArray
it is set up as Lua, Device within Events. The supposed sending command is now set as print, and here's the log:
Code: Select all
2017-11-14 18:21:39.345 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71219 -O /dev/null
2017-11-14 18:21:39.351 EventSystem: Script event triggered: Watermeter
2017-11-14 18:21:45.026 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:21:45.037 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:21:49.635 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:21:49.646 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:21:49.651 LUA: Water usage is set to 71.22m3
2017-11-14 18:21:49.651 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71220 -O /dev/null
2017-11-14 18:21:49.658 EventSystem: Script event triggered: Watermeter
2017-11-14 18:21:55.375 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:21:55.388 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:21:59.931 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:21:59.944 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:21:59.948 LUA: Water usage is set to 71.221m3
2017-11-14 18:21:59.948 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71221 -O /dev/null
2017-11-14 18:21:59.955 EventSystem: Script event triggered: Watermeter
2017-11-14 18:22:05.678 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:22:05.689 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:10.240 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:22:10.251 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:10.256 LUA: Water usage is set to 71.222m3
2017-11-14 18:22:10.256 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71222 -O /dev/null
2017-11-14 18:22:10.262 EventSystem: Script event triggered: Watermeter
2017-11-14 18:22:16.011 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:22:16.027 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:20.862 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:22:20.873 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:20.878 LUA: Water usage is set to 71.223m3
2017-11-14 18:22:20.879 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71223 -O /dev/null
2017-11-14 18:22:20.885 EventSystem: Script event triggered: Watermeter
2017-11-14 18:22:27.166 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:22:27.182 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:32.232 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:22:32.243 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:32.248 LUA: Water usage is set to 71.224m3
2017-11-14 18:22:32.248 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71224 -O /dev/null
2017-11-14 18:22:32.256 EventSystem: Script event triggered: Watermeter
2017-11-14 18:22:38.662 Sysfs GPIO: gpio21 new state = on
2017-11-14 18:22:38.674 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:43.704 Sysfs GPIO: gpio21 new state = off
2017-11-14 18:22:43.722 (Watermeter GPIO) Lighting 2 (Watermeter GPIO)
2017-11-14 18:22:43.728 LUA: Water usage is set to 71.225m3
2017-11-14 18:22:43.728 LUA: wget http://192.168.0.19:8080/json.htm?param=udevice&type=command&idx=3709&svalue=71225 -O /dev/null
2017-11-14 18:22:43.736 EventSystem: Script event triggered: Watermeter
2017-11-14 18:22:50.086 Sysfs GPIO: gpio21 new state = on
AS you can see from the above log, the svalue is changing, so it should be ok, but when I remove the print command and replace it to os.execute, the value won't be seen at master PI (however firing the the whole URL from browser works and Master PI's virtual counter gets updated).
Where's the bug? Any ideas?
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Wednesday 15 November 2017 5:35
by pvangorp
Use os.execute('wget http://...... instead of print. Print was for debugging!
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Wednesday 15 November 2017 7:18
by LouiS22
pvangorp wrote: ↑Wednesday 15 November 2017 5:35
Use os.execute('wget http://...... instead of print. Print was for debugging!
I mentioned before that print is now for testing purpose to see values are arriving. After that I specified that it's not working with os.execute, values aren't arriving to master pi

Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Wednesday 15 November 2017 7:36
by pvangorp
They will or the entered ip is wrong!
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Wednesday 15 November 2017 8:19
by LouiS22
pvangorp wrote: ↑Wednesday 15 November 2017 7:36
They will or the entered ip is wrong!
IP is correct as also mentioned: copypasting the very same IP with value triggers Master PI and counter gets updated there
No other idea where it goes south.
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Thursday 16 November 2017 8:52
by Benneton
Hi,
Last week the sensor arrived, yesterday I had some time to fiddle with it, Installation went smooth, add of 'watermeter' in Domoticz, loading script, Cron bit and the diverder to 1000. Then I rebooted and found it to work, great for one thing, having the sensor connected interfered with my RFXCOM on the USB port. I can use only one, the water meter or the RFXCOM.
My guess is that both use to much power.
This post helped me in finding out.
My question is can I power the sensor with an external power supply not using the 5v from the PI and just connect the black to GPOI21 (pin40) to receive the pulses from the sensor?
Any other solution is welcomed to! Thanks for the support.
Bernard
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Thursday 16 November 2017 10:04
by pvangorp
Bernard, I use several devices on USB and GPIO watermeter and relais without any power issues, but I use the original Pi3 adapter with 2.5A. You can use a separate power supply, but than I would use a Level Converter (as discussed before in this topic).
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Thursday 16 November 2017 21:58
by Benneton
Hi PvanGorp
Thanks for this hint! I have currently a 2.1A power supply, will swap it with an original PI power supply I have. Hopeful this will solve the power issue.
Otherwise it also could be cable length, approx 5meter.
Update 29/11/2017:
Got it figured out, cable was faulty, connected up new cable and now all is working fine for 3 days. Will check in a week or so how accurate the measurement will be.
Thanks to al who made this possible!
Bernard
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 17 November 2017 12:49
by Draakje
pvangorp wrote: ↑Friday 25 August 2017 10:45
Instead you can connect a 3.3v zener diode on the black wire and your GPIO's are safe. They are verry cheap and perfect for low power.
https://www.kiwi-electronics.nl/zenerdiode-3v3-500ma.
For accurate measurement use a 9 or 12 volt adapter instead of 5v from the PI.
Could you elaborate the ZenerDiode connection?
Do you mean putting the zener between black wire and GPIO pin ? And in what direction ? Kathode on ..... / anode on ....
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 17 November 2017 15:36
by pvangorp
Between black wire and GPIO. For direction I used a volt meter. If correct connected it give 3.3v instead of 5v. When wrong connected it gives 5v
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Friday 17 November 2017 16:11
by Draakje
pvangorp wrote: ↑Friday 17 November 2017 15:36
Between black wire and GPIO. For direction I used a volt meter. If correct connected it give 3.3v instead of 5v. When wrong connected it gives 5v
Thanks!
Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Saturday 18 November 2017 14:07
by Draakje
pvangorp wrote: ↑Friday 17 November 2017 15:36
Between black wire and GPIO. For direction I used a volt meter. If correct connected it give 3.3v instead of 5v. When wrong connected it gives 5v
Ok,
So When I measure the voltage I have like 5,1V without the Zener and 1,7 With the zener.. (Are these similar to what you have?)
The meter does work in Domoticz but it is way off.. Just Flushing the toilet will increase the meter with 10 liters...... (No I do not have a very large toilet

)
I have set the meter setting to 1000.
Where should I check things over ?