Water-meter Sensor, help configuring it

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

so, you’re telling me that I’ll have to learn how to copy-paste python now? :wink: I was afraid that this time will come sooner or later… :smiley:

this is where I couldn’t find any solution. I started to think that maybe the plastic transparent cover on the meter is somehow distracting the led and confuses pulse count… but even if I tried with something else [I prepared a piece of wood with reflective foil and black painting to simulate the meter ;)] it still was with the same results. or maybe me calibrating the screw wasn’t as precise as should.

omg, in the meantime you’ve found the code. THANKS!
don’t know what to do with it yet, but hoping to figure it out at the evening :wink:
do I understand it correctly, that the python script assumes the sensor is connected to RPi?

…aaaaand that’s a great edit :smiley: good thing I was still writing my answer :wink:
sure, I’ve got some other Raspberries somewhere around to test it, not sure if it will help with configuring tasmota then, but at least like you wrote - I’ll be able to check the sensor weakness maybe.

I’ll keep this topic updated in case I figure something out!

hahaha, i feel you getting to all this trouble! justto finally realize that the the sensor is china-defective :stuck_out_tongue:

Yup, it’s got vcc/gnd and the signal wire went to gpio #5 (as you see, im using setmode(GPIO.BCM) so you ll need to find a BCM gpio map to see which one is gpio5 or set the appropriate number.

BTW, why does your sensor have two signal pins? does one send on/off and the other is supposed to be connected differently?

–quick google search–

Yup, that’s it, you have it connected on the DO right?
The DO should give 0/1 and the AO (analog output) will give low values on detection and high values when nothing’s detected, according to this guy:
image

Also, scrap the “connect the sensor to the rpi” idea, the sensor has an indicator led, that could help you see if its reading the changes correctly, no?

Manually check if the led flashes once every turn of the meter?
Like on while white, off while black? then go on from there :slight_smile:

just a quick reply to confirm: yes, before mounting on the meter I was testing with the LEDs only (one shows “power is on”, second detects state) - and all is fine. LEDs are reacting way they should - it helped me to calibrate the sensor (to find the sweet spot, when sensor reacts at silver part and turnes off for black one). also: depending on sensitivity setting, keeping the signal led turned on (meaning: moving something reflective next to the sensor) makes counter to increase just a little or lots of - more sensitive setting gave me tens of counter-points when moved finger/my wooden simulator; and less sensitive setting gave me just a few points after waving the same thing with the same speed - that’s I moved to ON/OFF readouts.

the sensor LEDs on the other side are indeed an “emmiter” and “reader” so to speak.

after “few days” of delay, I had a moment to look again on my ideas and… solution was really simple, I just have to check all the readouts on meters, and enter everything into “production device”, right now tested on another wemos and looks like it’s working the way I was thinking of.

so, my sensor is connected to D1 pin on my wemos board & is configured as Switch1; then Counter1 is selected on other, unused pin [in my case: D5] - it’s just a placeholder for numbers.

then, in the tasmota’s console, I’ve entered:

switchmode1 1
counter1 <enter-initial-counter-value-here>
rule1 on switch1#state=0 do Counter1 +1 endon
rule1 5
rule1 1

after that, every sensor “blink” [which is understood as toggle: OFF->ON] increases counter1 by value of 1.
so, other way than the standard pulse-count, it counts every blink as one and not as a few or even more like before. I don’t have to save anything anywhere, as the count is preserved after esp reset.

tomorrow I’ll start “daily driver tests” with the right wemos board mounted on water meters and I’ll see if there is any miscalculation with the measured liters.

2 Likes

Good morning, seen following in this discussion because I’m interested in progress, my current situation is as follows: I have a water tank that I fill with a well, at this moment I installed a water flow sensor (FL-808) and a sensor Ultrasound built by me with a nodemcu and firmware ESPEASY I am attaching a sketch. currently I have the exact measure of the level of filling by means of ultrasound and the fall of the water but the problem that I only measure the liters per minute but I can not find the solution to have a total of liters taken. I am attaching some photos.

in the yellow circle is the flow of water (liters per minute) and it’s ok, in the red circle is water level inside the tank and it’s ok, and last in the blue circle I would create the total liters of water taken … I really hope to succeed … also thanks to your help …

I’m not using ESPEASY so I can’t help directly, but maybe my answer will give you some keywords to look for :slight_smile:
as far as I know, your flow sensor should give pulses while water flowing thru it, right? I guess, that based on that pulses the flow ratio liter per minute is counted. so looks like you just need to count and summarize all the pulses and then figure out exactly how many pulses are for a liter, and then maybe just divide number-of-pulses by liter-to-pulse-ratio?

