Simple possibility to measure time


I am new to node red. I searched a lot, but I gess with the wrong searchterms. :-/
I would like to have a possibility to measure the "on" time of a device.
It is switched with HTTP, I have it already in place in a flow and added e.g. a working GUI-switch which works well (displaying "on" and "off", able to switch).

now I need to measure how long it is "on" to calculate the power consumption, as I know much the device consumes exactly I only need to track the time it is switched on.

I would be able to do this with variables and timestamps, but I think this is not the first time somebody need this, so can me please point somebody which element I can use for?

Thank you in advance!

Best regards

As far as I am aware, there is no special node that will do this for you.

Most likely, the best approach would be to use a flow or global variable to track the on time. If you have multiple devices to track, I personally would make that variable an object that is keyed on a unique identifier for the device. Then you can track as many as you like (subject to memory limitations).

Once a device sends an off, you would use the on time, calculate and send on the elapsed time and delete the entry in the object. If you end up with 000's of devices, you can make the flow/global variable handling more efficient but by and large, it is likely enough to just retrieve and save the whole thing.

This may be helpful, it measures the time between messages so if you send it the On and the Off then it will tell you how long it was On. I haven't tried it but it is one of @BartButenaers so I would expect it to work fine.

have a look
measure run time

Oops, forgot the link.

thank you colin, the "interval length" I have had already found, but it looked like in my case it is only a misuse ...
thank you juntiedt I will take a look at the flow. :smiley:

I don't think that is a misuse of the node, it is exactly the sort of thing it is designed for.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.