Persist timer/delay node state between Node-RED restarts/reboots

Hi,

I'm using Node-RED for my DIY home automation stuff and it has been working great. I'm using the built-in delay nodes for some stuff, e.g. to turn off certain lights automatically after no movement has been detected for a while, but I face a minor problem with it (and Nore-RED persistence in general).

If I reboot my NR container (as my whole infra is organized via Docker Compose), then all these timers/delay nodes lose their active state and my home can basically get into an invalid/inconsistent state, where some lights are physically on but NR does not know about them and since the timers are not running, it will not turn them off until some related flow is triggered again by movement or anything.

I changed my context store to write that to the filesystem, but unfortunately that setting does not seem to affect timers/delay nodes. (Also the node statuses displayed in the editor are lost upon reboot too.)

This is not a major issue and I can live with it, but it would be nice if NR handled graceful shutdowns better and could write these in-memory states to the disk as well, and continue where it left off after a restart.

In the meantime I plan to check this node-red-contrib-stoptimer-varidelay node as suggested elsewhere on this forum, but it would be really nice if the built-in delay node also supported this feature!

Thanks!

1 Like

I managed to replace every built-in delay node in my flows with this node-red-contrib-stoptimer-varidelay type and it is working well!

The only thing you need to do is to enable both options for each node: "Resume timer on deploy/restart" and "Ignore incoming _timerpass". The latter is important if you are chaining delays (which I did, as they are needed for state machines with scheduled automatic transitions).

Also if you want to cancel a running delay, instead of the original one, like this:

return {
    reset: true
};

You need to send a message like this:

return {
    payload: 'stop'
};

to the node. (I just create these custom payloads with the function node.)

With these changes basically they behave the same, but this solution survives NR reboots!

1 Like

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