Page 20 of 20

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 8:55
by gizmocuz

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 9:08
by Benneton
Thanks for this tip, problem is that I need to order stuff and work out how to use the ESP8266 Proximity sensor.
The python script has worked for many years very so I would like to stick to it.

Need to sort out many other things as well, from PI 3 to PI 4 was not as straight forward as I thought.

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 9:25
by waltervl
There is a watermeter Python plugin https://github.com/akamming/domoticz-watermeter
Perhaps this is compatible with your setup.

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 15:13
by Benneton
Thank you, saw that plugin too, so as I did not get the script updated and working under Python 3 I installed the plugin
This appeared to work fine. Could create the hardware.
Did not see a new 'apparaat' (device) so I figured it pickup on the existing watermeter (IDX 1992)
Is my assumption correct? If not is there a way to associate this plugin with the existing device created for watermeter (IDX 1992)?

Issue is that is not updating the values in the watermeter deivce. The file created to track watermeter values is okay. Saw that is created in:
/home/bernard/domoticz/ the file "meterstand_water.txt"
when opening I see there are values added / increasing after water use.

In the domoticz log I see these error messages:
2023-02-09 14:20:33.091 Error: WaterMeter: Call to function 'onHeartbeat' failed, exception details:
2023-02-09 14:20:33.091 Error: WaterMeter: Traceback (most recent call last):
2023-02-09 14:20:33.091 Error: WaterMeter: File "/home/bernard/domoticz/plugins/domoticz-watermeter/plugin.py", line 340, in onHeartbeat
2023-02-09 14:20:33.091 Error: WaterMeter: _plugin.onHeartbeat()
2023-02-09 14:20:33.091 Error: WaterMeter: File "/home/bernard/domoticz/plugins/domoticz-watermeter/plugin.py", line 303, in onHeartbeat
2023-02-09 14:20:33.091 Error: WaterMeter: Domoticz.Log("RFXMeter/RFXMeter counter ("+Devices[1].Name+") - "+str(counter/1000)+" M3")
2023-02-09 14:20:33.091 Error: WaterMeter: KeyError: 1

Additional information:
Platform PI 4 model b - 4gb ram
OS version:
PRETTY_NAME="Raspbian GNU/Linux 11 (bullseye)"
NAME="Raspbian GNU/Linux"
VERSION_ID="11"
VERSION="11 (bullseye)"
VERSION_CODENAME=bullseye

Domoticz version: 2022.2 (stable)

Does anyone has an idea what these messages mean and how I can fix them?

As always many thanks for the support.

Bernard

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 17:03
by waltervl
Did you stop/dispable the old python script? as it seems to be working now.....

The plugin should create a new device, perhaps you have to enable it in device list to see it on the utility tab.
There is a device replace function under the edit button to replace old device by new device.

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 17:31
by Benneton
Of course enable new devices....
Did that and found the new water meter device.
Updated the meterstand_water.txt
and now total is correct.

I was to quick in deleting the old watermeter, should have replaced it to keep history....

But that is to late now.

Thank you for your help and pointing me in the right direction.

Seems to work fine again :)

Bernard

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Thursday 09 February 2023 22:49
by azonneveld
I used a prox before, but accuracy was poor, switching to an optical sensor provided better results.

See this thread: viewtopic.php?p=297311#p297311

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Wednesday 01 March 2023 15:21
by Copitano
For those who benefit from it, this watermeterscript is working for me on Domoticz 2023.1, 64 Bits Bullseye, Python 3.9.2

Code: Select all

#!/usr/bin/python
import RPi.GPIO as GPIO
import time
import requests
import os

#Watermeter stand (wordt alleen initeel gebruikt als er geen bestand meterstand_water.txt is)
global Counter
Counter = 0

#Domoticz URL
domoticz_url = "http://192.XXX.XX.XXX:8080"
#Domoticz IDX van de water sensor (RFXMeter)
idx = 318

#Open meterstand.txt file en lees meterstand
#Als meterstand.txt niet aanwezig is maakt script bestand aan en vult de meterstand
fn = "/home/pi/domoticz/scripts/meterstand_water.txt"
if os.path.exists(fn):
    f = open(fn, "r+")
    inhoud = f.readline()
    a,b,c = inhoud.split()
    Counter = int(c)
else:
    f = open(fn, "w")
    f.write( 'meterstand = ' + repr(Counter))
    f.close()

#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 aditioneel als Pullup-Weerstand aktiveren
GPIO.setup(40, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)

#Functie  callback
#Dit is de functie die aangeroepen wordt in de interrupt
def Interrupt(channel):
    print('Callback function called!')
    time.sleep(0.05)         # need to filter out the false positive of some power fluctuation
    if GPIO.input(40) == 0:
       print('quitting event handler because this was probably a false positive')
       return
    #Teller elke interrupt uitlezen en met 0.5 liter verhogen (deler watermeter op 10 zetten)
    f = open(fn, "r+")
    inhoud = f.readline()
    a,b,c = inhoud.split()
    Counter = int(c)
    Counter = Counter + 1
    f.close()
    #Schrijf meterstand naar bestand
    f = open( fn, 'w')
    f.write( 'meterstand = ' + repr(Counter))
    f.close()
    #Send counter to domoticz JSON
    url1 = domoticz_url+'/json.htm?type=command&param=udevice&idx='+str(idx)+'&svalue='+str(Counter)
    response1 = requests.get(url1).text
    #Voor debug => print voorbeeld van de JSON aanroep en/of de counter
    print ("JSON call = "+ str(url1))
    print ("Watermeter Counter = " + str(Counter))

    #Interrupt-Event toevoegen, sensor geeft een 0 en en bij detectie een 1
#Bij detectie een 1 daarom check stijgende interrupt.
GPIO.add_event_detect(40, GPIO.RISING, callback = Interrupt, bouncetime = 200)

try:
    while True:
      time.sleep(0.2)        
except KeyboardInterrupt:
  GPIO.cleanup()
  print ("\nBye")
  

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Sunday 19 March 2023 21:13
by ssk17051980
my domoticz server it's in house.
the watermeter it's outside, in the yard.
is there any chance with an esp32 instead of the domoticz server?

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Monday 20 March 2023 9:38
by waltervl
ssk17051980 wrote: Sunday 19 March 2023 21:13 my domoticz server it's in house.
the watermeter it's outside, in the yard.
is there any chance with an esp32 instead of the domoticz server?
Yes, see viewtopic.php?p=299038#p299038

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Saturday 04 November 2023 11:32
by ssk17051980
gizmocuz wrote: Thursday 09 February 2023 8:55 This is another way to do it

https://github.com/gizmocuz/esp_proximity_sensor_mqtt

has anyone tried this method?

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Saturday 04 November 2023 12:38
by azonneveld
I have tried a number of 5V proximity sensors, but they all failed within 6 months.
Even while the sensor was working, it produced lots of false readings.

Two year ago I switched to a Line Tracking Sensor, and that one is still working fine.

I would recommend this sensor instead of a prox.

Reading data from the sensor works the same as when using a prox.

example:
https://www.amazon.nl/AZDelivery-Infrar ... B07DRCKV3X


older post about this topic

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Tuesday 07 November 2023 14:01
by gizmocuz
Could you post some more information about the line tracking method?
Where do you place it? Is there a case/holder that we can print?
I would expect false positives with this type of sensor as well as we can read on this forum

You could also modify my sketch to filter our false positives by checking the time interval between two pulses.
And if it's too fast you know it can't be right

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Sunday 19 November 2023 21:32
by azonneveld

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Posted: Sunday 21 January 2024 15:20
by azonneveld
gizmocuz wrote: Tuesday 07 November 2023 14:01 Could you post some more information about the line tracking method?
Where do you place it? Is there a case/holder that we can print?
I would expect false positives with this type of sensor as well as we can read on this forum

You could also modify my sketch to filter our false positives by checking the time interval between two pulses.
And if it's too fast you know it can't be right
Apparently my previous links are not working anymore ; :?

fyi: using the optical sensor, the system measured 500 too much on a total of 75000.
No filters applied, only the built in 250ms debounce time. (espeasy)

Would you still like to know more?