Watermeter lezen met raspberry en Inductieve NPN sensor Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.
clubeddie
Posts: 79
Joined: Saturday 19 March 2016 22:12
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by clubeddie » Wednesday 14 February 2018 21:04

philchillbill wrote:
Wednesday 14 February 2018 20:59
See Hobbybob's post earlier in this thread - that schematic should do it for you - it was already drawn in the early days of this thread. There are also posts that show using zener diodes to make sure the pi GPIOs never see more than 3v3 despite a 5v or 12v supply to the inductive sensor. Just search earlier topics in this thread.
Will do, thanks.

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Wednesday 14 February 2018 21:14

If I see the number of people asking about master/slave Domoticz installs when they connect the water meter reader to a secondary pi, it's clear a lot of people are just blindly copying stuff without understanding a thing of what they are actually doing. The script in the VERY FIRST post of this entire thread will update *any* Domoticz instance on your network and the pi it runs on DOES NOT need to run Domoticz. If your water meter is remote then just connect it to a cheap local pi-0-W that runs nothing other than the original python script as a daemon and you're done. Really !
Last edited by philchillbill on Friday 16 February 2018 12:06, edited 1 time in total.
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Thursday 15 February 2018 18:43

For anybody looking for the most elegant way from an electronic engineering perspective to interface the sensor to the pi, see the schematic below. The N-channel FET shown is a BS170 which can handle 500mA and 60V but you could use just about any general purpose equivalent and it will work (e.g. 2N7000). However, make sure it's a FET and not a bipolar transistor. 1=Gate, 2=Drain, 3=Source. Here's how it works:

The 10K resistor at the input (i.e. the output of the inductive sensor - black wire) pulls it down to make sure the FET is off when nothing is connected or if the inductive sensor is open-circuit. In this state the FET has effectively infinite resistance from Drain to Source and the 10K pullup to 3v3 gives us a HIGH on the GPIO pin. When a voltage is applied to the gate of the FET it switches on and has practically zero resistance from Drain to Source so pulls the output down to zero volts, giving us a logic LOW at the GPIO. So yes, it INVERTS the input signal but that doesn't matter to us because we count pulses in this application.

This circuit will allow you to power the inductive sensor (brown wire) with anything from 5V to its max spec of 36V and the pi will still just 'get' 0 to 3v3. It works great at 9V and at 12V - anything higher really isn't necessary. It may work at 5V if you're lucky but it is formally spec'd at 6V minimum. By using a FET instead of the simple 1k/2K voltage divider or the zener mentioned in earlier posts, you're guaranteed not to overload the pi no matter what happens because the pullup on the pi input is connected to the 3V3 supply line on the pi itself.

The resistor values of 10K are not critical and you can use anything you like that's ~10K or greater. See below for the pinout for the BS170 (note that the 2N7000 has a mirrored pinout):
Attachments
bs170.png
bs170.png (19.77 KiB) Viewed 2264 times
tCad1.png
tCad1.png (3.69 KiB) Viewed 2267 times
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

Benneton
Posts: 31
Joined: Thursday 08 December 2016 10:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Benneton » Sunday 18 February 2018 12:05

Hi,

Since 13/02/2018 my watermeter is not seen anymore in domoticz.
I looked at the NPN Sensor and it seems to work, red light puls when detects.

I checked the log (sudo nano /var/log/cronlog.log):

Traceback (most recent call last):
File "/home/pi/domoticz/scripts/watermeter.py", line 23, in <module>
a,b,c = inhoud.split()
ValueError: need more than 1 value to unpack


Above error is shown as my programming skills are poor I have no clue how to resolve.
Checked the meterstand.txt file, is present and value is also present.

This was yesterday when I started to investigate.


I now have solved the issue by:
Stopping service watermeter.py
deleting the file meterstand.txt
starting service watermeter.py in from cmd line leaving window open to check for errors.
Checked the meterstand.txt and saw that value was 0, updated value and saved file.
Refresh of browser and it was fine again.

I noticed one thing when I started this project the meterstand.txt only had a value in it.
When the file was created by the script it now states:
"meterstand = 571411"
Could this be related to the version Domoticz? I run Beta, V3.8922

Bernard

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Monday 19 February 2018 11:06

@Bernard, This script talks to Domoticz 'one-way' via json and the version of Domoticz is irrelevant to what the script itself does. If there's a bug in the latest beta then the meter-value might display incorrectly in Domoticz, but Domoticz can't mess this script up, unless a beta messed up your python install somehow (unlikely).

