What happens if I restart HA and Node-Red is waiting?

As the title, what happens when the system reboots (i.e. due to update, changing config etc?) and my Node-Red is mid flow?
I’m assuming it just cancels and does nothing?

e.g.

I’d like to try and avoid this, but I’m a little unsure the best way to solve this

Is there a way to trigger state changes if restart is actioned (i.e. prior to the actual restart?), tho that could get complex
Or some way to prevent (or warn) on restarts if a flow is in progress?

Alternatively, if I went for fixed times as triggers then I guess then I guess the flow gets much more complex as the times need breaking out. Also if I happen to be restarting at that time, same issue…

Sure I’m not the first to come across this conundrum, but with the price of energy at the moment I definitely don’t want my towel rails over-running!

Thanks :slight_smile:

Yes it will just stop.

You can use the same method as we use in HA automations to set a datetime helper and trigger on this time.
That is what I can think of right now.

Hmm… is this a reasonable way to do it?

image

TBH, if I’m doing that I may as well just break out the wait’s into time triggers anyway (although harder to read)

You could also do something like this:

So home assistant start event triggers and if time is in the ranges and they are on call service.

1 Like

So I just tried this (pumping a notification to me to test) and it didn’t seem to work
image

The notification definitely works as tried a manual trigger, but restrating HA didn’t kick off the action… have I done something wrong

You can’t listen for that event in NR. When HA restarts it’s API goes down which is how NR receives events. NR has to wait until HA has fully finished restarting, brought it’s API back up and then allowed clients to connect again before it can reconnect. And until then all it can do is poll asking if it’s online again. By the time all that has finished the normal HA start event has already been fired and NR missed it.

There is an NR internal event though. When NR’s websocket client does disconnect and reconnect it fires an “event”. It’s not a real HA event since it’s only in NR but you can listen for it with the events: all node. It fires an event of type home_assistant_client:disconnected event on disconnect and an event of type home_assistant_client:ready and home_assistant_client:running on reconnect (not sure the difference).

I used to listen for these and treat them as HA startup since that was mainly when they fired. They do also fire on NR restart but that was far less common. Although I should note if you want to do this you must change the deploy mode to anything other then “full” otherwise it will fire this event on every deploy
Screen Shot 2022-08-17 at 10.02.27 AM

Another simpler option is just to create an HA automation that runs on HA start and fires a custom event like my_ha_started after a 10 second delay or so. Something long enough to be sure NR reconnected.

1 Like

Ah thanks for this. I end up restarting node red a lot (since it doesn’t pick up name changes etc until it’s been done) so that may not be ideal, but useful insight nonetheless

This might be the way to go I think…

I was wondering on whether to use a HA automation, but is there a way to check state of something going on in Node Red from there?

State meaning what flows are running? No. I’m not even sure it’s possible to do that from NR let alone HA. But you can certainly make sensors during your flows and then look at them from HA using the entity node

1 Like