Water-meter Sensor, help configuring it

You will have to find or write a pi compatible library or read from the adruino over the serial (USB).
Alternatively just use MQTT post from the arduino, or use the arduino component

I can already read the sensor data inside HA.
What i want is to manipulate it, in order to change the unit from pulses to liters and have it showing up like the temperature and other sensors (i have a link in my OP).
Any ideas?

The arduino code sums the number of pulses in a second (pulses_in_a_second )then calculates the hourly flow in litres from:

hourly_litres = pulses_in_a_second * 60 / 7.5

I would personally use a python_script to do the timing/summing/calculation and write hourly_litres to a sensor that is displayed on the front end.

1 Like

Did you ever worked out the code? I am strubbling the same. Already have sensor data but want to create dummy sensors with the right output (liters)

To be honest, i set the project aside as it seemed to gather a heavy load of data and turned my DB huge and my HA slow.

I will come back to it after i have looked into mariaDB and template sensors, so i can better manipulate the stored presented data.

Here is a block of code from the link above that will give you an idea on how to go forward and mathematically manipulate your data:

sensor:
  - platform: template
    sensors:
      transmission_down_speed_kbps:
        friendly_name: "Transmission Down Speed"
        unit_of_measurement: 'kB/s'
        value_template: "{{ states('sensor.transmission_down_speed')|float * 1024 }}"

One small update would be that i am working on connecting the flow sensor to a nodeMCU chip which i have flashed with the ESPeasy firmware, as it is really far from my main rpi running HA.

The ESPeasy has functionality that manipulates the data before sending it through mqtt to my HA. There you can enter someting like %value%/220 which in my case turns pulses to liters and send actual liter information to HA.

I have not managed to get it to work yet but here is some info.

Thanks for your reply. To bad is has such a load on your ha unit. Do you have any idea how to interpretate and split the code here: Watermeter pulse sensor S0PCM
?

Thanks

No clue mate, due to my lack of experience and expertise, i am just looking into problems as soon as they come up.
Never had to fiddle with that sensor before :slight_smile:

Hi Krash, just an update, I’ve decided to go your route and use the EspEasy firmware instead, I have it connected and hoping to conduct some testing to calibrate the meter. As I’m guessing you mentioned %value%/220 and 220 isn’t the default correct?

Exactly what i was referring to.
No, 220 isnt a default, it’s just a number i figured out by filling water bottles :slight_smile:
Every liter was about 220-230 pulses on my sensor.
Some testing should tell you what the number you should use is.

Did you get it to work? Because i never managed to get a steady reading with it.

Having the same issue, working with the pulses seems to be giving inconsistent readings, with tasmota on the sonoff trying to use pulse timer, however cant seem to get the math working on Hass to calculate flow…

hoping some1 can shed some light on this? :exploding_head:

Maybe the sensor data can be manipulated with this new option, Filter Sensor?

Found a non invasive possible alternative, if any1’s interested i posted a question here.
Would love any input.

Hey, im back on the project again :slight_smile:
I managed to get it to work with the tasmota’d sonoff but had to do a little soldering 1st.
My waterflow sensor works with 5v in so, i had to get that from the chip by soldering a cable on the 5v pin on this picture:

Here is the final 5v out soldered:

Routed the cable that way to avoid crossing the sonoff’s power rails:

And finally cut a small nick on the case to bring the cable where i wanted it. Again, i didnt use the little missing corner of the board to avoid running the little cable over the 230VAC power lines:

So now i get an increasing pulse counter:
image

It is not really accurate but, i think that’s the flow meter’s problem, when i fill in 1 liter with small flow i get a smaller reading than when i fill it at full flow of the tap.
That’s not a big problem for me as i want to keep track of the irrigation system in my country house remotely, to check for leaks and stuff, so i dont need great accuracy.

Now heading to do the HA part, ill keep you guys posted.


Update with HA code:

sensors.yaml:

  - platform: mqtt
    name: "water_meter"
    state_topic: "tele/sonoff_water_meter/SENSOR"
    value_template: "{{ value_json.Counter1 }}"
    unit_of_measurement: "Pulses"

And using a template sensor in order to make it read liters:

  - platform: template
    sensors:
      water_meter_liters:
        friendly_name: "Water Meter in Lt"
        unit_of_measurement: 'lt'
        value_template: "{{ (states('sensor.water_meter')|int *1/225) | round(2) }}"
        #The conversion rate is a result of testing, and not very accurate.
        #The round(2) is to only get two decimals at the end of the liter count.

I also made a script that would reset the Tasmota counter to 0, for future use in an automation:
scripts.yaml:

water_meter_reset:
  sequence:
    - service: shell_command.water_meter_reset

and shell_commands.yaml:

  water_meter_reset: 'curl http://sonoffIP/cm?cmnd=counter1%200'
  #that's command "counter1 0"

Now im working on a Trend binary sensor in order to know when the water is running or not:
binary_sensors.yaml:

  - platform: trend
    sensors:
      water_meter_running:
        entity_id: sensor.water_meter
        device_class: moisture
        max_samples: 2
        sample_duration: 30

It works half good, triggers when the water is running, but wont reset to off when the water stops, i must be doing something wrong. (posted about it here)

Will post further updates when any.

4 Likes

Nice work. How do how calculator a day usage?

I haven’t figured that out yet, but I think it would need some db manipulation, set a template sensor equal to to the value of the daily consumption then save it?
Haven’t looked into it tbh.

forgive me resurrecting the old thread, but didn’t wanted to open new with the problem that is touched here :wink:

I just built a water meter with ESP (wemos) and two TCRT5000 (separate counters for house water and garden water) sensors. wemos flashed with latest tasmota. calibrated the TCRT5000 to properly react for reflective/non-reflective part of the watermeters’ rotating thingy, but still thinking how to make the readings more useable…

right now, depending on “the speed of flow” pulse count shows counts that vary a lot… a 3-digit reading when tap is fully opened and water flows like from fireman’s hose, and 5-digit output when slowly fulling up the bucket… so during my testing 1 liter equals to 552 (fast), or to 5297 (middle speed), or to 14616 (slow as hell)… tried to think out the solution like dividing it with time, or some constant-number but nothing worth trying pops up in my head.

did you managed to bite this problem somehow?
right now those readings are useable only as boolean - “water is opened” or “water is closed”, and of course that makes no sense for me :wink:

ok, so I’m going to make a little chit-chat with myself :wink:

I think I’ve found kinda simple solution, but still struggling to get it work [I need to read more on tasmota’s commands and rules]. the plan is:

  1. set the TCRT5000 sensors as switches
  2. set two additional counters assigned to pins that are not used in wemos
  3. set up tasmota rules, with the trigger “sensor state = OFF” and action “increase counter” [of course twice, with corresponding sensor and counter numbers], and publish the counters via MQTT

right now I’m stuck on the rule construction [but just started it, and while I found out about rules “5 minutes ago”, I hope that it’s just a matter of reading the guide/tutorial/wiki etc.]. if anyone wants to contribute or point me to better direction - you’re welcome to do so!

Hey there,

So let me get this straight, your water meter has some rotating thingy that reflects light and the TCRT5000 counts these pulses. This sounds very interesting. Here are my thoughts, and sorry if im missing something, i might be completely wrong:

It sounds to me, though, like it is not very accurate like it has some maximum pulses per given time that it can read. I mean, the more time the water flows, the more this thing registers pulses. Seemingly unrelated to the actual pulses. Try to test it for a specific amount of time, with different water flows like, 20 sec with small/medium/max flow and see the results.
As i said above i had some inconsistencies while trying to measure the number of pulses per liter it was like 221-228 or something (and completely different identical counter that i tried on another project, around 340).
Your value differentiation makes me think that something is not working correctly.