The python code 'a,b,c = inhoud.split()' simply takes the 3 fields 'meterstand = 571411' and assigns meterstand/=/571411 to the variables a/b/c and then c is further used as the value reading while a and b are unused. If python complains about this split operation, it means that there was nothing or insufficient data to split, meaning the file meterstand.txt was likely unreadable for some reason for this script (or that it didn't contain 3 parameters). What were the permissions on that file and who owned it (command: ls -al)? Was the cronjob run as root or the pi user? Is the file complete?
Last edited by philchillbill on Wednesday 28 February 2018 12:31, edited 1 time in total.
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

roelv
Posts: 2
Joined: Tuesday 27 February 2018 23:17
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Heerhugowaard, NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by roelv » Tuesday 27 February 2018 23:35

There is an easy way of reading sensor measurements into a Raspberry Pi, using Domoticz, without having to program at all. That is: using 1-wire sensors. They are recognized immediately by Domoticz and the counting and graphing is done automatically. The only problem is that I did not yet find a 1-wire inductive or optic sensor for the watermeter. Possible solution: use the inductive type you described earlier and convert its signal (is it analog or digital?) to a 1-wire signal. Could this component be of any help? https://datasheets.maximintegrated.com/en/ds/DS2450.pdf

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Wednesday 28 February 2018 11:16

roelv wrote:
Tuesday 27 February 2018 23:35
There is an easy way of reading sensor measurements into a Raspberry Pi, using Domoticz, without having to program at all. That is: using 1-wire sensors. They are recognized immediately by Domoticz and the counting and graphing is done automatically. The only problem is that I did not yet find a 1-wire inductive or optic sensor for the watermeter. Possible solution: use the inductive type you described earlier and convert its signal (is it analog or digital?) to a 1-wire signal. Could this component be of any help? https://datasheets.maximintegrated.com/en/ds/DS2450.pdf
So, instead of following a very simple and fully-explained tutorial that dozens of people have built already (and can therefore help out), you'd rather point to a data-sheet for a chip that people will now have to figure out for themselves how to use because there's no tutorial? I sincerely doubt that will be easier :?
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

Benneton
Posts: 31
Joined: Thursday 08 December 2016 10:46
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Benneton » Wednesday 28 February 2018 12:03

Philchillbil,

Thanks for the explenation.
I now understand why I did get an error with just a number in the file.

I believe the reason all was messed up became to an error in the logfiles and cleaning of the files.
I had no space left on the SD card to write, I found old open logfiles in multiple instances.
After removal, all worked, except the 2 counters, Gas and Water.
Files must have come corrupt some where in the process.

Bernard

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Wednesday 28 February 2018 12:29

Benneton wrote:
Wednesday 28 February 2018 12:03
I now understand why I did get an error with just a number in the file.
That explains it indeed - if 'split' expects 3 parameters to split then it will complain if there's only one. Glad you sorted it out.
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

roelv
Posts: 2
Joined: Tuesday 27 February 2018 23:17
Target OS: Raspberry Pi
Domoticz version: 3.8153
Location: Heerhugowaard, NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by roelv » Wednesday 28 February 2018 13:09

philchillbill wrote:
Wednesday 28 February 2018 11:16
roelv wrote:
Tuesday 27 February 2018 23:35
There is an easy way of reading sensor measurements into a Raspberry Pi, using Domoticz, without having to program at all. That is: using 1-wire sensors. They are recognized immediately by Domoticz and the counting and graphing is done automatically. The only problem is that I did not yet find a 1-wire inductive or optic sensor for the watermeter. Possible solution: use the inductive type you described earlier and convert its signal (is it analog or digital?) to a 1-wire signal. Could this component be of any help? https://datasheets.maximintegrated.com/en/ds/DS2450.pdf
So, instead of following a very simple and fully-explained tutorial that dozens of people have built already (and can therefore help out), you'd rather point to a data-sheet for a chip that people will now have to figure out for themselves how to use because there's no tutorial? I sincerely doubt that will be easier :?
Philchillbill,
I saw your schematic which seems a great solution if you are able to program your device and count the pulses. However, I also noticed that dozens of people in this and other fora are busy for months trying to program their devices in a way that accurate measurements will be registered. Reflecting to myself, that is too complex. I think one of the purposes of Domoticz is that it is readily built en distributed as an image for people who just want to use it 'as is', and buy modules like RFXcom en KlikAan KlikUit receivers, weathersensors, temp/humiditysensors and even connect to (weather)sensors remotely via internet etc. In my surroundings very few friends, colleguas, neighbours or relatives use Domoticz or a Pi, let alone have knowledge of hard- and software, so making things easier would be a nice goal.
Connecting via a 1-wire solution seems to me avoiding the hassle of programming and making connections via simple wiring quite easy. But indeed, you're right doubting that just pointing to the datasheet is helpful. I hope this inspires someone to come to a non-coding solution. :idea:

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Wednesday 28 February 2018 17:12

Roelv,
The initial tutorial written by @markiemark is fantastic and should be doable even by copy/pasters due to his completeness and attention to detail. Your idea of a simple interface to Domoticz definitely has merit, but then we'd need a full schematic and costing for the copy/pasters. Given that this project just counts pulses, it should be possible to connect it to the external sensor-contact on e.g. a FIbaro Z-Wave door/window sensor. If somebody is prepared to solder, you can use a (cheaper) Neo Coolcam one by desoldering the reed detector and soldering on the inductive sensor instead. This would then 'look' to Domoticz as if a door was opening/closing on every pulse of the water meter. It's trivial to use a Lua script to update a counter for such pulses:

commandArray = {}
local function updatenum(dev, value1)
local cmd = string.format("%d|0|%d", otherdevices_idx[dev], value1)
table.insert (commandArray, { ['UpdateDevice'] = cmd } )
end
if (devicechanged['WaterPulseCounter'] == 'On') then
updatenum('Water', tonumber(otherdevices['Water']) + 1)
return commandArray

This would, of course, be a more expensive solution than even a dedicated Pi-zero-W. And you'd need to be already using Z-Wave. But it would prove there are more roads that lead to Rome...
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

jnmulder
Posts: 4
Joined: Thursday 15 March 2018 22:34
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by jnmulder » Thursday 15 March 2018 22:40

Hoi,

Is er iemand die onderstaand probleem (kraan uit, sensor blijft aan, counter blijft tellen) heeft gefixed?


Alvast bedankt,

Jan

sammyke007 wrote:
Thursday 30 November 2017 15:16
Hallo allemaal

Ik ben volop bezig mijn watermeter (België) uit te lezen.
Het betreft dit type meter:
Image. Je kan deze uitlezen met een hallsensor gezien er een uitsparing is, waarin deze past (links op de foto, zwart plastic kapje verwijderen en de op kabel gesoldeerde hall sensor inschuiven).
Ik gebruik een RPI 3. Op GPIO 21 (pin 40) steekt een KY024 (met hall sensor) dewelke een puls geeft elke keer als het meest rechtse getal (nr 2 op de foto, deciliter dus als ik het juist voor heb) 1x volledig rond gaat. Dus per liter krijg ik een puls door op mijn hall sensor. Dat werkt ook momenteel.

Ik gebruik een licht gewijzigd script;

Code: Select all

import RPi.GPIO as GPIO
import time
import urllib
import os


idx = 90
#Reset TimerKeepAlive
TimerKeepAlive = 0

#Board is pin nr, BMC is GPIO nr
#Read output from water meter op pin 40
GPIO.setmode(GPIO.BOARD)
# Set GPIO 21 (Pin 40) als Input aditional as Pullup activated
GPIO.setup(40, GPIO.IN, pull_up_down = GPIO.PUD_UP)

#Functie  callback
#Funtion used by interruptcall
def Interrupt(channel):
  
  #Send counter to domoticz JSON
  global Counter
  Counter = 1
  httpresponse = urllib.urlopen("http://192.168.1.190:8084/json.htm?type=command&param=udevice&idx="+str(idx)+"&svalue="+str(Counter))
  #For debug => print example of JSON-call
  #print "JSON call = "+ str(url1)
  print "Watermeter Counter = " + str(Counter)

#Interrupt-Event, NPN off a sensor is 1 and detection is 0
#Detection is 0,falling interupt
GPIO.add_event_detect(40, GPIO.FALLING, callback = Interrupt, bouncetime = 350)

try:
  while True:

        #Send every 50 minutes [300sec] an update to keep sensor alive in Domoticz
        TimerKeepAlive = TimerKeepAlive + 1
        print "Counting time " + str(TimerKeepAlive)
        if TimerKeepAlive > 1800:

                httpresponse = urllib.urlopen("http://192.168.1.190:8084/json.htm?type=command&param=udevice&idx=90&svalue=0")
                #For debug => print JSON-call
                #print "JSON call = "+ str(url1)

                TimerKeepAlive = 0
        else:
                time.sleep(1)
except KeyboardInterrupt:
  GPIO.cleanup()
  print "\nBye"
Dit lijkt vrij goed te werken. Alleen als ik mijn kraan dichtdraai op het moment dat de magneet bij de hall sensor staat (en het ledje dus oplicht op de KY024), dan blijft de counter optellen.

Iemand enig idee aub?
Alvast bedankt!

clubeddie
Posts: 79
Joined: Saturday 19 March 2016 22:12
Target OS: NAS (Synology & others)
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by clubeddie » Thursday 15 March 2018 22:45

Maybe if you try to ask in english you can get an answer

jnmulder
Posts: 4
Joined: Thursday 15 March 2018 22:34
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by jnmulder » Thursday 15 March 2018 23:24

Thanx I'll try in english.

I've got the script (on page one of this discussion) to work. However when the watermeter stops running (finished using water) and the led stays on, my counter (the seperate file) keeps adding up

Does anybody know how to fix this?


Thx,

Jan

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Monday 19 March 2018 19:07

Looks like you have noise/interference on the signal from the meter. If the half-moon disc that rotates under the inductive sensor just happens to stop at the threshold-point for the sensor then you may get chattering on the signal. How long is your cable and hoe well shielded is it? Any sources of electrical noise nearby?
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

jnmulder
Posts: 4
Joined: Thursday 15 March 2018 22:34
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by jnmulder » Tuesday 20 March 2018 21:23

Thanx for youre response.

The cable is about 1, m long and not shielded.
There are some electrical devices nearby so youre suggestion could be right. What is the best way to shield the cable? Shield the complete kabel from sensor until Rpi?

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Wednesday 21 March 2018 9:23

jnmulder wrote:Thanx for youre response.

The cable is about 1, m long and not shielded.
There are some electrical devices nearby so youre suggestion could be right. What is the best way to shield the cable? Shield the complete kabel from sensor until Rpi?

Yep, and make sure the shield is grounded. You basically want something like a coax cable where an earthed shield surrounds the core. For a 1m length, just wrapping some tin foil like used for baking might do the trick and be quick to try.


Sent from my iPhone using Tapatalk
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

mastersnarf
Posts: 2
Joined: Thursday 22 March 2018 17:17
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Oudenbosch
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by mastersnarf » Saturday 24 March 2018 2:07

Hoi allemaal
Ik ben bezig met het uitlezen van mijn watermeter.
Hiervoor heb ik het scribt watermeter.py wat aangepast.
Nu wil ik de tijden van laag hoog en hoog laag van elkaar aftrekken zodat ik te zien krijg hoelang de puls laag en de puls hoog is.

Callback function called!
Wachten op positive puls van water meter sensor
GPIO input = 0 op 2018-03-24 00:41:33.892119
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:36.862196
Watermeter Counter = 474330
Callback function called!
Wachten op positive puls van water meter sensor
GPIO input = 0 op 2018-03-24 00:41:40.398372
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:43.334820
Watermeter Counter = 474331
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:44.718261
Watermeter Counter = 474332
Callback function called!

dit is mijn watermeter.py
#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import datetime
import urllib2
import os
from datetime import datetime
i = datetime.now()
print str(i)
#Watermeter stand (wordt alleen initeel gebruikt als er geen bestand meterstand_water.txt is)
global Counter
Counter = 27273

#Domoticz URL
domoticz_url = "http://192.168.0.187:8080"
#Domoticz IDX van de water sensor (RFXMeter)
idx = 1

#Open meterstand.txt file en lees meterstand
#Als meterstand.txt niet aanwezig is maakt script bestand aan en vult de meterstand
fn = "/home/pi/domoticz/scripts/meterstand_water.txt"
if os.path.exists(fn):
f = file(fn, "r+")
f = open(fn)
inhoud = f.readline()
a,b,c = inhoud.split()
Counter = int(c)
else:
f = open(fn, "w")
f.write( 'meterstand = ' + repr(Counter))
f.close()

#Board is pin nr, BMC is GPIO nr
#Read output from water meter op pin 19
GPIO.setmode(GPIO.BOARD)
# Set GPIO 10 (Pin 19) als Input aditioneel als Pullup-Weerstand aktiveren
GPIO.setup(19, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

#Functie callback
#Dit is de functie die aangeroepen wordt in de interrupt
def Interrupt(channel):
print('Callback function called!')
time.sleep(0.03) # need to filter out the false positive of some power fluctuation
if GPIO.input(19) == 0:
print('Wachten op positive puls van water meter sensor')
laag = datetime.now()
print 'GPIO input =',GPIO.input(19),'op',str(laag) # Voor debug kijk naar waarde van de gpio poort
return
# Voor debug kijk naar waarde van de gpio poort
hoog = datetime.now()
print 'GPIO input =',GPIO.input(19),'op',str(hoog)

#Teller elke interrupt uitlezen en met 1 liter verhogen (deler watermeter op 1000 zetten)
file(fn, "r+")
f = open(fn)
inhoud = f.readline()
a,b,c = inhoud.split()
Counter = int(c)
Counter = Counter + 1
f.close()
#Schrijf meterstand naar bestand
f = open( fn, 'w')
f.write( 'meterstand = ' + repr(Counter))
f.close()
#Send counter to domoticz JSON
url1 = domoticz_url+'/json.htm?type=command&param=udevice&idx='+str(idx)+'&svalue='+str(Counter)
req1 = urllib2.Request(url1)
response1 = urllib2.urlopen(req1)
#Voor debug => print voorbeeld van de JSON aanroep en/of de counter
# print "JSON call = "+ str(url1)
print "Watermeter Counter = " + str(Counter)
#Interrupt-Event toevoegen, sensor geeft een 0 en en bij detectie een 1
#Bij detectie een 1 daarom check stijgende interrupt.
#bouncetime=negeer detectie in miliseconde.
GPIO.add_event_detect(19, GPIO.RISING, callback = Interrupt, bouncetime = 200)


try:
while True:
time.sleep(0.2)
except KeyboardInterrupt:
GPIO.cleanup()
print "\nBye"

Sorry voor de verkeerde schrijfwijze van mijn uitleg.
Ben vandaag pas begonnen met forum.

mvg Frans

User avatar
philchillbill
Posts: 228
Joined: Monday 12 September 2016 13:47
Target OS: Linux
Domoticz version: beta
Location: Eindhoven. NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by philchillbill » Sunday 25 March 2018 0:07

Frans, volgens mij heb je noch een vraag, noch een opmerking gemaakt in het bovenstaande. Waarmee moeten we je helpen?
NUC/Ubuntu, Evohome Heating + HGI80, Evohome Security, 4x HikVision IP cams, Aeotec, Neo & Fibaro Z-Wave, Logitech Media Server (on Synology DS916+), 10x SqueezeBox, Kodi, Harmony Hub, 5x Amazon Echo, HA-Bridge, Hue.

mastersnarf
Posts: 2
Joined: Thursday 22 March 2018 17:17
Target OS: Raspberry Pi
Domoticz version: V3.8153
Location: Oudenbosch
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by mastersnarf » Sunday 25 March 2018 1:45

Hoi allemaal
Mijn vraag was om de tijden van laag naar hoog van elkaar af te trekken en ook van hoog naar laag.
In mijn voorbeeld zou dit dan zijn.

van GPIO input = 1 op 2018-03-24 00:41:36.862196 - GPIO input = 0 op 2018-03-24 00:41:33.892119
2018-03-24 00:41:36.862196 - 2018-03-24 00:41:33.892119 = 2.970077 (de gpio poort is bijna 3 seconde laag)

van GPIO input = 0 op 2018-03-24 00:41:40.398372 - GPIO input = 1 op 2018-03-24 00:41:36.862196
2018-03-24 00:41:40.398372 - 2018-03-24 00:41:36.862196 = 3.536176 (de gpio poort iets meer dan 3.5 seconden hoog)

de tijd van laag komt van
laag = datetime.now()
en van hoog
hoog = datetime.now()

Callback function called!
Wachten op positive puls van water meter sensor
GPIO input = 0 op 2018-03-24 00:41:33.892119
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:36.862196
Watermeter Counter = 474330
Callback function called!
Wachten op positive puls van water meter sensor
GPIO input = 0 op 2018-03-24 00:41:40.398372
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:43.334820
Watermeter Counter = 474331
Callback function called!
GPIO input = 1 op 2018-03-24 00:41:44.718261
Watermeter Counter = 474332
Callback function called!

Ik hoop dat ik het een beetje goed heb uitgelegd.

mvg Frans

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests