Node Red Integration - how to avoid "NoConnectionError: No connection to Home Assistant"

Hi All
I am getting up to speed on integration node red with home assistant and am currently struggling to perform actions when my node red flow starts. I keep getting the “NoConnectionError: No connection to Home Assistant” error.

I am sure that I could fix this just by modifying when the inject node pushes a messages into the flow but there must be an event or some other message that I can use to start my flows that tells me when home assistant has booted and is available?

Thanks

Your question is vague. What is your experience with Node Red? Where do you see this error?
Could the Current State node help?
Did you know that you can set a delay in the inject node?

Yes I am aware, that’s what I meant by:

I see this error on any (so it seems at least) node from HA that I try to use immediately when the flow starts. If I delay the inject node by 10 seconds I do not get the error.

I am trying to use the current state node to query the state when the flow starts. It needs an input message though - that’s what my inject node is pushing a message into but at flow boot I get the error.

If I read this correctly (I have not tried it), could you check the state of an entity to see if it is in a “Connecting” state?

Thanks for the reply but I think that is just referring to the state of the node in node-red. It shows a little cicrcle and “connecting” under it. I don’t think that this is accessible within a flow to trigger a node.

Could you use the Status node to trigger the state change?

I use a loop function to check if the NR is connected to the HA, maybe it will help you

if (global.get("homeassistant.homeAssistant.isConnected") == true) {
    msg.ha_connected = true;
    flow.set("ha_connected", true)
    return msg;
} else {

    flow.set("ha_connected", false)
    msg.ha_connected = false;
    return msg;

}

I would avoid using a “hard/infinite loop” to check any status because there are more efficient and safe ways to do this. If a state change can’t be detected using an event, trigger, or status node, why not just wait on homeassistant.homeAssistant.isConnected == true using the “wait until” node?

1 Like

I can test your solution, but in my case this loop only runs on nr startup

It appears that an event is fired when HA is ready, so I have a set of nodes that listens for a home_assistant_client events, and then if the payload is services_loaded, HA and Node-RED are ready to go. I use the nodes below and just have a switch on the payload, though I don’t do anything with the switch. It then goes to a link out and I use a link in for other nodes that need to know when HA is ready.

[{"id":"f44c410e38cbeeea","type":"switch","z":"a42ea764.b87b98","name":"State","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"connecting","vt":"str"},{"t":"eq","v":"connected","vt":"str"},{"t":"eq","v":"states_loaded","vt":"str"},{"t":"eq","v":"services_loaded","vt":"str"},{"t":"eq","v":"disconnected","vt":"str"},{"t":"eq","v":"running","vt":"str"}],"checkall":"true","repair":false,"outputs":6,"x":373,"y":798,"wires":[[],[],[],["5f38473fcb6ee383"],[],[]]},{"id":"d1e9d73ad671b600","type":"server-events","z":"a42ea764.b87b98","name":"","server":"d83da4b3.5bea38","version":2,"eventType":"home_assistant_client","exposeToHomeAssistant":false,"eventData":"","haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"waitForRunning":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"eventData"}],"x":163,"y":798,"wires":[["f44c410e38cbeeea"]]},{"id":"5f38473fcb6ee383","type":"link out","z":"a42ea764.b87b98","name":"HA Ready","mode":"link","links":["062976db5a737458","16754f0e173efca7","1b2fc147088746fb","2ab41a6a39456aba","3e8003d44c9a1412","9253783814e839f3","a723366d6c7306ff","dfb0b21903ffee14","e3d3f4ee9c08816a","eeea041ba45d426e","5738416c557ce9a6","68c1f5a84e5d5beb"],"x":563,"y":798,"wires":[],"l":true},{"id":"d83da4b3.5bea38","type":"server","name":"Home Assistant","version":5,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":30,"areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]
5 Likes

Brilliant. Just what I was looking for. Many thanks.

Please mark post as solved

I did try to do this but obviously failed the idiot test and couldn’t see how… If you enlighten the idiot then I’ll do it!
Thanks

yup, looked for a tick. Looks like it’s probably not enabled for this forum

I do the same for the past year or so, but have been keying off of “ready” instead of “services_loaded”.

I seem to recall looking for something that spelled out what the different events mean, but didn’t have luck at the time. Anyone know what the difference is?

I did not find any documentation (yet) but the home_assistant_client output is:

image

My guess is “states_loaded” and “services_loaded” correspond to the Node-Red context data readiness.

image

Not sure what “running” is but “ready” is the final state.

https://zachowj.github.io/node-red-contrib-home-assistant-websocket/node/events-all.html#client-events

Thank you sir. Just found it in github where you added it in the code.

I had this issue, and I put a “wait until” node in that checks the state of sensor.time making sure that it is “not in” “unavailable,unkown”. Job done, no more error, and in my case, my retained MQTT message sensors are correct.

When I deploy in NodeRED

… and about 5-10 seconds later