Re: Watermeter lezen met raspberry en Inductieve NPN sensor
Posted: Saturday 18 November 2017 15:38
My diode gives 3,3v
1,7v might be to low. Did you get the correct diode?

Open source Home Automation System
https://forum.domoticz.com/
Well I checked the number on the diode (1n746a) and according to the specs this should be a 3,3v zener..
Go to settings, meters and set the RFXMeter for water to 1000. Thats all
Ok Now I see what I am doing wrong..philchillbill wrote: ↑Monday 20 November 2017 15:20 Your meter produces 1 pulse per liter so measuring 0,134 liters is impossible. The average water consumption per day in the Netherlands is 119 liters per person so 134 sounds dead right to me !
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¶m=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¶m=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"
Code: Select all
/json.htm?type=command¶m=udevice&idx=258&svalue=16.00
Code: Select all
/json.htm?type=devices&rid=258
{
"ActTime" : 1512119268,
"ServerTime" : "2017-12-01 10:07:48",
"Sunrise" : "08:26",
"Sunset" : "16:24",
"result" : [
{
"AddjMulti" : 1.0,
"AddjMulti2" : 1.0,
"AddjValue" : 939827.0,
"AddjValue2" : 0.0,
"BatteryLevel" : 255,
"Counter" : "590.002 m3",
"CounterToday" : "282.293 m3",
"CustomImage" : 0,
"Data" : "590.002 m3",
"Description" : "",
"Favorite" : 1,
"HardwareID" : 5,
"HardwareName" : "Dummy",
"HardwareType" : "Dummy (Does nothing, use for virtual switches only)",
"HardwareTypeVal" : 15,
"HaveTimeout" : false,
"ID" : "82258",
"LastUpdate" : "2017-12-01 10:06:48",
"Name" : "Water Meter",
"Notifications" : "false",
"PlanID" : "0",
"PlanIDs" : [ 0 ],
"Protected" : false,
"ShowNotifications" : true,
"SignalLevel" : "-",
"SubType" : "Counter Incremental",
"SwitchTypeVal" : 2,
"Timers" : "false",
"Type" : "General",
"TypeImg" : "counter",
"Unit" : 1,
"Used" : 1,
"ValueQuantity" : "",
"ValueUnits" : "",
"XOffset" : "0",
"YOffset" : "0",
"idx" : "258"
}
],
"status" : "OK",
"title" : "Devices"
}
Micha, after failing with the Python script, I got the LUA script working and it works great!Micha123 wrote: ↑Wednesday 06 September 2017 0:13 Im set LUA to DEVICE
Im checking the names again and again. I became that error message.
Maybe i test it with an other browser to start the lua script but i dont think what the problem is....
tested again, script startet, readed the Value from virtual Counter, so i restart the pi and after a simply restart i got the error again.
Louis22, the correct command is:LouiS22 wrote: ↑Monday 23 October 2017 10:19Have you found the bug yet?Trigun wrote: ↑Friday 13 October 2017 21:33something happend.but unfortunately nothing happens on the other device.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 just found out that I never see the following print:is this correct or should it only set once, in the beginning?Code: Select all
print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
Code: Select all
os.execute('curl "http://192.168.1.190:8084/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsageTot..'"')
Code: Select all
os.execute('curl "http://192.168.1.190:8084/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsageTot..' " ')
Mate, THANK YOU! Indeed that was my problem, now it's okay and I'm happysammyke007 wrote: ↑Friday 01 December 2017 17:37Louis22, the correct command is:LouiS22 wrote: ↑Monday 23 October 2017 10:19Have you found the bug yet?Trigun wrote: ↑Friday 13 October 2017 21:33
something happend.but unfortunately nothing happens on the other device.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 just found out that I never see the following print:is this correct or should it only set once, in the beginning?Code: Select all
print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
the HTTP link needs to be in between " " so when I seperate it for readability:Code: Select all
os.execute('curl "http://192.168.1.190:8084/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsageTot..'"')
Code: Select all
os.execute('curl "http://192.168.1.190:8084/json.htm?param=udevice&type=command&idx=91&svalue='..sWaterUsageTot..' " ')
Go to Setup -> Settings -> Other -> Sensor Timeout and set a value that's long enough for you. I have 4320 which is 72 hours = 3 days.
Thanks!philchillbill wrote: ↑Tuesday 05 December 2017 9:32
Go to Setup -> Settings -> Other -> Sensor Timeout and set a value that's long enough for you. I have 4320 which is 72 hours = 3 days.
Hi Sammyke007,sammyke007 wrote:Just create it with the JSON command from the first page of this post. Don't forget to change the IP!
I'll write a full guide tomorrow if OK for the authors because everything is spread now...