Failing to reconnect to HA
See original GitHub issueDescribe the bug
I am running a single host on my house (it’s a small house xD). I am running Room-Assistant via docker. I also run Home-Assistant and Mosquitto with docker. I am noticing that my device trackers are losing state information occasionally.
To reproduce
I am pinpointing it to HA restarts and/or Mosquitto restarts. For example today the mosquitto container updated itself. HA is not able to recognise device state since then.
Relevant logs
4/12/2021, 6:44:39 PM - info - HomeAssistantService: Re-connected to broker
4/12/2021, 6:44:39 PM - info - EntitiesService: Refreshing entity states
4/15/2021, 1:01:12 AM - error - HomeAssistantService: connect ECONNREFUSED 192.168.x.x:1883
4/15/2021, 1:01:13 AM - error - HomeAssistantService: connect ECONNREFUSED 192.168.x.x:1883
4/15/2021, 1:01:15 AM - info - HomeAssistantService: Re-connected to broker
4/15/2021, 1:01:15 AM - info - EntitiesService: Refreshing entity states
Relevant configuration
---
global:
instanceName: "Antas Studio"
integrations:
- homeAssistant
- bluetoothClassic
homeAssistant:
mqttUrl: 'mqtt://192.168.x.x:1883'
bluetoothClassic:
interval: 30
addresses:
- A4:D9:31:BD:F4:ZZ
- 60:BE:C4:C8:FA:ZZ
My docker containers
# Home Assistant Core - Home Automation
homeassistant:
image: homeassistant/home-assistant:latest
container_name: homeassistant
restart: always
depends_on:
- mariadb
- adguard
- mosquitto
network_mode: host
volumes:
- $DOCKERDIR/homeassistant/config:/config
- $DOCKERDIR/shared:/shared
environment:
PUID: $PUID
PGID: $PGID
TZ: $TZ
labels:
# Diun
- "diun.enable=true"
# Mosquitto - MQTT Broker
# dexec mosquitto /bin/sh -> mosquitto_passwd -b /mosquitto/config/passwd username passwd
mosquitto:
image: eclipse-mosquitto:latest
container_name: mosquitto
restart: unless-stopped
security_opt:
- no-new-privileges:true
ports:
- $MOSQUITTO_HTTP_PORT:1883 #http
# - $MOSQUITTO_HTTPS_PORT:8883 #https
- $MOSQUITTO_WEBSOCKET_PORT:9001 #websockets
command: mosquitto -c /mosquitto-no-auth.conf
environment:
PUID: $PUID
PGID: $PGID
TZ: $TZ
labels:
## Watchtower
- "com.centurylinklabs.watchtower.enable=true"
# Room Assistant
roomassistant:
image: mkerix/room-assistant
container_name: roomassistant
restart: always
security_opt:
- no-new-privileges:true
depends_on:
- mosquitto
- homeassistant
cap_add:
- NET_ADMIN
network_mode: host
volumes:
- $DOCKERDIR/roomassistant/config:/room-assistant/config
- /var/run/dbus:/var/run/dbus
labels:
## Watchtower
- "com.centurylinklabs.watchtower.enable=true"
Expected behavior
When ever room assistant reconnects to HA/Mosquitto I’d expect the entities to be properly available in HA.
Environment
- room-assistant version: 2.16.0
- installation type: Docker
- hardware: NUC
- OS: Ubuntu 20.04
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
5 Ways to Fix Connection Failed, Reconnecting in HA Tunnel ...
1. Expired Time - Fixed! · Quit HA Tunnel Plus app, · Go to your System Settings, · Click on App Management, ·...
Read more >Can't connect to HA without a reason - Home Assistant OS
You can do that from home assistant web: First check configuration (Configuration - General - Check config) to make sure there is no...
Read more >RDP Session Fail to Reconnect after NetScaler HA failover ...
Whenever there is network disruption or failover, RDP client tries to reconnect, in this case the reconnection will be successful based on rdpCookieValidity ......
Read more >Failed to connect virtual device ethernetX (50112413)
vNIC disconnected after vSphere HA failover or vMotion and reconnecting vNIC fails with error: Failed to connect virtual device ethernetX ( ...
Read more >Troubleshoot Firepower Threat Defense High Availability Issues
Standby Node Fails to Join HA with "CD App Sync error is App Config Apply Failed" ... On the Standby FTD command line,...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I changed my MQTT config. Now I am persisting retained messages. I missed that detail when setting up MQTT. I believe this fixes it.
I’ll close this now and reopen if I notice any problems.
Thanks for providing these additional details - they give a pretty good hint. I believe what’s happening here is that room-assistant sends the HA config discovery information once when the entity is created, but not again on reconnect. This is done because the discovery information doesn’t change during the application lifecycle of room-assistant. Since the messages are marked as to retain they should be available to HA anytime, but this of course doesn’t work if the MQTT broker does not persist the messages across restarts. Since upgrading the container image starts a fresh instance the previously retained messages are lost.
My main suggestion would be to create a volume for /mosquitto/data on your mqtt container (if you can) and see if that fixes it for you. This volume should take care of carrying over retained messages across container upgrades.