ok, yes I initially had the number of pulses, then inside the firmware EspEasy via rule I translated the stacked in liters per minute, but the point is not the liters per minute or how many impulses we have for liters, what we have / I have to find is how to create a counter that gives us a total of water taken daily or monthly, I think in previous posts you were working on that? ie store the data collected?

yeah, my description was for the TASMOTA firmware - via web configuration of tasmota I set up the counter, and then created a rule that increments this counter if “switch” is turned on-off. first I used “pulses” but couldn’t get the needed accuracy to know how many pulses are in one liter - so I just reconfigured the signal from my sensor as “switch” and not “pulse-count” [all in tasmota config]. and because the firmware has built-in, reboot-resistant counters, I’m using that to keep the overall number of liters.
I’m guessing, that you can do similar stuff in ESPEASY, if it’s also has rules etc. as you wrote. you just need to do it “before translation” to liter per minute :slight_smile:

there’s also a second way maybe - if you can read the overall pulse count via homeassistant, you can make a sensor [or input_number field, to have the ability to manually correct it via dashboard if needed] which will show liters count on given time. then, if you’ll add this sensor/input_number field to recorder, it should remain even after rebooting HA.

I have something like that for the daily count:

sensor:
  - platform: mqtt
    name: water_meter_RAW
    state_topic: "tele/garage_watermeter/SENSOR"
    value_template: "{{ value_json['COUNTER'].C1 }}"
    qos: 1
    retain: True

input_number:
  water_today:
    name: water_today
    min: 0
    max: 999999
    step: 1
    mode: box
  total_counter_yesterday:
    name: total_counter_yesterday
    min: 0
    max: 999999
    step: 1
    mode: box

automation:
  - id: summarize_daily_usage
    alias: summarize_daily_usage
    trigger:
      - platform: time
        at: '00:00:00'
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.water_today
          value: 0
      - service: input_number.set_value
        data_template:
          entity_id: input_number.total_counter_yesterday
          value: "{{ states.sensor.water_meter_RAW.state }}"
  - id: current_daily_usage
    alias: current_daily_usage
    trigger:
      - platform: state
        entity_id: sensor.water_meter_RAW
    action:
      - service: input_number.set_value
        data_template:
          entity_id: input_number.water_today
          value: "{{ states('sensor.water_meter_RAW')|int - states('input_number.total_counter_yesterday')|int }}"

I assume that it’s not perfect, but it’s the first version that gave me what I needed, so right now I’m happy with it :wink: probably will upgrade/update it somewhere in the future, after I’ll finish other things.

2 Likes

fine thanks, I will start from your sketch to adapt it to my configuration let’s see what comes out …:wink: I will keep you updated, thanks again

Very nice, automation, ill use it when ill set up my counters again.

I also used to send a reset meter command to the tasmota fw with this curl shell command:
water_meter_reset: 'curl http://local.sonoff.ip/cm?cmnd=counter1%200'
Which you could run every night after saving your total to avoid doing the math on HA.

And im pretty sure i had figured out an equivalent mqtt command somehow but cant finnd it right now :slight_smile:

1 Like

@gojonny I hope you don’t mind a side question, how did you get your cards to look 3-dimensions?

 - type: vertical-stack
    cards:
      - type: custom:card-modder
        card:
          type: custom:gauge-card
          title: Temperatura CPU
          entity: sensor.cpu_temp
          scale: 40px
          severity:
            red: 65
            green: 0
            amber: 55
        style:
          background-repeat: no-repeat
          background-color: rgba(50,50,50,0.3)
          background-size: 100% 68px
          border-radius: 12px
          border: solid 1px rgba(100,100,100,0.3)
          box-shadow: 4px 4px rgba(0,0,0,0.4)
          color: white

each card has custom-card-modder and the style shown below

yeah, I thought about that, but to be honest - my daily usage is “just for fun”, and the total counter is more important to me, as it’s the one that my water usage invoices depend on :wink: so I’m thinking about it like about a “solid number” while daily/monthly usage is just for my “internal statistics”.

on the other hand - I could set up more counters on tasmota [up to 4 in total], so maybe will use your tip with additional daily counter set up on the same wemos board, making it independent from HA

hey use this https://github.com/arendst/Sonoff-Tasmota/wiki/PZEM004T,-Wemos-D1-Mini-and-a-1602-I2C-display for monitor Power.

How did you modified your two automatisation to integrate this shell command ? I am quiet new with HA ?