Home Assistant and ESPhome in Docker

Be patient and at some point you will achieve it or you will have new ideas. Luck!

can u give the method a try on ur Android phone?

Sorry to jump on an old thread, but you can actually manage specific services inside of your compose by specifying them in the command (ex: docker-compose down homeassistant). And bringing up all services with docker-compose upwill only restart those which have changed :slight_smile:

4 Likes

Indeed, there are many ways to manage Docker containers. For example, you can back up data, manage volumes, consumption and images. In this introductory guide to Home Assistant Docker containers, I have tried to use the simplest possible commands based on my experience.

The world of Docker is vast and each user must explore it and adapt it to their needs.
Therefore, it has not been considered appropriate to continue adding commands in this guide.
The decision to have a home automation server in Docker is a great responsibility that requires knowledge, as Home Assistant and ESPHome are very important server.
Each user must assess their situation and deepen their knowledge of container use according to their needs.

Hi,

When you have multiple USB they might swap places.
So I recommend the USB device ID and not the assigned USB port (USBx) because when there are more than 1 USB devices attached on a system reboot assigned USB ports can (and will) change. UDEV can be used also but requires extra work outside the container. Command to show USB devices by ID:

sudo ls -la /dev/serial/by-id

For your docker-container use a logical USB name.

devices:
- /dev/serial/by-id/usb-FTDI_FT232R_USB_UART_AK2NEAM6-if00-port0:/dev/ttyUSB_DSMR
2 Likes

Good advice. I have both USB devices exposed as I have both a coral for frigate and a TI zigbee cordinator for ZHA. Can I assume this method will work for both devices?

First question would be “Did you experience it yourself?”

swapping USB port will not happen much, the first time it happened to me last summer I was off course on holiday. Likely my Linux-settings with automatic updates is the root cause why it happened because this process can also initiate a reboot.

I think this is a or mayby the solution to avoid it, so try it out. Your Coral for frigate will be a good “sandbox” and despite you need to recreate this container if you do not change the second part (likely :/dev/ttyUSB2), you do not need to change any Frigate settings. You can always change this later to a more meaningful and non-confusing name.

BTW About

privileged: true

There are topics which advise you not to use this. If I understand it correctly with my NOOBS/DUMMY limited Linix/Docker knowledge your container with this setting will have access to more(/everything?) than the container itself.

This is one of those settings I have had for as long as I can remember, but I don’t remember why I had it enabled. I am in the process of updating this.

Where do I put the fonts required for ESPHome? In my case the Docker data is stored in appdata on UnRaid, but do I store the fonts in the ESPHome folder, the Home Assistant folder or a Font folder in the parent directory?

The ESP32 device tutorial talks about using the File Editor in Home Assistant from Settings/Add-ons to set this up, but I don’t see an add-ons option under settings?

EDIT: Ok, all sorted

I stumbled upon this reading this thread on ESPHome.
This is great :smiley: I ha ve been looking for a solution for ages ! I have two USB dongles on my NUC, one Zigbee and one Z-Wave. Each time the NUC restarts (luckily, not often), they get swapped.
Will try this solution tonite !

Just sharing the solution I found somewhere on the internet after I got fed up with similar switches of USB devices. It works for me, if it also does for you you can like the post :grinning:

Sharing is building knowlegde

Hi,
The instructions at the top of this thread have been great. I have migrated from an rpi4 setup to a small home server. Thanks very much for your help in setting up home assistant.

But I am having a little trouble with esp home. I have the docker running OK, but I do not know where to put the configuration information from my old rpi4.

There was an esphome directory within homeassistant config directory. I have tried to put its contents in the config directory in the esphome docker but it does not work.

Can you please let me know where to copy the config information?

Thanks

I use a other directory:

    volumes:
      - /home/shares/pi/esphome/config:/config

copy to this

Thanks!

It is working fine now.

Have you set up a media directory on the docker home assistant?

There is a discussion here about the media location https://community.home-assistant.io/t/media-folder-location/231755/12

I have set this up and can select one of my own sounds in a media player, but it does not play.

I think this error appears:

homeassistant.components.sonos.exception.SonosUpdateError: Error calling SonosMediaPlayerEntity._play_media on media_player.decking: HTTPConnectionPool(host=‘192.168.86.33’, port=1400): Read timed out. (read timeout=9.5)

