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?
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!
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
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.
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