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.
Trigun
Posts: 187
Joined: Wednesday 30 November 2016 12:58
Target OS: Raspberry Pi
Domoticz version: 4.9700
Contact:

Water meter readout with raspberry and Inductive NPN sensor

Post by Trigun » Friday 13 October 2017 20:48

pvangorp wrote:
Friday 13 October 2017 19:36
Should be sWaterUsage in keep Alice part!
alright, I tested it with using the line in a browser and that works! the virtual device did change, great!

but back in the script it does nog change, I've also tried the "Commandarray... etc" no luck either.

any ideas?

this is my setup:

Code: Select all

commandArray = {}

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

-- 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 ")


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'] = '8|0|'..sWaterUsageTot..''
  os.execute('wget http://IPADDRESS:PORT/json.htm?type=command&param=udevice&idx=IDX&svalue='..sWaterUsageTot..' -O /dev/null')
else
    -- Keep a live device
    if (timedifference(otherdevices_lastupdate["Watermeter"]) > 300)
    then
        print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ");
        commandArray['UpdateDevice'] = '8|0|'..sWaterUsage..'' 
        os.execute('wget http://IPADDRESS:PORT/json.htm?type=command&param=udevice&idx=IDX&svalue='..sWaterUsage..' -O /dev/null')   
    end
end

return commandArray

pvangorp
Posts: 115
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 » Friday 13 October 2017 20:58

Do you get some sort of error in the log? Looks oke to me. Is the ip included in your system settings network e.g. 127.0.0.*;192.168.*.* of both devices? Executing in browser should be the same as in script. You can use a print for debuging instead of os.execute. Otherwise I need to create a simmilar environment to test it in real.

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Friday 13 October 2017 21:11

pvangorp wrote:
Friday 13 October 2017 20:58
Do you get some sort of error in the log? Looks oke to me. Is the ip included in your system settings network e.g. 127.0.0.*;192.168.*.* of both devices? Executing in browser should be the same as in script. You can use a print for debuging instead of os.execute.
I can see the lua script being triggerd but the master device is not being updated.
I don't see any errors at all. I'try the print option.

thank you!

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Friday 13 October 2017 21:21

Trigun wrote:
Friday 13 October 2017 21:11
pvangorp wrote:
Friday 13 October 2017 20:58
Do you get some sort of error in the log? Looks oke to me. Is the ip included in your system settings network e.g. 127.0.0.*;192.168.*.* of both devices? Executing in browser should be the same as in script. You can use a print for debuging instead of os.execute.
I can see the lua script being triggerd but the master device is not being updated.
I don't see any errors at all. I'try the print option.

thank you!
Strange, it seems nothing happens. is this what you meant with "print"?

Code: Select all

commandArray = {}

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

-- 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 ")


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'] = '8|0|'..sWaterUsageTot..''
  print('wget http://192.168.1.94:8080/json.htm?type=command&param=udevice&idx=157&svalue='..sWaterUsageTot..' -O /dev/null')
else
    -- Keep a live device
    if (timedifference(otherdevices_lastupdate["Watermeter"]) > 300)
    then
        print("Water usage is still " .. sWaterUsage / 1000 .. "m3 ");
        commandArray['UpdateDevice'] = '8|0|'..sWaterUsage..'' 
        print('wget http://192.168.1.94:8080/json.htm?type=command&param=udevice&idx=157&svalue='..sWaterUsage..' -O /dev/null')   
    end
end

return commandArray
it doen't show anything at all in the log file. it's just like the line is not being used.

pvangorp
Posts: 115
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 » Friday 13 October 2017 21:27

What happens when you swap the commandarray and weet line order. The print above the commandarray is in the log?

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Friday 13 October 2017 21:33

pvangorp wrote:
Friday 13 October 2017 21:27
What happens when you swap the commandarray and weet line order. The print above the commandarray is in the log?
something happend.

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
but unfortunately nothing happens on the other device.

i just found out that I never see the following print:

Code: Select all

print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
is this correct or should it only set once, in the beginning?

User avatar
LouiS22
Posts: 497
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 » Monday 23 October 2017 10:19

