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.

Moderators: leecollings, remb0

User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by gizmocuz »

Quality outlives Quantity!
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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.
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by waltervl »

There is a watermeter Python plugin https://github.com/akamming/domoticz-watermeter
Perhaps this is compatible with your setup.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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.
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
Benneton
Posts: 111
Joined: Thursday 08 December 2016 9:46
Target OS: Raspberry Pi / ODroid
Domoticz version:
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
azonneveld
Posts: 153
Joined: Wednesday 02 October 2019 7:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
User avatar
Copitano
Posts: 49
Joined: Friday 28 June 2019 1:26
Target OS: Raspberry Pi / ODroid
Domoticz version: 2022.2
Location: NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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")
  
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ssk17051980
Posts: 112
Joined: Thursday 08 December 2022 22:15
Target OS: Raspberry Pi / ODroid
Domoticz version: 2023.2
Location: ROMANIA
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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?
azonneveld
Posts: 153
Joined: Wednesday 02 October 2019 7:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
User avatar
gizmocuz
Posts: 2350
Joined: Thursday 11 July 2013 18:59
Target OS: Raspberry Pi / ODroid
Domoticz version: beta
Location: Top of the world
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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
Quality outlives Quantity!
azonneveld
Posts: 153
Joined: Wednesday 02 October 2019 7:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post by azonneveld »

rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
azonneveld
Posts: 153
Joined: Wednesday 02 October 2019 7:37
Target OS: Raspberry Pi / ODroid
Domoticz version: 2024.4
Location: Netherlands
Contact:

Re: Watermeter lezen met raspberry en Inductieve NPN sensor

Post 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?
rpi4 - zigbee2mqtt - roborock - espeasy - rfxcom - homewizard p1 - otgw - homebridge - surveillance station - egardia - goodwe - open weather map - wol - BBQ detection - rsync backup
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest