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.
Post Reply
u01pei
Posts: 34
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 » Wednesday 06 September 2017 20:33

Hobbybob wrote:
Saturday 12 August 2017 13:55
Hello, I want to include water-usage in my Domoticz as well, and although it will be dificult to get a wire running between the metercabinet in the hallway where the water-meter is and my livingroom where I have my Raspberry Pi, I am guessing it is going to be the only way...

So: 2 questions:
First off: the device in Domoticz you have a screenshot of is a counter that is modified to display water. I can reproduce that, but I also see a type "Counter incremental". What is the difference between these two, and following that: what is the correct one to use?
Aside from that: Can I connect the blue and brown wires to another power supply, and just the black one to the Pi or does that not work? That would save me 2 wires that I have to move through the rooms... Also: is it a problem if the signal-wire is relatively long? Say, 10 meters?

Oh, and do you need to use any resistor or anything before the signal-wire goes ino the GPIO, or can the Pi handle the output from the sensor as-is?
Why don't you connect the sensor to an esp8266? with esp easy installed on it, I find it is the best solution to get data wireless to your pi. I bought https://www.aliexpress.com/item/new-Wir ... 0.0.RhBndZ

pvangorp
Posts: 121
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 » Wednesday 06 September 2017 20:40

Thats also a way of fixing it :D

pvangorp
Posts: 121
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 » 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
Last edited by pvangorp on Wednesday 06 September 2017 21:01, edited 1 time in total.

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Hobbybob » Wednesday 06 September 2017 20:45

u01pei wrote:
Wednesday 06 September 2017 20:33
Hobbybob wrote:
Saturday 12 August 2017 13:55
Hello, I want to include water-usage in my Domoticz as well, and although it will be dificult to get a wire running between the metercabinet in the hallway where the water-meter is and my livingroom where I have my Raspberry Pi, I am guessing it is going to be the only way...

So: 2 questions:
First off: the device in Domoticz you have a screenshot of is a counter that is modified to display water. I can reproduce that, but I also see a type "Counter incremental". What is the difference between these two, and following that: what is the correct one to use?
Aside from that: Can I connect the blue and brown wires to another power supply, and just the black one to the Pi or does that not work? That would save me 2 wires that I have to move through the rooms... Also: is it a problem if the signal-wire is relatively long? Say, 10 meters?

Oh, and do you need to use any resistor or anything before the signal-wire goes ino the GPIO, or can the Pi handle the output from the sensor as-is?
Why don't you connect the sensor to an esp8266? with esp easy installed on it, I find it is the best solution to get data wireless to your pi. I bought https://www.aliexpress.com/item/new-Wir ... 0.0.RhBndZ
I have somthing setup now with a wire, but perhaps for future sensors (I don't think this will be the last one I connect). Is there a wiki or tutorial or anything on how to connect and configure one of these for usage in Domoticz? I'm very interested.

u01pei
Posts: 34
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 » Wednesday 06 September 2017 21:23

I have somthing setup now with a wire, but perhaps for future sensors (I don't think this will be the last one I connect). Is there a wiki or tutorial or anything on how to connect and configure one of these for usage in Domoticz? I'm very interested.
Yes there is:

https://www.letscontrolit.com/wiki/index.php/ESPEasy

ratjenl
Posts: 17
Joined: Saturday 12 August 2017 9:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by ratjenl » Wednesday 06 September 2017 21:31

I received another 2 sensors. Both are working fine except one wont read through the plastic on my watermeter. As far as i can see i have the same meter posted here in this topic.

Can anybody explain why i don't get the liters but the total amount as stated in the attachment ?
Attachments
water.png
water.png (12.16 KiB) Viewed 752 times

pvangorp
Posts: 121
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 » Wednesday 06 September 2017 21:59

Disconnect it from your pi and test it with a 9v battery. The higher the voltage, the bettter the detection. When it works oke you'll need a 9v or 12v adapter and a step-down converter otherwise you'll fry your pi.

The litres is only the first day. The counter is set initially today.

ratjenl
Posts: 17
Joined: Saturday 12 August 2017 9:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by ratjenl » Wednesday 06 September 2017 22:10

One is working from within the pi, the other one just isn't strong enough even with an 12v or 24v adapter is just doenst read through the plastic. I guess there is a slight difference in both npn's.

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Hobbybob » Thursday 07 September 2017 8:35

ratjenl wrote:
Wednesday 06 September 2017 22:10
One is working from within the pi, the other one just isn't strong enough even with an 12v or 24v adapter is just doenst read through the plastic. I guess there is a slight difference in both npn's.
I had the same problem. The sensor worked when I tested it by holding it against something metal, but the plastic top on the watermeter was too thick or something. Also with a 12v adapter. I now have a working setup with a tcrt5000 with the help of heggink. That uses an infared detector, maybe you could look at that.

D'rMorris
Posts: 296
Joined: Thursday 01 May 2014 9:01
Target OS: Raspberry Pi
Domoticz version:
Location: Netherlands - Sittard
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by D'rMorris » Thursday 07 September 2017 8:43

ratjenl wrote:
Wednesday 06 September 2017 21:31
I received another 2 sensors. Both are working fine except one wont read through the plastic on my watermeter. As far as i can see i have the same meter posted here in this topic.

Can anybody explain why i don't get the liters but the total amount as stated in the attachment ?
If you share your script we can have a look. Perhaps you are mixing up nvalues and svalues?

User avatar
LouiS22
Posts: 449
Joined: Friday 27 February 2015 14:21
Target OS: Raspberry Pi
Domoticz version: beta
Location: Budapest, Hungary
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by LouiS22 » Thursday 07 September 2017 9:35

ratjenl wrote:
Wednesday 06 September 2017 21:31
I received another 2 sensors. Both are working fine except one wont read through the plastic on my watermeter. As far as i can see i have the same meter posted here in this topic.

Can anybody explain why i don't get the liters but the total amount as stated in the attachment ?
1 m3 is 1000 liter. So your screenshot seems correct. 914 m3 is 914000 liter.

One more thing: have you set the divider at domoticz's settings page (Settings/Meters-Counters/) (as stated on the first post)? Maybe that'S the step you missed.

User avatar
gielie
Posts: 180
Joined: Tuesday 12 January 2016 12:40
Target OS: Raspberry Pi
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by gielie » Thursday 07 September 2017 11:31

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
OK i tried this script but i can't get to work, i don't understand any of it, the python script works great but id like this one to work either and there must be something im missing.

Can you change the script with some additions of the variables in the beginning like IDX=? GP0=?
What kind of switch do i have to add? and how does the script know what gpo pin i use.
- Vision ZU1401 USB Stick
- Aeotec MultiSensor 6
- FIBARO FGS222
- FIBARO FGWPE Wall Plug
- Everspring AN157
- Neo CoolCam Power plug
- Neo CoolCam PIR Sensor
- Popp Smoke Detector
- Toon
- Kodi Media Server

ratjenl
Posts: 17
Joined: Saturday 12 August 2017 9:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by ratjenl » Thursday 07 September 2017 18:20

Everything is working now ok for me. Domoticz is showing a lot more then the actual usage ( domoticz says 915.333 while the meter says 915.261. I am trying to figure out how to fix this, maybe it is because i placed the npn not good enough. Sometimes the red led keeps burning. Anybody else got this issue aswell ?

Micha123
Posts: 15
Joined: Monday 28 August 2017 16:44
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Micha123 » Friday 08 September 2017 9:26

Check hownyour sensor works.


If you sensor short/unshort VCC then you need to pulldown gpio
If your sensor is short/unshort GND then you need to pullup gpio


Then you need to know when your sensor is shorting unshorting pin (vcc of gnd)

If it unshort pin by bounce so you need in your script


if (devicechanged['GPIO Watermeter'] == 'Off')


If it shorts the pin by bounce you need


if (devicechanged['GPIO Watermeter'] == 'on')

If you have that wrong, so you became wrong measure.

ratjenl
Posts: 17
Joined: Saturday 12 August 2017 9:13
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by ratjenl » Friday 08 September 2017 21:06

Micha123 wrote:
Friday 08 September 2017 9:26
Check hownyour sensor works.


If you sensor short/unshort VCC then you need to pulldown gpio
If your sensor is short/unshort GND then you need to pullup gpio


Then you need to know when your sensor is shorting unshorting pin (vcc of gnd)

If it unshort pin by bounce so you need in your script


if (devicechanged['GPIO Watermeter'] == 'Off')


If it shorts the pin by bounce you need


if (devicechanged['GPIO Watermeter'] == 'on')

If you have that wrong, so you became wrong measure.
I don't get anything of what you are saying my friend. I got exactly the same sensor as the topicstarter

Trigun
Posts: 183
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Friday 15 September 2017 11:33

hi pvangorp,

I recently received a new NPN sensor.
I tested t with a 9v battery and it works!

when I put in on my meter, it doesn't work. I believe th glass is too thick for the sensor to measure anything.
is there a solution for this problem?
all tests work so I am close to the final step.

Thnx in advance!

User avatar
gielie
Posts: 180
Joined: Tuesday 12 January 2016 12:40
Target OS: Raspberry Pi
Domoticz version: latest β
Location: The Netherlands (Alkmaar)
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by gielie » Friday 15 September 2017 11:44

Trigun wrote:
Friday 15 September 2017 11:33
hi pvangorp,

I recently received a new NPN sensor.
I tested t with a 9v battery and it works!

when I put in on my meter, it doesn't work. I believe th glass is too thick for the sensor to measure anything.
is there a solution for this problem?
all tests work so I am close to the final step.

Thnx in advance!
I had the same with one of my sensors (one worked out of the box one didnt).
What i did i took some of the plastic tip of the sensor with sandpaper, just a small bit and tested it and it worked, probably the plastic tip is too thick.
- Vision ZU1401 USB Stick
- Aeotec MultiSensor 6
- FIBARO FGS222
- FIBARO FGWPE Wall Plug
- Everspring AN157
- Neo CoolCam Power plug
- Neo CoolCam PIR Sensor
- Popp Smoke Detector
- Toon
- Kodi Media Server

Trigun
Posts: 183
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Friday 15 September 2017 11:49

gielie wrote:
Trigun wrote:
Friday 15 September 2017 11:33
hi pvangorp,

I recently received a new NPN sensor.
I tested t with a 9v battery and it works!

when I put in on my meter, it doesn't work. I believe th glass is too thick for the sensor to measure anything.
is there a solution for this problem?
all tests work so I am close to the final step.

Thnx in advance!
I had the same with one of my sensors (one worked out of the box one didnt).
What i did i took some of the plastic tip of the sensor with sandpaper, just a small bit and tested it and it worked, probably the plastic tip is too thick.
Sounds like an idea! Will test it, thnx for Your reply!


Sent from my iPhone using Tapatalk

Trigun
Posts: 183
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Saturday 16 September 2017 23:35

Trigun wrote:
Friday 15 September 2017 11:49
gielie wrote:
Trigun wrote:
Friday 15 September 2017 11:33
hi pvangorp,

I recently received a new NPN sensor.
I tested t with a 9v battery and it works!

when I put in on my meter, it doesn't work. I believe th glass is too thick for the sensor to measure anything.
is there a solution for this problem?
all tests work so I am close to the final step.

Thnx in advance!
I had the same with one of my sensors (one worked out of the box one didnt).
What i did i took some of the plastic tip of the sensor with sandpaper, just a small bit and tested it and it worked, probably the plastic tip is too thick.
Sounds like an idea! Will test it, thnx for Your reply!


Sent from my iPhone using Tapatalk
It Worked! thanks for the great tip!

Trigun
Posts: 183
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 3.5877
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Saturday 16 September 2017 23:46

pvangorp wrote:
Sunday 03 September 2017 7:56
The problem with my previous script is that when no water used, the devices shows offline.
I fixed this with a keep a live part. When no water detected update with keep a live every 5 minutes, just like the other smart meters in Domoticz.

Code: Select all

commandArray = {}

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

return commandArray
Hi pvangorp,

where did you put this script and how to use it. I am experiencing the same.

Thnx in advance!

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests