Trying to automate the start (wol) of my dell r720 server (and it works) then after a delay restart HAOS
I built a simple flow in node red
at time wol server delay 7 seconds restart Home assistant
in node red my flow contains a node that is to restart Home assistant. On a newly developed flow the restart operation works fine. However as HA restarts the node red node to restart HA shows an error.
if i trye to restart the flow a second time the server starts however it does not reboot
Note: HAOS is installed on a different laptop
the node red node has
name
server name : |Home assistant (i only have this server installed in node red)
action:homeassistant.restart
data: on
merge: blank
queue: do not queue messages
Error: Unrecognized error: {“type”:“result”,“success”:false,“error”:{“code”:3,“message”:“Connection lost”}} at getErrorData (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/common/errors/inputErrorHandler.js:65:13) at inputErrorHandler (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/common/errors/inputErrorHandler.js:73:38) at ActionController._InputOutputController_preOnInput (/config/node_modules/node-red-contrib-home-assistant-websocket/dist/common/controllers/InputOutputController.js:69:51) at processTicksAndRejections (node:internal/process/task_queues:105:5)
Node-RED HA Nodes communicate with Home Assistant via a WebSocket. The Action node sends a message to HA to run a given action. All HA Actions now return a response, either returned data value or just to say the action has completed.
When the action is ‘homeassistant.restart’ the action restarts Home Assistant, and the first thing HA does is a clean shutdown, which terminates all WebSockets, including the one between Node-RED and HA.
Therefore, the Action node is waiting for a reply to say the action has completed, and the WebSocket connection gets cut, so the node issues an error message to say that the connection has closed (before it saw a reply).
I have found a way to get around this.
in Home Assistant, using the Helper, create a Button (input_button) and call it “Restart HA”
in Home Assistant, create a new Automation, called “Restart HA”.
add an Entity-State as trigger, using the ‘input_button.restart_ha’ you just created
add an Action ‘homeassistant.restart’
Now, when the button “Restart HA” is pressed, the automation will trigger and restart HA.
In Node-RED you can now use the Action “input_button.press” and the target “input_button.restart_ha”.
Calling this action just presses a button, which provides a return before the HA automation triggers to restart HA.
Home Assistant restarts, and no error message seen.