Maybe there is some DNS or DHCP issue on the host? You can try to bash into the node red container - assuming your container name is node-red
docker exec -it node-red bash
Then assuming your IP is still 192.168.2.60 type
ping 192.168.2.60
The ping should work and you should get bytes returned. Ctrl C will stop the ping, typing exit will get out of the bash session. If the ping doesn’t work there is some networking issue within the host or the network.
pinging 192.168.2.60 from within the container works:
bash-5.0$ ping 192.168.2.60
PING 192.168.2.60 (192.168.2.60) 56(84) bytes of data.
64 bytes from 192.168.2.60: icmp_seq=1 ttl=64 time=0.094 ms
64 bytes from 192.168.2.60: icmp_seq=2 ttl=64 time=0.153 ms
64 bytes from 192.168.2.60: icmp_seq=3 ttl=64 time=0.143 ms
64 bytes from 192.168.2.60: icmp_seq=4 ttl=64 time=0.151 ms
64 bytes from 192.168.2.60: icmp_seq=5 ttl=64 time=0.159 ms
64 bytes from 192.168.2.60: icmp_seq=6 ttl=64 time=0.138 ms
64 bytes from 192.168.2.60: icmp_seq=7 ttl=64 time=0.119 ms
64 bytes from 192.168.2.60: icmp_seq=8 ttl=64 time=0.112 ms
64 bytes from 192.168.2.60: icmp_seq=9 ttl=64 time=0.145 ms
^C
--- 192.168.2.60 ping statistics ---
9 packets transmitted, 9 received, 0% packet loss, time 8185ms
rtt min/avg/max/mdev = 0.094/0.134/0.159/0.020 ms
bash-5.0$
Here is my Node-RED log (from portainer):
> [email protected] start /usr/src/node-red
> node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
28 Oct 20:41:02 - [info]
Welcome to Node-RED
===================
28 Oct 20:41:02 - [info] Node-RED version: v2.0.6
28 Oct 20:41:02 - [info] Node.js version: v14.17.6
28 Oct 20:41:02 - [info] Linux 5.11.0-38-generic x64 LE
28 Oct 20:41:02 - [info] Loading palette nodes
28 Oct 20:41:03 - [info] Settings file : /data/settings.js
28 Oct 20:41:03 - [info] Context store : 'default' [module=memory]
28 Oct 20:41:03 - [info] User directory : /data
28 Oct 20:41:03 - [warn] Projects disabled : editorTheme.projects.enabled=false
28 Oct 20:41:03 - [info] Flows file : /data/flows.json
28 Oct 20:41:03 - [info] Server now running at http://127.0.0.1:1880/
28 Oct 20:41:03 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
28 Oct 20:41:03 - [info] Starting flows
28 Oct 20:41:03 - [info] Started flows
28 Oct 20:42:58 - [info] Stopping flows
28 Oct 20:42:58 - [info] Stopped flows
28 Oct 20:42:58 - [info] Starting flows
28 Oct 20:42:58 - [info] Started flows
28 Oct 20:42:58 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
28 Oct 20:45:13 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
28 Oct 20:47:28 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
28 Oct 20:49:43 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
So I guess for some reason Home Assistant is refusing the connection request ? I regenerated a new long-lived access token but that didn’t help…
I see nothing in the Home Assistant logs…
It’s definitely not connecting, not sure if Home-assistant is refusing the connection or if the request just doesn’t leave the Node red container. Do you have other Node red palettes/flows that connect to anything else on the local network? If you use mqtt try to see if you can at least get that to work from Node Red. This will at least let you know if there’s a problem with Node red or Home-assistant.
Do you have any funny http settings in Home Assistant that are interfering? Is Home Assistant behind a proxy or firewall that is blocking the local network? Check ip banning to see if the local ip is banned.
Make sure you spell out the whole ip of the machine in the base url of the server configuration- ie all the numbers http://192.168.2.60:8123
You would think “localhost” would work since it’s on the same machine, but localhost will just loop back into the docker container, and never connect to Home Assistant which runs outside of the Node red container.
I’m definitely not using localhost. The screenshot was just to explain that when I click the search icon on the right, it doesn’t pick up the right URL of my HA instance… Which now makes me suspect that somehow Node-RED does not access the network…
FWIW, I’m running these two docker containers on a NUC with also other containers running Pihole, Samba, Eclipse Mosquitto, ZwaveJS2MQTT, Portainer. All running happily
As a last resort, you can try running Node red in host networking mode too. It just leaves it a little more “open” to the network so make sure it’s secured and requires auth to access the editor.
Replace the port part of your docker compose with network_mode: host
This would then make localhost:8123 work and bypass any network issues docker might be creating.
Recreating 95bf883801cc_nodered ... done
Attaching to nodered
nodered |
nodered | > [email protected] start /usr/src/node-red
nodered | > node $NODE_OPTIONS node_modules/node-red/red.js $FLOWS "--userDir" "/data"
nodered |
nodered | 28 Oct 23:23:59 - [info]
nodered |
nodered | Welcome to Node-RED
nodered | ===================
nodered |
nodered | 28 Oct 23:23:59 - [info] Node-RED version: v2.0.6
nodered | 28 Oct 23:23:59 - [info] Node.js version: v14.17.6
nodered | 28 Oct 23:23:59 - [info] Linux 5.11.0-38-generic x64 LE
nodered | 28 Oct 23:24:00 - [info] Loading palette nodes
nodered | 28 Oct 23:24:00 - [info] Settings file : /data/settings.js
nodered | 28 Oct 23:24:00 - [info] Context store : 'default' [module=memory]
nodered | 28 Oct 23:24:00 - [info] User directory : /data
nodered | 28 Oct 23:24:00 - [warn] Projects disabled : editorTheme.projects.enabled=false
nodered | 28 Oct 23:24:00 - [info] Flows file : /data/flows.json
nodered | 28 Oct 23:24:00 - [info] Server now running at http://127.0.0.1:1880/
nodered | 28 Oct 23:24:00 - [warn]
nodered |
nodered | ---------------------------------------------------------------------
nodered | Your flow credentials file is encrypted using a system-generated key.
nodered |
nodered | If the system-generated key is lost for any reason, your credentials
nodered | file will not be recoverable, you will have to delete it and re-enter
nodered | your credentials.
nodered |
nodered | You should set your own key using the 'credentialSecret' option in
nodered | your settings file. Node-RED will then re-encrypt your credentials
nodered | file using your chosen key the next time you deploy a change.
nodered | ---------------------------------------------------------------------
nodered |
nodered | 28 Oct 23:24:00 - [info] Starting flows
nodered | 28 Oct 23:24:00 - [info] Started flows
nodered | 28 Oct 23:24:00 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered | 28 Oct 23:24:00 - [info] [server:Home Assistant] Connected to http://192.168.2.60:8123
But… now Node-RED web interface is not anymore reachable at 192.168.2.60:1880…
That’s odd. Is something else running on port 1880? You can check by running
sudo lsof -i :1880
If should produce no output with the container stopped, and with the container running show something like
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
docker-pr ### root 4u IPv4 ##### 0t0 TCP *:1880 (LISTEN)
docker-pr ### root 4u IPv6 ##### 0t0 TCP *:1880 (LISTEN)
You might have another container running Node red you didn’t remove or maybe you previously even tried to install it on the host’s bare metal and part of it is still there using port 1880.
If there is a port conflict you can also specify a different port, like 1881, by doing this:
ports:
- "1881:1880"
Then your node red page editor would be at 192.168.2.60:1881
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node-red 168424 jiheffe 18u IPv4 757705 0t0 TCP *:1880 (LISTEN)
I’m really at my days’ end here… Using Portainer, I removed all Node-Red related items I could find (container, image, network) and restarted. Still the same…
Yes it’s frustrating to fix one thing and then it breaks something else.
When I run sudo lsof -i :1880, it get the command is docker and the user is root. You’re getting it as node-red with you as the user. Not sure if that matters, but have you double checked that there isn’t a Node Red process running outside of docker somewhere? When you stop the Node Red container, does running sudo lsof -i :1880 produce a blank result (it should)? Did you try running starting the container on a different port like 1881 mentioned above?
I’m assuming there is some sort of docker or network configuration problem creating your issue. Checkout these steps that you should do after installing docker , like creating a docker group and adding your user to the docker group
You can prune your docker to remove any hanging pieces of an old container that might mess things up- Note - Make sure all the containers you want are running or it will remove them when you do this
I’m not sure what to try other then the prune or settings mentioned in the docker documentation linked above.
Maybe you can get more help posting on the Node red forum
I can confirm this is not an issue with Home Assistant, but rather with Node-RED and/or Docker.
I configured an MQTT broker in Node-RED, and I am having exactly the same behaviour there.
Case 1 - with ports: statement
ports:
- "1880:1880"
I can connect to Node-RED on port 1880
Node-RED can NOT connect to either HA or MQTT broker
nodered | 31 Oct 11:01:28 - [info] Server now running at http://127.0.0.1:1880/
nodered | 31 Oct 11:01:28 - [info] Starting flows
nodered | 31 Oct 11:01:29 - [info] Started flows
nodered | 31 Oct 11:01:29 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered | 31 Oct 11:01:59 - [info] [mqtt-broker:Mosquitto MQTT] Connection failed to broker: http://192.168.2.60
Case 2 - with network_mode: statement
network_mode: host
I can NOT connect to Node-RED on port 1880
Node-RED does connect to HA and MQTT broker
nodered | 31 Oct 11:06:30 - [info] Server now running at http://127.0.0.1:1880/
nodered | 31 Oct 11:06:30 - [info] Starting flows
nodered | 31 Oct 11:06:30 - [info] Started flows
nodered | 31 Oct 11:06:30 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered | 31 Oct 11:06:30 - [info] [mqtt-broker:Mosquitto MQTT] Connected to broker: http://192.168.2.60
nodered | 31 Oct 11:06:30 - [info] [server:Home Assistant] Connected to http://192.168.2.60:8123
I’ll leave this here for reference but will move to the Node-RED and/or Docker forums to try to find an answer.
Thnx for your suggestions, it helped me isolate the issue .
@Jiheffe did you ever find a solution for this? I just recreated my home assistant and node red, all running on the latest and greatest versions. My node red also will not connect to home assistant.
On my old docker containers the two services connect just fine. I basically copy and pasted the docker-compose file from one machine to another but on the new machine it won’t connect.
I even purposefully entered the wrong api token into the NR server settings to confirm HA did get the connect attempt and refused it. Putting the correct token causes the error to go away but all nodes are still in a “connecting” state.
Ok solved it for my case, the reason i couldn’t reach the webhost even after changing my settings.js uiHost to my host ip address was a firewall issue, for some reason even though i added the ports the servers firewall i had to restart the firewalld service before it worked
Also a note for anyone else having the same problem and the firewall and uiHost doesnt work try using setenforce 0 to (temporarily) disable selinux which might be causing the issues for others.
Appreciate all the information in this thread. I lost the ability to see my entities and in searching my setup it appeared I lost my server link. Removing and reinstalling N-R didn’t solve the issue. The response from “mwav3 Tim” helped me understand correct entries, problem solved. Thanks to all who provided suggestions. As a new HA and N-R user, I was a bit lost.