Trigun wrote:
Friday 13 October 2017 21:33
pvangorp wrote:
Friday 13 October 2017 21:27
What happens when you swap the commandarray and weet line order. The print above the commandarray is in the log?
something happend.

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
but unfortunately nothing happens on the other device.

i just found out that I never see the following print:

Code: Select all

print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
is this correct or should it only set once, in the beginning?
Have you found the bug yet?

pvangorp
Posts: 115
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 25 October 2017 18:07

New feature tip. You can hide the dummy “GPIO Watermeter” by putting a $ in front of the name (don’t forget to change the script aswell) or put the device in the “hidden devices” Floor plan.

Draakje
Posts: 113
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Draakje » Sunday 29 October 2017 21:26

Hobbybob wrote:
Sunday 13 August 2017 20:36
Okay, I've tried to read up on the information about this, and I came up with the following wiring-scheme. As said, I am not very good at reading diagrams with symbols, so I made something a litte more visual for myself.

Can anybody with a little more knowledge than me check if this would be a good way? I calculated the 1kOhm and 2kOhm on the site oohlaf mentioned, and fiddled with the Ohms to get two values that I can actually buy, and produces as close to 3.3V as possible.

Schakeling watermeter.jpg
Ok I would like to have some more information about this setup..

I am about to connect the same sensor on my Raspberry pi3.
I have read about the voltage being 3,3V but My raspberry has (2) 5 volt connections on the GPIO.

So my real question is.. do I need the resistors shown in the diagram? as I am putting 5 volt in.....

Many thanks for any info.
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

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

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Trigun » Sunday 29 October 2017 21:58

LouiS22 wrote:
Monday 23 October 2017 10:19
Trigun wrote:
Friday 13 October 2017 21:33
pvangorp wrote:
Friday 13 October 2017 21:27
What happens when you swap the commandarray and weet line order. The print above the commandarray is in the log?
something happend.

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
but unfortunately nothing happens on the other device.

i just found out that I never see the following print:

Code: Select all

print("Water usage is set to " .. sWaterUsageTot / 1000 .. "m3 ");
is this correct or should it only set once, in the beginning?
Have you found the bug yet?
Hi louiS22,

Haven't found it yet as the code seems correct.
I was hoping pvangorp could help us out.

pvangorp
Posts: 115
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 30 October 2017 5:24

Draakje wrote:
Sunday 29 October 2017 21:26
Hobbybob wrote:
Sunday 13 August 2017 20:36
Okay, I've tried to read up on the information about this, and I came up with the following wiring-scheme. As said, I am not very good at reading diagrams with symbols, so I made something a litte more visual for myself.

Can anybody with a little more knowledge than me check if this would be a good way? I calculated the 1kOhm and 2kOhm on the site oohlaf mentioned, and fiddled with the Ohms to get two values that I can actually buy, and produces as close to 3.3V as possible.

Schakeling watermeter.jpg
Ok I would like to have some more information about this setup..

I am about to connect the same sensor on my Raspberry pi3.
I have read about the voltage being 3,3V but My raspberry has (2) 5 volt connections on the GPIO.

So my real question is.. do I need the resistors shown in the diagram? as I am putting 5 volt in.....

Many thanks for any info.
Use a zener diode, as I mentioned before. The zener diode is for protection. It prevents that the GPIO pin get more then 3.3v. https://www.kiwi-electronics.nl/zenerdiode-3v3-500ma

You can also use a logic level converter from 5v to 3.3v, more accurate, but zener is cheaper.
Last edited by pvangorp on Monday 30 October 2017 5:36, edited 3 times in total.

pvangorp
Posts: 115
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 30 October 2017 5:32

I created a test environment for your situation.

As you can see in your dump something goes wrong!!!

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 looked into it and &param is translated wrong by Domoticz. (type=command¶m=udevice)

Change the order of the url parameters and use:

Code: Select all

json.htm?param=udevice&type=command&idx=......
and it will work.

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 30 October 2017 7:53

