Noob Here- Node Red Needs to send command twice to "wake up" connections?

So this only happens with node red command. Alexa and mobile app command seems to work fine.

For example, if I want to turn on the light. The first time command is sent. It gives an error message such as this.

“Call-Service attempted without connection to server.”

or

“Entity could not be found in cache for entity_id: Sensor XYZ”

If i send in the same command via Inject Node.

It magically works for a while. It almost seems like connections goes to sleep and needs to be woken up.

I would greatly appreciate any solutions here.

Edit - Just to note. I am running Node-Red as add-ons on HA CORE 2022.7.5 and HA OS 8.2

We need to know more about the device, integration and the sequence you are using.

I would guess you have your deploy method in NR set to Full

image

So every time you deploy NR has to reconnect HA. This is not an instant process so if you have any flows that run on the startup of NR. They are running before NR has connected to HA. Hence the two errors you’re seeing.

I would recommend changing your deploy to Modified Nodes and then NR won’t drop the connected to HA every time you deploy.

1 Like

Node Red for HA runs alongside HA as an entirely separate program, and it communicates back and forth using websocket and API calls. All of the HA nodes require a connection to a configuration node used to define the server connection back to HA.

Yes, if the connection is not being used, it can ‘go to sleep’. This stuff is all new to me, but I have found that API calls to quiescent servers can timeout while the server is getting its act together. I have seen both messages, but not very often. I have quite a few active Node Red flows running many sequences at regular (less than 1 minute) intervals 24/7, so usually there is always something going on and I only have connection problems when starting up HA/NR (but not for very long) or immediately after having added a new entity and likewise for a short time NR can’t find it. I always deploy everything (it works, why change) and have never found that to cause any delay that I have noticed.

Not guaranteed to address your problem, but do check your HA server node settings.

In the right hand info window menu select ‘configuration nodes’
Look for a/the server node for Home Assistant.
Double click to edit, and check the settings.

If you are using NR as an add-on, the settings will be just ‘I use the HA add-on’. The rest -

Delay connection attempts - clearly not something we want on!

Cache autocomplete results - NR loads and holds all the HR entities in a Global Variable and pulls in names etc to enable an ‘auto complete’ feature when typing in names in HA nodes. To speed things up and reduce load on the API calls to HA this information can be cached, but as is often the case caching can cause lookups to fail, so I run with this off.

Heartbeat - I do not use this, but according to the documentation this sends a ping (at defined intervals) and waits for a pong back, and will reconnect to HA if not received. This may be a way forward to keep the connection alive and more responsive when required.

1 Like

That looks promising!!

Will turn it on and report back if that fixes the issue.

Thank you!!