Send Pulse Counter Value immediately to MQTT

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
coalado
Normal user
Posts: 2
Joined: 11 Feb 2020, 21:00

Send Pulse Counter Value immediately to MQTT

#1 Post by coalado » 11 Feb 2020, 21:06

I'm running a TCRT5000 sensor as Generic Pulse Counter Device.

I known problem with this sensor is, that it bounces on every edge and thus the falling/raising edge option does not work.

I would like to solve this issue in software. To do this, I need to send every pulse and it's time to a mqtt broker - without any interval.

I tried this with Rules without success. Can anybody give me a hint on how to do this?
Thanks


My Rule:

Code: Select all

on stromzaehler#Count>=1
 Publish %sysname%/Counter,[stromzaehler#Count]
endon
I have a single Controller (MQTT) that works fine if I enable "Send to controller" in the stromzaehler device

User avatar
grovkillen
Core team member
Posts: 3607
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: Send Pulse Counter Value immediately to MQTT

#2 Post by grovkillen » 11 Feb 2020, 22:04

Code: Select all

on stromzaehler#Count do
If [stromzaehler#Count]>=1
 Publish %sysname%/Counter,[stromzaehler#Count]
 EndIf
endon
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

GravityRZ
Normal user
Posts: 107
Joined: 23 Dec 2019, 21:24

Re: Send Pulse Counter Value immediately to MQTT

#3 Post by GravityRZ » 12 Feb 2020, 16:20

i would do an extra check on the time to skip that bounce

first on the pulsecounter device deselect send to controller and put interval to 1 second
Then you need to know what your fastest good pulse is going to be
eg if your fastest pulse is 2000ms then do a test that the pulse received is a good pulse a bounce will probably be faster)
to be save do acheck on anything slower then 1500

i did this with my watermeter and sofar no missing pulses or bounces/jitters
on stromzaehler#Count do
If [stromzaehler#Count]>0 and [stromzaehler#Time]>1500 //only send if there is a pulse and it is no bounce/jitter
Publish %sysname%/Counter,[stromzaehler#Count] //publish counter value
Publish %sysname%/CounterTime,[stromzaehler#Time] //publish time between pulses to avoid jitter or false pulses
EndIf
endon

i use this to send to domoticz in case you use domoticz as well (idx=idx of counter device in domoticz)
Publish domoticz/in,'{"idx":337,"nvalue":0,"svalue":"1"}'

coalado
Normal user
Posts: 2
Joined: 11 Feb 2020, 21:00

Re: Send Pulse Counter Value immediately to MQTT

#4 Post by coalado » 12 Feb 2020, 17:58

My findings so far:
@GravityRZ
The Count Event comes before the time event. If you listen to the Count event, the time value is outdated. It might be better to listen on the Time Event.

Unfortunately, I only get an event if the interval condition of the device triggers. If I set Data Aquisition Interval to 60 Seconds, I get an Event every 60 Seconds, and not every time the value changes.

This makes the Rules kind of useless for my use case.

I solved the debounce/Mode Type/Edge issues by using a Schmitt trigger in hardware - so at least this issue is solved.

But I still cannot send the Impuls immediately in time

GravityRZ
Normal user
Posts: 107
Joined: 23 Dec 2019, 21:24

Re: Send Pulse Counter Value immediately to MQTT

#5 Post by GravityRZ » 12 Feb 2020, 20:21

ok but if you set the interval to 1 second you get at least 1 trigger per second.
this means that if the value changes within that second it is send. if it changes more times in 1 second then indeed it does not work.

i also wanted the device to send a pulse whenever a change is received instead of regular intervals.
lucky for me the fastest waterflow in my home is 25 liters/minute which means every 2.4 seconds so probing every second is enough for me.

regarding the stromzaehler#Time
this is the time between pulses

so first pulse :time is probably very low
second pulse:time is the time between the 2 pulses

nice that you used a schmitt trigger in the hardware. i was about to do the same when i figured out that for me i could use the time value.

maybee they will change the pulsecounter plugin so it can detect pulses in realtime without having to use an interval.
interval for send to contrlller makes sense but not if you want to use rules

Post Reply

Who is online

Users browsing this forum: No registered users and 13 guests