LouiS22 wrote:
Wednesday 11 October 2017 10:35
Is there any way to transfer these values from a slave PI to a Master PI? (Virtual counters don't get updated this way :( ).
I'm just curious why everybody seems to think that the slave-pi in this situation needs to run Domoticz? I have a slave-pi in my house to read out a quad current meter that I have installed in my meter closet (better English than meter cast :mrgreen: ) to give more granularity per breaker-group than my p1 smart-meter does. I just update the counters/meters/switches in my main (and only) Domoticz instance (running on a NUC incidentally, not a pi) using JSON.

Code: Select all

    if (pwr[i] != oldpwr[i] ):
      idx=str(meters[i])
      url = 'http://192.168.1.12:8080/json.htm?type=command&param=udevice&nvalue=0&idx='+idx+'&svalue='+pwr[i]
      print "Meter | "+time.ctime()+"\n "+url
      try:
        request = urllib2.Request(url)
        response = urllib2.urlopen(request)
      except urllib2.HTTPError, e:
        print e.code; time.sleep(60)
      except urllib2.URLError, e:
        print e.args; time.sleep(60)


is an example of how I update 'remotely' without having to have Domoticz locally on the remote machine. What's the benefit of having Domoticz on the slave-pi - might be easier than DDNS if the master and slave pi's are not on the same WiFi?
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.

Draakje
Posts: 113
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Draakje » Monday 30 October 2017 8:41

pvangorp wrote:
Monday 30 October 2017 5:24
Draakje wrote:
Sunday 29 October 2017 21:26
Hobbybob wrote:
Sunday 13 August 2017 20:36
Okay, I've tried to read up on the information about this, and I came up with the following wiring-scheme. As said, I am not very good at reading diagrams with symbols, so I made something a litte more visual for myself.

Can anybody with a little more knowledge than me check if this would be a good way? I calculated the 1kOhm and 2kOhm on the site oohlaf mentioned, and fiddled with the Ohms to get two values that I can actually buy, and produces as close to 3.3V as possible.

Schakeling watermeter.jpg
Ok I would like to have some more information about this setup..

I am about to connect the same sensor on my Raspberry pi3.
I have read about the voltage being 3,3V but My raspberry has (2) 5 volt connections on the GPIO.

So my real question is.. do I need the resistors shown in the diagram? as I am putting 5 volt in.....

Many thanks for any info.
Use a zener diode, as I mentioned before. The zener diode is for protection. It prevents that the GPIO pin get more then 3.3v. https://www.kiwi-electronics.nl/zenerdiode-3v3-500ma

You can also use a logic level converter from 5v to 3.3v, more accurate, but zener is cheaper.
And the zener diode goes on the input (GPIO pin 40) ?
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

pvangorp
Posts: 115
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 30 October 2017 12:28

To your input GPIO of your Pi. Check your zener diode with a voltage meter. It does mater how you connect it. If wrong it stil gives 5v to your pi!

Draakje
Posts: 113
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Draakje » Monday 30 October 2017 12:33

pvangorp wrote:
Monday 30 October 2017 12:28
To your input GPIO of your Pi. Check your zener diode with a voltage meter. It does mater how you connect it. If wrong it stil gives 5v to your pi!
Ok I am not an expert in zenerdiodes. So what is the correct way? how do I check it with a voltage meter?
what to look for?
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

pvangorp
Posts: 115
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 30 October 2017 12:35

The output is about 3volt or about 5volt when wrong way connected.

Draakje
Posts: 113
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Draakje » Monday 30 October 2017 12:36

pvangorp wrote:
Monday 30 October 2017 12:35
The output is about 3volt or about 5volt when wrong way connected.
Ok so test when the sensor is connected (but not to the GPIO)
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

pvangorp
Posts: 115
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 30 October 2017 12:38

Yep

Draakje
Posts: 113
Joined: Thursday 22 October 2015 21:14
Target OS: Linux
Domoticz version: 3.5468
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by Draakje » Monday 30 October 2017 12:41

pvangorp wrote:
Monday 30 October 2017 12:38
Yep
Many thanks! will follow up :)
Hardware: Raspberry Pi 3, OTGW, 433MHz Superheterodyne 3310 RF Link
Software: Ubuntu 16.04, Domoticz v3.5468, WiringPi, rc-switch

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests