Measure the Pulse duration of input Signal

Hello to Everybody,

I'm new in the Rode red community .

My setup is a raspberry pi 3 B+ with the automation hat shield.

Im trying to find a way to measure the pulse duration of an input signal.

I would like to know how many time an input stay High and to pass this data or directly to a dashboard.

Could anyone give me a help?

Regards

Andreas

Welcome to the forum! What lengths of time do you want to measure? Seconds, minutes etc.

Hey ghayne,

I would like to measure from seconds up to hours.

this flow in the cookbook shows how to store a value to use in a different flow
So you could save the time when your signal went high/low
and then work out the time difference when it changes

https://cookbook.nodered.org/basic/route-on-context

Thank you ukmoose for your hint,

I have already checked this the important think is that I need a solution with real time results I mean when the input goes high to start a time counter.

Don't forget that Node-Red is not a "Real time" system, the shorter the periods you want to measure the more inaccurate the results will be. If you want to measure short periods accurately you would be better off using an Arduino or ESP8266 dedicated to measuring the times and pass the results to node red for display and/or evaluation.

1 Like

not I don't want to measure with accuracy the seconds, this input indicate the working time of a machine.

you can detect when an input goes high. Getting the current time in a javascript function is a simple bit of javascript. Google will be your friend
then store that as the context valie

The node node-red-contrib-interval-length will measure the time between messages. Feed the state change messages to it and each time it switches it will tell you how long since it last changed.

@colin,
Indeed I developed that node-red-contrib-interval-length node for this kind of use cases. Thanks for the advertisement :wink:

I made a little flow for you to get you on the path of thinking how the things work here in Node-RED.
flows.json (3.0 KB)
Explore it and ask a lot of questions. :slight_smile:

Hey hotNipi,

Your flow help me a lot.

the thing is that I want to have in a dashboard a timer that will start to count the after the input goes high. and not to wait until the input goes low and calculate the difference.

has anyone any idea about that?

Question should be have you any idea? :slight_smile:
I definitely have some ideas but I'd like to follow yours. Because of you are doing it and when it is ready, it will be your solution. The best one in the world. And we are happy to help you to achieve this.
So start experiments and when you are stuck then you have specific questions about it. And we are happy to help on such.

To not let you empty handed right now, here is something you can think about to get the things moving again - In addition what you already have (a bit modifications of course needed) you should do something like this:

The node-red-contrib-interval-length node mentioned earlier (thanks @BartButenaers) can be made to do this, but it needs a bit of extra logic to work as a start/stop timer. This flow could get you started, although you might want to delay the reset message when stopping. One of the debug nodes is just to show the start and stop messages, and the other would be replaced by your dashboard node(s). The flow should work for multiple timers (topics), but I haven't checked.

[{"id":"2dd7f10a.e9a46e","type":"interval-length","z":"7de47013.a039d","format":"human","bytopic":false,"minimum":"","maximum":"","window":"","timeout":false,"msgTimeout":"2","minimumunit":"msecs","maximumunit":"msecs","windowunit":"msecs","msgTimeoutUnit":"secs","reset":true,"startup":false,"msgField":"payload","timestampField":"timestamp","repeatTimeout":true,"name":"","x":480,"y":400,"wires":[["df192dd9.00dd2"],["df192dd9.00dd2"]]},{"id":"85f43934.99e8d8","type":"inject","z":"7de47013.a039d","name":"","topic":"","payload":"start","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":400,"wires":[["bbdf10aa.c2cb7"]]},{"id":"df192dd9.00dd2","type":"debug","z":"7de47013.a039d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":670,"y":400,"wires":[]},{"id":"dc1a9f5.756276","type":"inject","z":"7de47013.a039d","name":"","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":110,"y":460,"wires":[["6ceba346.52589c","2dd7f10a.e9a46e"]]},{"id":"6ceba346.52589c","type":"change","z":"7de47013.a039d","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":460,"wires":[["bbdf10aa.c2cb7"]]},{"id":"bbdf10aa.c2cb7","type":"rbe","z":"7de47013.a039d","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":270,"y":400,"wires":[["2dd7f10a.e9a46e","bcbca1c9.5b84b8"]]},{"id":"bcbca1c9.5b84b8","type":"debug","z":"7de47013.a039d","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","x":470,"y":360,"wires":[]}]