Is this an issue with docker port forwarding that I need to address?

Since you linked my post I’ll chime in.

I think your issue here is in regards to the later part of my post, specifically the authSig. Anything above the www directory requires authentication. Sonos isn’t authenticating to HA and has no way to do so. The only option would be to place a folder in the www folder with the sound files. The problem with that approach is that they would then be accessible without any authentication to anyone in the world.

In my post I’m specifically addressing HA sending files to the Mobile client. That client is authenticated to HA and can therefore access the local directory.

Thanks for your suggestions.

I have relocated my sound file to beneath the www directory, as you suggested, but can still not play the sounds to the sonos devices.

Initially I could see the error message I mentioned on the screen when I was running 2024.9.1. I manually updated to 2024.9.2 and still cannot play the sounds but can no longer cause the error message to appear on the screen.

My small server is actually running Open Media Vault and I am using its docker compose add-on to run my Home Assistant and ESPhome dockers. I am wondering if that may be the cause of this unexpected behaviour.

It looks like the new docker Home Assistant has retained some settings from my rpi4 Hass Home Assistant installation.

I have been following up with error log files and can see that the issue is related to authSIG.

val="ERROR_CANT_REACH_SERVER"/><TransportErrorDescription val="2,0,Relaxing River Sounds - Peaceful Forest River - 3 Hours Long.mp3?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI,192.168.86.30:8123,http://192.168.86.30:8123/media/local/Relaxing%20River%20Sounds%20-%20Peaceful%20Forest%20River%20-%203%20Hours%20Long.mp3?

The address 192.168.86.30:8123 is not the address of the current docker Home Assistant. It was the address of the rpi4 install, but my server is at 192.168.86.34.

I have attempted to rectify this issue by using the Local IP integration, which reports the correct ip. I have restarted HA several times but the problem persists.

Well it has been a lot of looking around, but there is a file called core.config in the .storage directory that contains a lot of configuration information, in particular a field called

“internal_url”: “http://192.168.86.34:8123”,

I manually edited this line to contain the correct ip address, then restarted Home Assistant and I am now able to play media files to the sonos device.

Hooray!

I recall in the previous installation on the rpi4 that it was possible to specify the internal url and have not found the location in the docker HA system.

Hopefully this helps someone else.

2 days later…
I cannot believe that I have suddenly lost the ability to play media files on the sonos device.

The favorites tab in the media browser has suddenly reported that there are no items.

I have not been able to find any discussions of this issue. Am I really alone?

It turns out I did not read the manual properly enough ie https://www.home-assistant.io/integrations/media_source/#local-media

My configuration.yaml file now has this at top and seems to work fine:

media_source:

homeassistant:
#
   media_dirs:
     local: /config/media

the next day…

The history has stopped working for all the entities. The useful time-trend does not appear.
The reading I have done has not helped with my install, https://community.home-assistant.io/t/psa-2024-7-recorder-problems/746428

when I run recorder.purge I get this:

Logger: homeassistant.components.recorder.util
Source: components/recorder/util.py:299
integration: Recorder (documentation, issues)
First occurred: 12:08:35 PM (1 occurrences)
Last logged: 12:08:35 PM

The system could not validate that the sqlite3 database at //config/home-assistant_v2.db was shutdown cleanly

some time later my configuration.yaml now contains:

# Example configuration.yaml entry from https://www.home-assistant.io/integrations/recorder/#disk-space-requirements
recorder:
  purge_keep_days: 5
  auto_purge: false

  include:
    domains:
      - sensor
      - switch
      - media_player
  
# Basic configuration.yaml entry from https://www.home-assistant.io/integrations/history/
history:  
  

It took several restarts of HA and even closing the docker before the database seemed to come back to life.

I am only including this blow-by-blow description in case it helps someone else migrating from a raspberry pi installation (mine was running smoothly for about 4 years)

What I have learnt lately is that docker Home Assistant seems to “listen” much more intently to the configuration.yaml file than I was used to. Stuff seemed to work in HassOS on the rpi and I am feeling pretty dumb that the transition was so difficult, but still this has been a good opportunity to fix up some things. For example, I used to use Zigbee2MQTT and ZHA on the rpi and have now consolidated my zigbee network on ZHA.