Home assistant docker (RPI): shell access to host machine / access to home network possible?

Hello

i am planning to run HomeAssistant in a docker container on a RPI4 (raspbian) but there are several things that i cannot quite wrap my head around.

  1. access to the home network: since HA will be running in its own closed environment will it have access to devices (i.e. IP adresses) in my home network? E.g. i have a couple of yeelight lamps which directly connect to my router (no bridge or anything). Will HA (addons) be able to access these?

  2. execute shell commands w root permission on host machine: again bc of running in its own container is it somehow possible to run shell commands/scripts on the host machine/RPI’s OS from within the home assistant container? Maybe via ssh?

sorry for what might be dumb questions but any replies would be much appreciated.

thanks

  1. The container will be able to access all devices on the network that the host OS can access. I would have to know your router configuration to tell if you’ll be able to connect to your lamps (probably yes).
  2. ssh should work.
1 Like

thank you for the fast reply!

  1. the lamps connect to the router/home network via wifi and are within the home network’s IP range just as the RPI is (i.e. 192.168.0.x) so no magic here

  2. could you maybe elaborate on how this would be achieved? or point me in the right direction? Can i just install a ssh addon within docker-homeassistant environment and then ssh-connect with username/pw/ip into the host machine to trigger shell scripts from there?

thanks

For (2) you can just SSH out of the container to the host. You do need to put the private key somewhere under /config/ and specify it on the command line, something like:

ssh -i /config/ssh/id_ed25519 -o StrictHostKeyChecking=accept-new [email protected] /usr/sbin/meltdown

You can’t use passwords here, since there’s nowhere to enter them.

1 Like

So there is a bridge between the WLAN interface and your LAN Ethernet ports. It’ll work.

thanks again for the replies

@ondras, yes, maybe my wording in OP was misleading.

about the SSH:
i can see that i still have to work on basic understanding of how hass works i.e. how this would be achieved.
basically i want to be able to have home assistant execute a shell script on host-RPI on demand (in this case when called via voice command over google assistant which i am planning to integrate into hass).

edit:
i found this thread on the forums Raspbian Hassio Run Kodi Automation - #2 by Lipown
i suppose this is what i am looking for? Then i would only need to find out how to trigger/call this service via remote (via HomeAssistant App on the phone and/or via voice command through google assistant)

I saw on the top post you mentioned a Docker container install, but later see you mentioned hassio. I have a docker install but that’s because I’m running Home Assistant on an old desktop using Ubuntu. If running on an rpi, I definitely would stick with the home assistant operating system (most still will call it hassio), with supervisor and add ons detailed here Raspberry Pi - Home Assistant If you go the docker container route, there will be no add ons, and you would have to install add-ons as separate containers and manage them yourself. It’s much harder to start out this way as most guides are based on having the add ons and supervised install.

This guy’s video does a good job explaining the different Home Assistant install methods and how they work:

thank you for pointing that out!

apart from docker and the hass.io image there is a third option “supervised installation”. wouldn’t this be the route to go if i want to stay on raspbian (i dont mind the unsupported label i suppose) while having full homeassistant functionality?

You get full Home Assistant no matter what.

The difference is whether you get the Supervisor - with add-ons and snapshots. Without the Supervisor you just spin up containers and manage your own backups.

Be warned, Supervised has some very specific requirements. If you don’t follow them exactly you can expect that at some point your system will refuse to upgrade, restart, and more until you address the issues it flags.

I would definitely not go this route. Reading the supervised install requirements here architecture/adr/0014-home-assistant-supervised.md at 91ecbe4af814de6c06f3f98afc0920b2491a334c · home-assistant/architecture · GitHub will explain why it’s not a good idea. Supervised on Raspian is not supported, and “Unsupported” doesn’t just mean you can’t ask for tech support, it means it won’t work as @Tinkerer pointed out above related to upgrading and restarting - and you’ll just have problems.

If you have to run raspbian (which I assume is because you are running other programs on the PI) then I would go the Docker container install route. It will be a little more challenging without the add ons but I’ve been running it for over a year this way myself. The downside is the steeper learning curve and no addons, but the upside is it frees up the machine to be able to run other programs and gives you a lot more options.

With the container install, you won’t get the openSSH add on. However, since Home Assistant container is running in Docker with host networking mode, Host network driver | Docker Docs you should be able to create the shell command in the configuration.yaml file to SSH out of the container to the host machine using the instructions in the link you posted above. This should then allow you to run a command on the host machine (outside the container).

2 Likes

thanks everybody for contributing! took me a bit to wrap my head around it but i got it to work eventually :slight_smile:

  1. yeelights are auto-discovered as devices (n.b. ONLY worked for me if they are on the newest firmware --otherwise the integration was found but no device could be added from it)

  2. consulting the thread i quoted above i was successfully able to create a simple switch that executes a shell script on the host machine. if anyone is a simple-minded newbie like me feel free to ask i’ll happily share details.

once again thanks everybody

1 Like