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.
Melissen
Posts: 47
Joined: Wednesday 16 November 2016 10:39
Target OS: -
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Melissen » Sunday 26 August 2018 12:01

Also made a script for a waterflowmeter !!!

You first need to make-activate 2 uservariables.
-begin INTEGER value=0
-begintijd INTEGER value=0
Then you need to make a virtual device Waterflow
- go to HARDWARE and make another virtualsensor "Waterflow" at Watermeter and use this as 'waterflow'


After this, you can use this script
jIDX is number of Waterflow device.

BE CAREFUL... AFTER 5 minutes of inactive watermeter, the flow resets to zero. When you use water again and the switch (on the watermeter) is almost directly ON, you can read a high flow-result, after the second liter the reading will be correct. When you turn off the water the flow will give the last value, but resets after 5 minutes. Will you turn on the water after about 4 minutes, you will get a low flow-value, because you only used that liter in the last 4 minutes. So the flow is 0,25liter/min ( 1 liter in 4 minutes)
Hope you will understand the start and end values of the flowmeter. When you use water for a longer time, the readings will be spot on.

EDITED 26-8 18:42
Edited line56 (putted - 300 in it), so the flowvalue isn't very high when you turn on water and metal plate is right in front of sensor. So no high values like 120liters/min anymore

Code: Select all

commandArray = {}

-- IDX Waterflow
jIDX = 404

-- Begintijd in uservariables zetten
if  (uservariables['begin'] == 0)
    then
        -- print ("begin instellen")
        commandArray['Variable:begin'] = tostring(1)
        commandArray['Variable:begintijd']= tostring(os.time())
end        

-- Decimalen
function round(num, numDecimalPlaces)
   local mult = 10^(numDecimalPlaces or 0)
   return math.floor(num * mult + 0.5) / mult
end

-- timedifference
functiontimedifference(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


-- Script
if (devicechanged['GPIO Watermeter'] == 'Off')
   then 
       -- print ("Watermeter gaat naar Off")
       btijd = uservariables['begintijd']
       duur = os.time() - btijd
       lpm = 60 /duur
       -- print (lpm)
       lpm = round(lpm, 2)
       -- print (btijd)
       -- print (os.time() - btijd)
       -- print (os.time())
       -- print (duur)
       -- print (lpm)
       commandArray['Variable:begintijd']= tostring(os.time())
       commandArray['UpdateDevice'] = ''..jIDX..'|0|'..lpm..''
   else
        -- Keep a live device and set flow to zero
        if (timedifference(otherdevices_lastupdate["GPIO Watermeter"]) > 300)
           then
               -- print("tijd langer dan 300")
               flow = 0
               -- commandArray['Variable:begintijd']= tostring(os.time() - 300)
               commandArray['UpdateDevice'] = ''..jIDX..'|0|'..flow..''
        end
end       

return commandArray
RFXcom433e ver1009,Raspberry Pi,Domoticz v3.5877

KaKu:16c remote,dimmer,wall-sockets,sunscreenswitch
Promax:wall sockets Elro:wall sockets Somfy:RFY screens
TFA:weather station Chinese temperature sensors, smoke detectors, power switches

jonathan12
Posts: 5
Joined: Sunday 31 December 2017 18:30
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by jonathan12 » Tuesday 28 August 2018 11:31

jonathan12 wrote:
Wednesday 15 August 2018 21:27
How big does the voltage drop has to be of the NPN sensor?

Mine is 2.8V with metal detecting and 3.5V without metal.
Input is 5V and i use a zener diode 3.3V

When i test the sensor it is always level=1
The led is on when metal is detected

pi@raspberrypi:~ $ sudo raspi-gpio get 21
GPIO 21: level=1 fsel=0 func=INPUT
Can someone tell me how big the voltage drop has to be?
My sensor is always level 1. With or without metal.

freijn
Posts: 387
Joined: Friday 23 December 2016 17:40
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands Purmerend
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by freijn » Tuesday 28 August 2018 13:30

It must go from VCC to zero

I have found, the higher the voltage the more sensitive it becomes. +5 could work but is too low..

CAREFULL **WARNING** !!

If you make VCC +12 then the output will be +12 as well. Feeding that into a Rapsberry or Arduino will be destructive !

I have made voltage reducer with 2 resistors and 1 led... Nice bonus is the led shows the puls :-)

webrazor
Posts: 29
Joined: Monday 09 November 2015 10:33
Target OS: Raspberry Pi
Domoticz version:
Location: The Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by webrazor » Wednesday 05 September 2018 15:55

I got the original script in this post running but only when i start it manual with

Code: Select all

python watermeter.py
For some reason the script wont execute in the crontab. This is the log:

Code: Select all

Sep  5 15:22:57 raspberrypi cron[390]: (CRON) INFO (Running @reboot jobs)
Sep  5 15:22:57 raspberrypi CRON[435]: (webrazor) CMD (sudo /usr/bin/python /home/pi/domoticz/scripts/watermeter.py >/var/log/cronlog.log 2>&1)
And this is the code in the crontab using: crontab -e

