# Trouble connecting to Home assistant (docker)

**URL:** <https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973>\
**Category:** General\
**Created:** [30 October 2021 12:13 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973 "2021-10-30T12:13:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jiheffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jiheffe/32/50136_2.png) [@Jiheffe](https://discourse.nodered.org/u/Jiheffe)\
**Post date:** [30 October 2021 12:13 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/1 "2021-10-30T12:13:39Z")

</div>

Hi,

I am at my wits end trying to get Node-RED connected to Home Assistant server. I have HA and NR running in docker containers on a NUC.  
These are the `docker-compose.yml` files for both:

```auto
version: "3"
services:
  homeassistant:
    container_name: homeassistant
    image: homeassistant/home-assistant:stable
    volumes:
      - ./config:/config
      - /etc/localtime:/etc/localtime:ro
      - /var/run/docker.sock:/var/run/docker.sock
    devices:
      # Conbee II Zigbee device on USB
      - /dev/ttyACM1:/dev/ttyACM1
    restart: unless-stopped
    network_mode: host

```

```auto
version: "3.7"
services:
  node-red:
    container_name: nodered
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Brussels
    ports:
      - "1880:1880"
    restart: unless-stopped
    volumes:
      - ./data:/data

```

Node-RED version:

```auto
nodered | 30 Oct 14:03:23 - [info] Node-RED version: v2.1.3
nodered | 30 Oct 14:03:23 - [info] Node.js version: v14.18.1
nodered | 30 Oct 14:03:23 - [info] Linux 5.11.0-38-generic x64 LE

```

Whith this configuration, NR tries to connect to HA without success:

```auto
nodered | 30 Oct 14:03:24 - [info] Starting flows
nodered | 30 Oct 14:03:24 - [info] Started flows
nodered | 30 Oct 14:03:24 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123

```

As advised by some in the HA forums, I changed the NR docker-compose.yml as follows:

```auto
version: "3.7"
services:
  node-red:
    container_name: nodered
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Brussels
# ports:
# - "1880:1880"
    restart: unless-stopped
    volumes:
      - ./data:/data
    network_mode: host

```

Doing so, NR connects to HA:

```auto
nodered | 30 Oct 14:08:57 - [info] Server now running at http://127.0.0.1:1880/
....
nodered | 30 Oct 14:08:58 - [info] Starting flows
nodered | 30 Oct 14:08:58 - [info] Started flows
nodered | 30 Oct 14:08:58 - [info] [server:Home Assistant] Connecting to http://192.168.2.60:8123
nodered | 30 Oct 14:08:58 - [info] [server:Home Assistant] Connected to http://192.168.2.60:8123

```

Great, problem solved 😀 ! Well, no...

In this configuration, I cannot connect anymore to NR via the 1880 port...  
But the port seems to be up and listening...

```auto
$ sudo lsof -i :1880
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node-red 429417 jiheffe 19u IPv4 1682621 0t0 TCP *:1880 (LISTEN)

```

What am I missing here ?

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [30 October 2021 16:06 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/2 "2021-10-30T16:06:42Z")

</div>

> [@Jiheffe](#):
>
> ```auto
> ports:
> - "1880:1880"
> 
> ```

Did you try it without the double quotes ? These are numbers, not strings.

---

<div class="post-metadata">

**Author:** ![Jiheffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jiheffe/32/50136_2.png) [@Jiheffe](https://discourse.nodered.org/u/Jiheffe)\
**Post date:** [30 October 2021 16:20 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/3 "2021-10-30T16:20:53Z")

</div>

Well, actually I found that single quotes, double quotes or even no quotes around the ports do not make any difference...

Whern I use the

```auto
    ports:
      - "1880:1880"

```

statements, I can connect to NR in the web interface, but I can't connect NR to the HA server.

Whern I use the

```auto
    network_mode: host

```

statement, NR connects to HA (according to the logs) but I can't connect to the NR web interface at 1880...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [30 October 2021 16:25 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/4 "2021-10-30T16:25:53Z")

</div>

I see for docker-compose the ports are actually in a string for some reason (never noticed that before weird).  
Then I don't know, you may have better luck in the HA forums/discord, not too many HA users here afaik.

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [30 October 2021 16:40 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/5 "2021-10-30T16:40:42Z")

</div>

My NR initiates the outbound connection to HA's bus, not the other way round. You can add the HA nodered integration (Not to be confused with the NodeRed add-on) but only if you want to publish direct from NR to HA.  
I have HA on port 8123 (Default) and NR on 32771:1880 I also have 3456:3456 and 8009:8009 on the NR container.  
For some reason, 1880 did not work on my Synology NAS hosted Docker. Ohh, also the network is in 'bridge' not 'host' mode.

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/b/0b9ac182950a4f73913504c4481a525b9d7004c3.png)

---

<div class="post-metadata">

**Author:** ![dougle03](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dougle03/32/32979_2.png) [@dougle03](https://discourse.nodered.org/u/dougle03)\
**Post date:** [30 October 2021 16:46 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/6 "2021-10-30T16:46:17Z")

</div>

When you took out the port mapping from your compose file, you effectively left docker to pick a random set of inbound ports. Try 21771:1880  
There is no secret sauce with 21771, but it's much less likely to be already in use..  
then try to connect to NR on that port - so | [http://ipaddress:21771](http://ipaddress:21771)

---

<div class="post-metadata">

**Author:** ![Jiheffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jiheffe/32/50136_2.png) [@Jiheffe](https://discourse.nodered.org/u/Jiheffe)\
**Post date:** [30 October 2021 19:47 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/7 "2021-10-30T19:47:30Z")

</div>

Thank you for all your suggestions 🙂

Actually, I do not really have a problem with the 1880 port to access the NR web interface when I use

```auto
    ports:
      - "1880:1880"

```

In that situation, I have no problem to get into the NR web interface. BUT, **NR does't connect** to the HA server.

On the other hand, when I use

```auto
    network_mode: host

```

NR does connect to the HA server, BUT is **not accessible at port 1880** via the web interface.

Both options are mutually exclusive, i.e. you cannot have both the `ports:` and `network_mode:` directives at the same time.

So for me the issue is not related to HA but rather to Docker and/or NR... and probably to my rather rookie knowledge of docker 😉

---

<div class="post-metadata">

**Author:** ![Jiheffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jiheffe/32/50136_2.png) [@Jiheffe](https://discourse.nodered.org/u/Jiheffe)\
**Post date:** [31 October 2021 10:19 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/8 "2021-10-31T10:19:48Z")

</div>

**Update:**  
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

```auto
    ports:
      - "1880:1880"

```

- I **can** connect to Node-RED on port 1880
- Node-RED can **NOT** connect to either HA or MQTT broker

```auto
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

```auto
    network_mode: host

```

- I can **NOT** connect to Node-RED on port 1880
- Node-RED **does** connect to HA and MQTT broker

```auto
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

```

Continuing investigation 🙃

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [31 October 2021 21:11 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/9 "2021-10-31T21:11:09Z")

</div>

> [@Jiheffe](#):
>
> Both options are mutually exclusive, i.e. you cannot have both the `ports:` and `network_mode:` directives at the same time.

That's why the `bridge` suggestion was made, as ports will only be discarded in `host` mode.

---

<div class="post-metadata">

**Author:** ![Jiheffe](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jiheffe/32/50136_2.png) [@Jiheffe](https://discourse.nodered.org/u/Jiheffe)\
**Post date:** [1 November 2021 07:07 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/10 "2021-11-01T07:07:54Z")

</div>

I tried this, but it makes no difference...  
Quite new to Docker, still trying to get the hold on networking options...

---

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [1 November 2021 15:37 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/11 "2021-11-01T15:37:22Z")

</div>

Did you actually recreate the containers after the modifications of the docker-compose.yml ? I would suggest to use bridge for HA as well.

---

<div class="post-metadata">

**Author:** ![mwav3](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/mwav3/32/50371_2.png) [@mwav3](https://discourse.nodered.org/u/mwav3)\
**Post date:** [2 November 2021 01:19 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/12 "2021-11-02T01:19:25Z")

</div>

> [@bakman2](#):
>
> I would suggest to use bridge for HA as well.

Home assistant needs to run in host networking mode for discovery and a lot of the integrations to work properly. Many of the different integrations use a variety of different ports. The docker install documentation for home assistant also says to use host networking mode.

Some get by with bridge mode fine for home assistant if they don't need discovery or aren't using an integration that needs it. While this could fix the problem by putting both containers in the same docker network, it could create other problems.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [1 January 2022 01:19 UTC](https://discourse.nodered.org/t/trouble-connecting-to-home-assistant-docker/52973/13 "2022-01-01T01:19:57Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
