Moving from HA OS to to Container

I’ve been running HA OS on an RPI 4B for several months and it’s great. Admittedly, I don’t know what I’m doing but I put in the time to figure out what I want to do, gradually.

I recently set up an Ubuntu server using an old Dell desktop and would like to move my HA to docker containers. I have a few add-ons but the only one that would need to move is Zwave JS UI. I’m also just getting started with ESPHome.

As a first step that would likely be educational for me, I’m wondering if I can run ESPHome in a docker container and link it to HA OS. I wouldn’t want to jump through hoops to do it but if it’s addidng a few lines to the docker compose in the ESPHome docs, or maybe creating a port for the container and giving it to my HA OS, it could be worth doing.

Any advice is welcome. I pretend to know more than I actually do. Thanks!

The ha docker and esphome docker don’t communicate with eachother. They both communicate with esphome devices on their network but that’s it. If you want to embed the web ui of esphome inside ha, I think iframe panel is what you want. iFrame panel - Home Assistant

ESPHome leaves a lot to be desired as far as documentation for setting up on Docker, but you should be able to get something started with this service in your docker-compose.yaml:

services:
  esphome:
    # `container_name` makes it so Docker wil create a consistent name.
    # There's nothing special about the name chosen.
    container_name: esphome
    # The tag is the `2023.12.9` part.
    # The hash is the `sha256:a8108cf5c4a162414de5bf7048a14bd8c64ded96c1fb9f6c891d03116e4e2a56` part.
    # You don't actually need both the tag and the hash in an image
    # I've specified them here because I find it easier to understand the tag as a human,
    # And Docker will both use the hash to pull the correct image and also validate the hash against it.
    # Most times you'd see something like `ghcr.io/esphome/esphome` or `ghcr.io/esphome/esphome:latest` or `ghcr.io/esphome/esphome:2023.12.9`.
    image: ghcr.io/esphome/esphome:2023.12.9@sha256:a8108cf5c4a162414de5bf7048a14bd8c64ded96c1fb9f6c891d03116e4e2a56
    # We're using host networking because ESPHome needs to use mDNS to auto-discover devices.
    # You could probably figure out how to set things up without the host network,
    # but it seemed non-trivial to me.
    network_mode: host
    # There are a few different restart policies.
    # `unless-stopped` says to always restart the container unless there's an explicit `docker compose stop esphome` (or similar).
    restart: unless-stopped
    volumes:
      # The `esphome/config` directory relative to this `docker-compose.yaml` file is where I keep device/secret YAMl files.
      # It needs to be mounted to the `/config` directory within the container.
      - ./esphome/config:/config
      # To set the time appropriately, we mount it from the host into the container read only (`ro`).
      - /etc/localtime:/etc/localtime:ro

To be a bit more explicit with what @Cyberbeni said, you could do something like the following in your Home Assistant configuration.yaml file to have ESPHome in a docker container show up on the left menu panel (in the same way the ESPHome addon shows up on the left menu panel):

panel_iframe:
  esphome:
    icon: mdi:chip
    title: ESPHome
    url: http://<ip-or-hostname-of-your-ubuntu-server>:6052

I think the first level under panel_iframe has to be unique. i think it’s used for the slug. So I’m not sure if you can have both the ESPHome addon and ESPHome in a docker container in the left menu bar with the same name/slug. If there’s a conflict, you might need to change things around with something like:

panel_iframe:
  esphome-docker:
    icon: mdi:chip
    title: ESPHome
    url: http://<ip-or-hostname-of-your-ubuntu-server>:6052

Or (if you want to make it easier to see in the UI):

panel_iframe:
  esphome-docker:
    icon: mdi:chip
    title: ESPHome in Docker
    url: http://<ip-or-hostname-of-your-ubuntu-server>:6052

There’s nothing special about that name/slug. Just needs to be unique.

Hopefully that gets you started!

Thanks for the tips. I just recently became aware that all add-ons run in their own (docker?) containers. That should make it fairly easy to move from HAOS to container when I’m ready to do so. Thanks for pointing to iFrame. I’ll certainly use it.

I ended up using ESPresence instead of ESPHome but I’ll likely start using ESPHome soon. ESPresence enabled me to use a BT sensor to unlock my front door after a series of fails with other types of sensors.

For what its worth, and my opinion is my own and maybe outdated, but I think youll have the best experience with the OS version, as its the ‘supported’ method. I used to run HA supervised but I kept getting errors and having to restart to get back to a ‘supported’ state in order to do updates. I now run the HA OS in a vm on proxmox and have never had an issue since.

I wrote a hass_ingress integration, and the original motivation was to enable containers to be placed in the HA sidebar like hassio addons. Because the new version of hassio only supports debian systems, and I need to run HA on non-debian. This integration will give you the same access experience as hassio addons.

ingress:
  adguardhome:
    require_admin: true
    title: AdGuard Home
    icon: mdi:shield-check
    url: http://127.0.0.1:45158
  nodered:
    require_admin: true
    title: Node-RED
    icon: mdi:sitemap
    url: http://127.0.0.1:45180
    headers:
      authorization: !secret nodered_auth
  esphome:
    title: ESPHome
    icon: mdi:chip
    url: http://127.0.0.1:6052