Multiple Timers

Hi everybody!
It's my 1st time in the Forum and my 1st project too.
I would like to have multiple timers available which will start according to a change state according to inputs. Therefore I could have simultaneously 1, 2 or N (max. 78) timers counting the seconds according to such inputs are ON.

Basically are timers counting the amount of time that the related input is ON (number of inputs are variable).

Do you have any idea how I could do it?

Welcome!

Do you need the timer to be displayed interactively? Or do you just need the on time to be delivered after the output goes OFF? This will impact the approach you might take.

Simplest is if you just need the output at the end because all you need to do is temporarily store the start date/time and then subtract that from the end date/time when the state changes.

Having an interactive timer showing would be slightly more involved.

In terms of having multiple. That is a matter of being able to differentiate between the inputs. Typically, the msg.topic is used to differentiate inputs but you don't have to use that. You would record the start date/time against the topic or whatever other identifier you are using.

Thank you! :slight_smile:

The timer (or timers) must be displayed interactively.
In past I build a dashboard in Processing (Java) showing basically the timers which were in the state ON. Now, I wanna upgrade with more features and put it accessible via HTML 5 so, I chose to start with Node-red.

What would you recommend? Record the start time, and then subtract it every second in order to have the the passed time?

I think that you could probably optimise slightly further than that - but in essence yes.

But you will do it in the client rather than at the server. So the server records the start date/time and passes it to your dashboard which triggers the counter to start.

The server will also send through the stop event so that the client stops the counter.

In your Dashboard, you will need to use a Dashboard Template (unless you are using my uibuilder node of course! :wink: ) to load some custom processing.

You can use a setInterval function to update your counter so you can control how often you update but I would think anything less than once per second probably doesn't make much sense.

In this way, you've distributed the processing load out to the clients rather than trying to handle everything in Node-RED on the server.

Sorry, What do you mean?
I was experimenting the function setInterval, setTimeout and so one and I did not need the "Template node".

JavaScript for me is very difficult! :confused:

So you are using a function node which runs code on the server.

But you don't need to make the server do a load of work when only a person needs to see the output.

Because the Admin UI is not meant to be used as a dashboard, there are several nodes that let you build an end-user interface and presents that as web pages to a users client browser. The easiest one to start with is called simply "Dashboard". It has a node called "Dashboard Template" that lets you create custom code including script.

So rather than trying to handle everything in function nodes - which results in you having lots of data to pass round (1 msg per second per timer), by only passing the data I mention, you can do the calculations and display purely in the users browser.

In your case, when you have a dashboard in Processing, as long as you can get Node-RED to pass data to your Processing dashboard, the principles would be the same, you would be sending a minimal amount of data through to Processing which would then be used in a suitable timer to display the information.

@TotallyInformation I think that I understand what you meant.
I will do and, if you don't mind, later I can send my code and you could do an evo. If not, no problem at all. I have appreciated a lot your support.

Thank you!

1 Like