Installing CLI tools in HA OS

Hi all, I’d like to understand the proper way of installing and running CLI tools and git repos. I’m an HA beginner with a fresh installation of Home Assistant OS on RPi4.

Use case: In addition to automating my home, I’d like the connect the RPi4 to a few arduinos using USB and program them using PlatformIO CLI (python). Specifically, I would like to install the PlatformIO commands, clone code repos, and SSH into the RPi to build and upload new versions of the code to the arduinos. If the RPi was running standard linux, this would be easy. What is the proper way of achieving this on the Home Assistant OS?

My current approach: I installed the Advanced SSH & Web Terminal addon, found a persistent folder outside the container (/homeassistant), created a virtual env in the persistent folder installing PlatformIO CLI in there, and cloned my code repo in the persistent folder. Now I can connect with the SSH addon, activate the environment and run the CLI tools. When executed for the first time, the PlatformIO scripts install the necessary libraries and tools. I noticed that some of these do not survive a reboot. Something is likely installed in the SSH container and needs to be reinstalled when the container is reloaded. My approach just doesn’t feel right.

I had a few alternative ideas:

  • install HA in a container on the Raspberry Pi OS instead of using HA OS.
  • create an add-on that derives from the SSH add-on also featuring the PlatformIO stuff (that seems to go against the modularity idea of addons)
  • create an addon just for PlatformIO and somehow figure out a way how to access it from the SSH container (that feels right, but I’m not sure if it’s possible in this containerized world).

What’s your advice? Would I be better off with the Raspberry OS running the docker version of HA? Apologies if I’m not using the correct terminology.

For your use-case, and as you seem to know your way in Linux, definitely. I doubt you will even be able to use USB inside a SSH addon.

Keep in mind that you’ll loose addon capability, then, though.

Thanks for the answer. I can access the USB device inside the SSH addon and programming the arduinos works just fine.

I’m a bit scared to shift to the HA Container setup. Like you hinted, I would have to install and manage all the addons I use as separate containers. It is doable, but will keep me busy for quite some time. Then there is the supervisor mode…

I’d love to get some better understanding of what an add-on can and cannot do (beyond what the hello_world addon guide says). I’m still wondering if the option of creating an addon for PlatformIO could be an option. It seems unlikely as the CLI scripts would need to be accessible from the SSH container. Would be happy to hear from experienced users.

An alternative for you might be the vscode addon.
You can install the platformio vscode addon inside the HA vscode addon (Phew… :joy:)

I installed the Studio Code Server, but the PlatformIO IDE extension is not available there. Or did you mean something different?

Ah, indeed. I guess the addon is just a different flavour…

I don’t see a point to installing PIO CLI on your HA machine, with the intent to SSH into it and do the work there.

I just do it on my PC, without the additional step of SSHing and managing PIO on HA. What for?

You develop your PIO code within the IDE of your PC anyway…

I cannot easily connect the USB cable from my PC to the arduinos when they are placed in their final location. But the RPi is sitting just next to them and it can easily connect them to them via USB. It is very inconvenient to always have to bring my laptop to the arduinos to upload the code. Whereas the RPi is always there. I have a lot of code to tweak in the arduinos, so I need to be able to easily reprogram them.

I develop on USB. Then, when most of it works → I place them where I need them and update via wifi OTA (a bit slower than USB, but fast enough → and i’m pretty sure faster than adding another layer of SSH-to-rpi complexity ;))

  1. develop on pc
  2. OTA

vs

  1. develop on pc
  2. go and physically connect arduino to rpi
  3. upload code to rpi
  4. upload code from rpi to arduino
  5. unplug the device from rpi

the second way might be some kind of compromise if you break OTA, but that should rarely happen (it did to me… once?)

as for logging → WebSerial (serial over http)

one more thing: it helps to have multiple ESPs lying around → you can develop on your PC via usb with one device, and upload OTA to another device when ready

I’m using Megas that do not support OTA. The megas are constantly plugged into the RPi (and their own PSU). I’m using VSCode with the Remote SSH extension that allows me to connect to the RPI from my PC, having pretty much the same user experience as if I had the mega connected to my directly PC. I just need to manually run the pio commands from the VSCode console to upload from the RPi to the mega.

Ah, right…

Well, I quickly switched to ESP8266/ESP32 → much better specs for a buck spent (more CPU, more RAM, WiFi included - AND cheaper).

Then yeah, OTA is not a solution for you :wink: