I am using a Raspberry Pi and node red as a monitor for my motorhome. I have added a cheap flow sensor to monitor water use. Originally I tried to use a GPIO node to count the pulses but the results are inconsistent. I assumed this is because Node Red can not catch all the pulses. I have seen other threads suggesting running a Python script. I have limited knowledge of Node Red and knew nothing about Python until this week but I have managed to get a script running.
When the water pump starts, a GPIO pin goes high and sends "sudo python flowmeter.py" command through an Exec node. (not used this before and know little about it) . The script runs counting the pulses until the the pump turns off. To avoid quick on off changes like filling a kettle, stopping then adding a little more, the script runs for another 10 seconds to see if the pump starts again. Once the delay loop finishes, an MQTT message is sent to Node Red and the script stops. My questions are:
Is it better running the script permanently but paused with a wait for GPIO high statement rather than starting and stopping it each time. Script probably only runs once an hour.
Can I export a variable back to node red without having to use MQTT.