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.
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 » Wednesday 04 April 2018 21:25

Thanx for youre repsponse.
instead I changed my script
Every 0.5 sec, I read out the level of the GPIO in an infinit loop.
When it has changed to on I add the counter with 1 and set a variable to on
next reading gpio = on and variable = on nothing happenes
next readin gpio = off variable = changed to off

so far (over 1 week now) not 1 liter deviation :-)


philchillbill wrote:
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

User avatar
philchillbill
Posts: 239
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 » Tuesday 24 April 2018 8:01

jnmulder wrote:Thanx for youre repsponse.
instead I changed my script
Every 0.5 sec, I read out the level of the GPIO in an infinit loop.
When it has changed to on I add the counter with 1 and set a variable to on
next reading gpio = on and variable = on nothing happenes
next readin gpio = off variable = changed to off

so far (over 1 week now) not 1 liter deviation :-)
Maybe you should post a code-snippet here to help others who have problems with signal bounce.



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.

Joep123
Posts: 36
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 » Sunday 06 May 2018 11:35

Hobbybob wrote:
Friday 25 August 2017 18:55
Today my sensor came in (the one with the yellow cap on the end), and it worked really well when I held a screwdriver next to it, but it looks like the plastic cap on top of the half-moon disc is too thick. It doesn't respond to that in any way... I've tried it with 5V and GND from the Pi (signal-cable not attached of course), and also with a 12V-adapter connected to it.

Any ideas if I can do something about this, or do I have to find a completely other way to register the water-usage? I'd rather not start damaging the water-meter since that belongs to the water-company.
I have the same situation. Did you find a solution for the plastic cap?
I used some sand paper and now the led is only on at a small piece of the water meter. If the metal part turns the led goes off.

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 » Sunday 06 May 2018 12:19

Joep123 wrote:
Sunday 06 May 2018 11:35
I have the same situation. Did you find a solution for the plastic cap?
No, I did not. I switched to another system that uses light (IR) to check when the haf-moon disc is rotating. It is a tcrt5000 I am using now.

Joep123
Posts: 36
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 » Tuesday 08 May 2018 21:24

@pvangorp

Time by time I get this error:

Code: Select all

2018-05-08 21:13:26.537 Error: EventSystem: in Watermeter: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
2018-05-08 21:13:33.693 Error: EventSystem: in Watermeter: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
2018-05-08 21:13:33.890 Error: EventSystem: in Watermeter: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
2018-05-08 21:13:33.909 Error: EventSystem: in Watermeter: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
As soon as I put a number > 0 into the user variable everything is fine for some time.
Do you have a solution for this issue?

SorzZy
Posts: 3
Joined: Sunday 07 June 2015 9:39
Target OS: Raspberry Pi
Domoticz version: Beta
Location: netherlands (the hague)
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by SorzZy » Sunday 20 May 2018 8:55

Same problem here!

2018-05-20 08:47:02.910 Error: EventSystem: in lua-water: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)

u01pei
Posts: 54
Joined: Sunday 04 January 2015 17:17
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by u01pei » Sunday 20 May 2018 10:27

Hobbybob wrote:
Sunday 06 May 2018 12:19
Joep123 wrote:
Sunday 06 May 2018 11:35
I have the same situation. Did you find a solution for the plastic cap?
No, I did not. I switched to another system that uses light (IR) to check when the haf-moon disc is rotating. It is a tcrt5000 I am using now.
I have the same sensor and had the same issue. The plastic cap is just a little to thick, so I used a sharp knife to cut it of. I wrecked one switch first, as I removed the entire orange cap, but that made the resin 9holding the sensor element) come loose, making it very fragile and causing a wire to break.
So on the second switch I only removed the lower side of the cap (so a only a cilinder remains around the sensor). The orange material is about 0,5 mm thick, so if you cut about 0,5 from the bottom edge you will remove only a disk of orange material and the cilinder remains attached.

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 » Sunday 20 May 2018 11:09

u01pei wrote:
Sunday 20 May 2018 10:27
I have the same sensor and had the same issue. The plastic cap is just a little to thick, so I used a sharp knife to cut it of. I wrecked one switch first, as I removed the entire orange cap, but that made the resin 9holding the sensor element) come loose, making it very fragile and causing a wire to break.
So on the second switch I only removed the lower side of the cap (so a only a cilinder remains around the sensor). The orange material is about 0,5 mm thick, so if you cut about 0,5 from the bottom edge you will remove only a disk of orange material and the cilinder remains attached.
After I had the IR-sensor in place I read about this. I belief that was someone who used sanding-paper to make it thinner. Perhaps I'll switch to this method sometime. My current setup does count water sometimes when nothing is being used. The half-moon disc is then exactly on the edge of where it is measured... Then again: this problem also occurs with the induction-sensors.

User avatar
sincze
Posts: 995
Joined: Monday 02 June 2014 22:46
Target OS: Raspberry Pi
Domoticz version: 4.9700
Location: Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by sincze » Tuesday 12 June 2018 12:33

After several years of having a TCRT-5000 as a watermeter I decided to check out the NPN as well.
NPN Meter.jpeg
NPN Meter.jpeg (109.91 KiB) Viewed 1317 times
.
TCRT is connected to the Raspberry pi. The NPN is attached to a WEMOS to create a wireless solution.

In the image you can see the test setup.
Not a lot of room over the watermeter wheel, but just sufficient to have both meters up and running.
Using Pass2php since 2016-12
LAN: RFLink, P1-Port, OTGW, MySensors
USB: RFXCom, ZWave
WIFI: Mi-light Wifi-Bridge, Sonoff, ESP8266, Xiaomi Gateway
Solar: Omnik Inverter, PVOutput
Video: Kodi clients with Harmony HUB
Sensors: You name it I probably got 1.

jagroeneveld
Posts: 6
Joined: Tuesday 29 May 2018 9:50
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by jagroeneveld » Tuesday 19 June 2018 17:36

In order to see if the results are successfully logged to Domoticz, I added the following lines
#err1 = response1.read()
#print "response = " + str(err1)

just after
#Voor debug => print voorbeeld van de JSON aanroep en/of de counter
#print "JSON call = "+ str(url1)
#print "Watermeter Counter = " + str(Counter)

I needed to do so because I use authorization in Domoticz

jonathan12
Posts: 6
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 » Sunday 22 July 2018 19:14

pvangorp wrote:
Wednesday 06 September 2017 20:45
I've upgraded my script by adding a "uservariable" this makes it possible to set the initial value and to make a correction when your PI is off for a while. Create a user variable called "WaterMeter" and enter the meter value eg "999999" (Where "999999" = 999.999m3). When the value is "0" it ignores the user variable.
I also added a variable for IDX, to make it easier to change the script.
So you don't need the line
To set the initial meter values http://<<YOUR DOMOTICZ IP>>/json.htm?type=command&param=udevice&idx=34&svalue=999999
any more

My updated script

Code: Select all

commandArray = {}

-- Set IDX of Watermeter
iIDX = 34

-- 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"]..''
    commandArray['Variable:WaterMeter'] = tostring(0)
end

-- Water usage
-- Retrieve value from water meter device:
sWaterUsage = otherdevices_svalues['Waterverbruik']

-- 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 + 1)
	
	print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ")
	commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsageTot..''
else
    -- Keep a live device
    if (timedifference(otherdevices_lastupdate["Waterverbruik"]) > 300)
    then
        print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ")
        commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsage..''   
    end
end

return commandArray
I question from a Noob:

When I enter the url in my browser http://<<YOUR DOMOTICZ IP>>/json.htm?type=command&param=udevice&idx=34&svalue=999999 I get this output:

{
"status" : "ERR"
}

When i try to read the version of domoticz http://<<YOUR DOMOTICZ IP>>/json.htm?type=command&param=getversion it works.

What am I doing wrong?

And maybe someone can edit the first post with the latest script, and the info about using a zener diode. Now al people do have to read all the postings.

pvangorp
Posts: 116
Joined: Tuesday 28 March 2017 10:18
Target OS: Raspberry Pi
Domoticz version: Latest B
Location: The Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by pvangorp » Sunday 22 July 2018 19:33

Start your url with ?param=......... &param is reserved. When you change the order of the url string it will work. json.htm?param=udevice&type=command&idx=34&svalue=999999

jonathan12
Posts: 6
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 » Monday 23 July 2018 21:08

http://xxx.xxx.xxx.xxx:8080/json.htm?pa ... lue=999999 is also giving me:

{
"status" : "ERR"
}

Without the port 8080 i get a pihole page. (Pihole is also running on my Pi)

pvangorp
Posts: 116
Joined: Tuesday 28 March 2017 10:18
Target OS: Raspberry Pi
Domoticz version: Latest B
Location: The Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by pvangorp » Monday 23 July 2018 21:24

Looks like your watermeter is not on idx34? 34 is the idx of my watermeter. Is your watermeter (RFXMeter) on the same idx??? Please double check the number in your device list.

DutchSolar
Posts: 5
Joined: Sunday 23 August 2015 20:43
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by DutchSolar » Friday 27 July 2018 9:35

Thanks to everyone in this forum for making all this possible.
I have now also successfully added my watermeter to Domoticz.

1 bug that keeps popping up and is really annoying is that whenever you change a device or lua script, the log will show :

Code: Select all

2018-07-27 09:19:58.007 Status: EventSystem: reset all device statuses...
And then the LUA script starts throwing errors.

Code: Select all

2018-07-27 09:20:02.164 Error: EventSystem: in WaterMeterLuav2: [string "commandArray = {}
..."]:18: attempt to perform arithmetic on global 'sWaterUsage' (a nil value)
The only way to get it working again (to my knowledge) is to fill the uservariable with the total water usage.
This is of course quite annoying because if any water is used during this error period, its usage is not recorded. That means you have to check on the actual meter. Sadly, in my case, the meter is quite inaccessible.

The error is thrown on line 18, Line 18 is :

Code: Select all

 sWaterUsagePrint = tonumber(sWaterUsage / 1000);

Anyone have any idea how I (and the others facing the same problem) can fix this?

My lua script in full :

Code: Select all

commandArray = {}

-- Set IDX of Watermeter
iIDX = 256

-- 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"]..''
    commandArray['Variable:WaterMeter'] = tostring(0)
end

-- Water usage
-- Retrieve value from water meter device:
sWaterUsage = otherdevices_svalues['Waterverbruik']

-- 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 + 1)
	
	print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ")
	commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsageTot..''
else
    -- Keep a live device
    if (timedifference(otherdevices_lastupdate["Waterverbruik"]) > 300)
    then
        print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ")
        commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsage..''   
    end
end

return commandArray
Thanks for taking the time to read this!

arnaudarduino
Posts: 4
Joined: Wednesday 06 July 2016 22:31
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by arnaudarduino » Friday 10 August 2018 21:28

Great tutorial, now my watermeter is in domoticz.
This puls counter works great for 1 puls is 1 liter ,kwh, m3 what ever.
Is it possible to change a little for puls S0 kwh , that means my kwh meter has 2000 imp for 1 kwh, 1pulse is 0.5 ... or 2pulse is 1....
When i change

Code: Select all

      Counter = int(c)
  Counter = Counter + 1       
  f.close()   
1 into 0.5 this script stops working.

What do i have to do txs

jonathan12
Posts: 6
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 » 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
Last edited by jonathan12 on Saturday 18 August 2018 10:34, edited 1 time in total.

freijn
Posts: 401
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 » Wednesday 15 August 2018 23:17

Jhon

I have put my sensor on 12 volts, but indeed.. limit the max voltage with an LED as the output will also become
12 volt when high. Your raspberry or arduino would not like that!

Cheers,

Frank

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 » Friday 24 August 2018 23:21

Hi,

Thx to PvanGorp, who started in this threat the LUA script.

Python didn't work for me, so the LUA script was my solution.

I only changed/added something in this script.
In the device/meter you can simply add the start-value. So the start-value is not counted in the usage. So you only see the usage in the logs, but the total-counter gives the good readings.

Instead of PvanGorp's startvalue in uservariables (watermeter) this value is used for correcting the total-counter. For example: if the counter is off by 15 litres after a while, you put 15 in the uservariable and a few seconds later the totalcounter is back on track.
You can enter a positive or negative value in this uservariable.


my counter in Utility is: WaterTester (because I used this one for editing this script) instead of WaterMeter (PvanGorp)
on/off gpio (switch) is: same as PvanGorp
uservariables: WaterMeter
LUA; device

Code: Select all

commandArray = {}

-- Set IDX of Watermeter
iIDX = 403

SWaterUsage2 = otherdevices_svalues['WaterTester']
SWaterUsage2 = tonumber(SWaterUsage2);
SWaterUsage3 = uservariables["WaterMeter"]
SWaterUsage3 = tonumber(SWaterUsage3);
SWaterUsage4 = (SWaterUsage2 + SWaterUsage3)

-- Set Watermeter based on user variable "WaterMeter"
if (uservariables["WaterMeter"] == 0 ) 
then
    sWaterUsage = SWaterUsage4
else
    print("Water usage is set to " .. SWaterUsage4 / 1000 .. "m3 by user")
    commandArray['UpdateDevice'] = ''..iIDX..'|0|'..SWaterUsage4..''
    commandArray['Variable:WaterMeter'] = tostring(0)
    sWaterUsage = SWaterUsage4
end

-- Water usage
-- Retrieve value from water meter device:
-- sWaterUsage = otherdevices_svalues['WaterTester']



-- 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 + 1)
	
	print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ")
	commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsageTot..''
else
    -- Keep a live device
    if (timedifference(otherdevices_lastupdate["WaterTester"]) > 300)
    then
        print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ")
        commandArray['UpdateDevice'] = ''..iIDX..'|0|'..sWaterUsage..''   
    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

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 » Saturday 25 August 2018 0:16

The only problem I'm facing right now is the totalcounter in my device.
Instead of 3 digits behind the , I've got 2 digits.
When I make a new device I've got 3 digits, but when I change the 'startvalue' it goes to 2 digits.

Instead of 1184.881m3 it shows 1184.88m3. When the counter reaches 1184.885 it shows 1184.89 (till 1185.894)
How can I get 3 digits back?

Think it's a problem in Domoticz itself. But I hope someone can help me
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

Post Reply

Who is online

Users browsing this forum: georgesattali and 2 guests