On the tasmota firmware, i dont quite get what you are trying to do. Why the workaround with switches and counters and not directly counter?

hi!

check out this photo - the clock-dial-looking disc in the right part of the meter is the silver-metal rotating-thing I was talking about :slight_smile: the black part blocks light from TCRT5000.

about the pulses used in the “counter” setting.
I was able to calibrate the sensor - as you can see, it has a little screw on it - to react appropriately to the spinning disc, but even then it’s reaction is [as far as I’ve noticed] based not only on “light interruption” but also on “time of the interruption/reflection”. I know that there’re debounce settings in tasmota, which might help a little, but unfortunately I think that I cannot bypass this incosistency while metering. not with my knowledge at least [I’m mostly a copy-paste programmer ;)]. if it would be something like yours 221-228 pulses, I’d be happy to use it, it would be almost perfect to estimate.

now about my “workaround”.
I figured it out, that if “counter” combines pulse and time; while the “switch” uses only two states - then maybe it’s the way to go. sure, with faster flow the ON/OFF are not very “real time” but I noticed, that somehow they are queued and seems like tasmota shows them all, but with the slight delay [understandable for me]. I know, that I could use HomeAssistant to count these ON/OFFS and make a counter inside HA, but that would double the delay IMO: sensor->tasmota->mqtt->homeassistant. too many places that could fail.
if I combine it on the tasmota side only I’m not only cutting off those additional parts from the equation, but also I have an opportunity to save the counter into “ESP’s memory” to keep it safe in case of some network/power issues [well, I mean: I’m wondering theorethically, something similar popped up somewhere on the tasmota website].

of course: I can be soooo wrong with my plan, but right now it’s all I’ve got :wink:
today after work I’ll probably start to read more about tasmota rules, so I could build a proper one and test my theory in real world. I am aware, that this method could be also very buggy or it would introduce couple of other problems/delays/inconsistencies - but like I wrote - it’s all that my partial knowledge could cook right now :slight_smile:

Got it, mines are the same.

Me too :stuck_out_tongue:

I don’t know about this, i haven’t noticed this with my counters (the principal is the same as the counter i use is also sending pulses, which the tasmota is adding up).

To be honest, i started messing with the pulse counter before i got into the tasmota/home assistant game. First time i set it up i had a python script (i think) that would add the pulses. Ill see if i can find that script somewhere in my back ups, maybe you can copy/paste it and it can help you figure it out what exactly is going on.

edit1: i mean, the first thing you should make sure is that one turn of the meter is registered as one pulse on the sensor. Else everything else after that will fail (unless you just want to monitor on/off and dont care about the rate/consumption)

edit2;
Found the block of code, you ll have to change your gpio number and confirm the naming, also you ll need to see if it’s a pull_up or pull_dn.
Hope you know what to do with this, as i’ve used it about a year a go and cant remember how to help you if needed :stuck_out_tongue:

#!/usr/bin/env python

import RPi.GPIO as GPIO
import time, sys

FLOW_SENSOR = 5

GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_UP)

global count
count = 0
previous = 0

def countPulse(channel):
   global count
   count = count+1
   # print (count)

GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING, callback=countPulse)

while True:
    try:
        time.sleep(0.05)
        if (count > previous):
          print(count)
          previous = count
    except KeyboardInterrupt:
        print ('\ncaught keyboard interrupt!, bye')
        GPIO.cleanup()
        sys.exit()

edit3:
Wait, dont bother with the python mess… can you hook up the counter directly on the pi?
At least for troubleshooting.
If so, you can use a Raspberry Pi GPIO Binary Sensor and set up the sensor directly on the HA bypassing the tasmota.
I think that would give you some insight as to how the sensor is registering ons and offs by avoiding any tasmota delays.

Sorry i might just be mumbling and getting you into worst trouble :stuck_out_tongue: someone with more experience should step in and stop me :smiley:

1 Like