Code: Select all

@reboot sudo /usr/bin/python /home/pi/domoticz/scripts/watermeter.py >/var/log/cronlog.log 2>&1
How can i check the script is really running?

bolderbast
Posts: 4
Joined: Thursday 06 September 2018 17:39
Target OS: Linux
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by bolderbast » Thursday 06 September 2018 17:51

Hi all,

I got this working, however with every 1 liter the Domoticz sensor increases with 10 liters. I can reproduce it as follows:

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=600
Sensor reports 6 m3

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=601
Sensor reports 6.01 m3

But 1 liter should be 0,001 m3 instead of 0,01 m3.

Any suggestions?
Thanks in advance!

Hobbybob
Posts: 147
Joined: Monday 01 May 2017 19:03
Target OS: Raspberry Pi
Domoticz version: Stable
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Hobbybob » Thursday 06 September 2018 18:00

bolderbast wrote:
Thursday 06 September 2018 17:51
Hi all,

I got this working, however with every 1 liter the Domoticz sensor increases with 10 liters. I can reproduce it as follows:

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=600
Sensor reports 6 m3

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=601
Sensor reports 6.01 m3

But 1 liter should be 0,001 m3 instead of 0,01 m3.

Any suggestions?
Thanks in advance!
Make sure you have the correct settings in Domoticz.

Go to "Settings" -< "Meters/counters" and make sure you have 1000 filled in the option water meter divider. You probably have 100 there.

bolderbast
Posts: 4
Joined: Thursday 06 September 2018 17:39
Target OS: Linux
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by bolderbast » Thursday 06 September 2018 18:12

Hobbybob wrote:
Thursday 06 September 2018 18:00
bolderbast wrote:
Thursday 06 September 2018 17:51
Hi all,

I got this working, however with every 1 liter the Domoticz sensor increases with 10 liters. I can reproduce it as follows:

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=600
Sensor reports 6 m3

curl "https://<server>:<port>/json.htm?type=command&param=udevice&idx=966&svalue=601
Sensor reports 6.01 m3

But 1 liter should be 0,001 m3 instead of 0,01 m3.

Any suggestions?
Thanks in advance!
Make sure you have the correct settings in Domoticz.

Go to "Settings" -< "Meters/counters" and make sure you have 1000 filled in the option water meter divider. You probably have 100 there.
Spot on! Thanks for this quick help! :-)

rubberduck84
Posts: 5
Joined: Monday 15 February 2016 10:09
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by rubberduck84 » Friday 05 October 2018 20:39

Ik have problems with the python script.
I got this error on domoticz

2018-10-05 20:37:32.288 Error: EventSystem: Failed to execute python event script "watermeter"
2018-10-05 20:37:32.289 Error: EventSystem: File "<string>", line 61
2018-10-05 20:37:32.289 Error: EventSystem: print "JSON call = "+ str(url1)
2018-10-05 20:37:32.289 Error: EventSystem: ^
2018-10-05 20:37:32.289 Error: EventSystem: SyntaxError: invalid syntax

Have anyone the fix for this problem?

Joep123
Posts: 16
Joined: Monday 26 March 2018 18:44
Target OS: Raspberry Pi
Domoticz version: Beta
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Joep123 » Monday 08 October 2018 18:42

Melissen wrote:
Sunday 26 August 2018 12:01
Also made a script for a waterflowmeter !!!

You first need to make-activate 2 uservariables.
-begin INTEGER value=0
-begintijd INTEGER value=0
Then you need to make a virtual device Waterflow
- go to HARDWARE and make another virtualsensor "Waterflow" at Watermeter and use this as 'waterflow'

After this, you can use this script. jIDX is number of Waterflow device.
Thanks for sharing this script, works fine (just a small typo: functiontimedifference(s) should be function timedifference(s), with a space after function).

I saved the script as script_device_waterflow.lua but I see the script will be triggered mutiple times in a second. How can I solve this? The average load of my Pi increased from 2% to 11-12%.

2018-10-08 18:28:37.117 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.288 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.585 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.851 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.918 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.958 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:39.993 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.027 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.061 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.095 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.129 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.163 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.402 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.638 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:40.929 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:41.168 Status: EventSystem: Script event triggered: Waterflow
2018-10-08 18:28:41.203 Status: EventSystem: Script event triggered: Waterflow

leonkoster
Posts: 2
Joined: Sunday 12 August 2018 20:52
Target OS: -
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by leonkoster » Tuesday 16 October 2018 22:17

I tried making it work but i keep getting the following error:

Traceback (most recent call last):
File "/home/pi/downloads/domoticz/scripts/watermeter.py", line 21, in <module>
f = file(fn, "r+")
NameError: name `file` is not defined

Post Reply

Who is online

Users browsing this forum: al300kr, astrapowerrr and 9 guests