Deploying Home Assistant with balena

Hi there!
I got into Home Assistant recently and of course I wanted to have my HA deployed with balena. Surprisingly I found little information or previous user experiences, and the process of setting it up was more challenging than I anticipated. So I documented the issues I had and wanted to share them.

If you have suggestions, alternatives or any comments please let me know!

1 Like

Hey @tmigone,

thank you very much for your medium post, we really appreciate the time you took to write it.
I will share it on our social media and I would also like to send you our swag pack as a thank you!

I will contact you privately,

Cheers :tada:

Hi @dansku, that is awesome, thank you! Iā€™ll get back to you via pm.

Sorry itā€™s an old thread but I didnā€™t quite understand the Medium post that you sent. I feel that itā€™s a bit hard to follow for someone whoā€™s new and working with Balena Cloud. If you could have a step-by-step guide or any other docs then that would be helpful.

What part are you having trouble with? Maybe we can helpā€¦
Maybe you also want to check out the projects here: https://github.com/balenalabs they will generally have a more detailed step-by-step guide on how to deploy them and you can then take the knowledge for this one :slight_smile:

I got it to work! Thank you for your time. I just followed the Medium post carefully.

@tmigone Thanks for the detailed post on Medium ā€“ I definitely found it helpful, and believe it speaks to some of the issues Iā€™m currently facing with regard to running Home Assistant on Balena. My current challenge is that Iā€™m a total N00b to Home Assistant, Balena, and containerized applications ā€“ so thereā€™s just a lot of surface area / learning curve ā€“ and often, itā€™s not immediately obvious which curve Iā€™m on.

Case in point: Having completed virtually my entire migration from a SmartThings v1 hub (4 days until it implodes), Iā€™m left with only some of my more complex automations - which may have used custom device handlers, or other automation (ā€œmirroringā€ devices, such that all lamps in a fixture, for example, can be controlled as a single device). Clearly - that is a Home Assistant topic / question. Butā€¦

What about the task (as described in the Medium post, and still just beyond my grasp on a couple of points) is the management of my Config file for Home Assistant ā€“ and, the next great hurdle ā€“ Lovelace dashboards. As Iā€™m working within HA, clearly by config is being updated - and persisted, outside the container ā€“ butā€¦ where / how would I do UI development? I certainly want to be keeping the config under source control - and am at least comfortable with ā€œbalena pushā€ ā€“ butā€¦ ?

One clear / obvious question for @tmigone : When you speak of development vs. production ā€“ I assume this means you have two entirely different devices (but under a single application - or two distiinct ones?) within Balena. I love the idea of a dev environment, and have plenty of Pis to go around - but a dev device wouldnā€™t have all my Zigbee and ZWave devices plumbed to it, of course - making testing certain things challenging. I guess I could at least be doing UI work there, testing upgrades, new integrations and config changes.

Thanks again for the post, and thanks in advance to the community for any additional insights, #ProTips or hand-holding.

Peace!
Billy

Hi

I have pinged Tomas, but Iā€™d like to take a shot at your dev and prod device question. In balena terminology, we use development and production devices to indicate devices that are running the development and production version of the balenaOS. These are 2 separate images, that have some differences - for example support for local device development exists in the developer image. You can read more about this on our docs for the same

Thereā€™s nothing stopping you from having the a production device (i.e. a device running production variant of balenaOS) along side a development device(i.e. a device running a development version of balenaOS) in the same app. In fact thatā€™s exactly how I do my app development. I develop locally on my dev device, and then push to the balenaCloud when my app is ready to be distributed to my other devices.

If you donā€™t want to enable certain services on your development device, you can either maintain 2 separate docker compose files, or structure your app such that your services check for a local variable to start or stop. So if you have an env variable that prohibits your zigbee service from running, that can be something you use to distinguish between your prod and dev devices (env variables can be set either fleet wide or per device)

1 Like

Thank you, @anujdeshpande ! Iā€™ve been chipping away at some of the masterclasses and doing a bit of balena push via the CLI for some projects ā€“ and Iā€™m totally following what your describing, and appreciate the feedback.

I guess my question is less Balena-centric, and more about Home Assistant - so perhaps (at least part of) my question belongs over there (e.g. How to do development on devices that can only be connected to one ā€œnetworkā€. I know, I know - with stubs, or ā€˜digital shadowsā€™ of devices. :smiley: But applying that, for example, to the Zigbee or ZWave ā€œIntegrationsā€ and device registration, grouping, automations, scenes, triggersā€¦ it seems the only place I can do development about ā€œGrouping my 3 dining room lights together and controlling them as a single unitā€ will be in my prod, RUNNING device. Then, any successful changes would need to be ā€˜back-portedā€™ to the repo ā€“ YIKES! This doesnā€™t sound like the right workflowā€¦ :slight_smile:

Thatā€™s the part of Tomasā€™ post, right at the fringes of my Docker and Balenu understanding, is the description of the mount vs, the bind mount, the timing of same and copying of files into the image.

Iā€™m gonna give it another read - and go hands-on (on a development build :)) and see what I can figure out.

Thanks again for the insights!

hey @snowake, Iā€™m glad you found the post useful!

Let me clarify the ā€œprodā€ vs ā€œdevā€ conundrum. What both you and Anuj describe is correct. balenaOS offers two flavours (ā€œProductionā€ and ā€œDevelopmentā€) with some differences, the main one being that the development version provides tools that aid you if you want to develop your code on your device (see this blog post for more context on that).

However, in my HomeAssistant blogpost I was not referring to balenaOS flavours when talking about prod and dev but rather:

  • ā€œproductionā€ is my Raspberry Pi that actually runs HomeAssistant 24x7
  • ā€œdevelopmentā€ is my development machine, my laptop computer where I do all my work.

This setup has an obvious drawback and itā€™s the one you already found, if you are working with hardware that connects to your Home Assistant device you need to have it connect to both your dev and prod devices. At the time I wrote the blogpost I only had some Philips Hue lights and a couple of sonoff devices, both of which I had connected to my Raspberry Pi for prod but also to my computer for development. If you have a bigger setup this is not scalable at all and it might not even work. Iā€™m not sure how the HomeAssistant devs do actual development maybe as you say itā€™s worth bringing this issue to their forums/GitHub as they might have some tips.

Since then Iā€™ve moved away from the workflow I talk about in the blogpost for this reason, moreover with recent (last 1.5 years) HA changes they are moving more and more into the direction of storing configuration in database-y files and not YAML files. So it become harder and harder to use this workflow I describe. What Iā€™m currently running is a modified version of GitHub - balenalabs-incubator/balena-homeassistant: Raspberry Pi + Home Assistant + balenaSense which is just a HA instance (you can ignore/remove the balenaSense stuff). This approach has a couple notable drawbacks that I have to live with:

  • I have no ā€œdevelopmentā€ environment anymore, so every time I upgrade stuff breaks.
  • I need to manually backup the ā€œconfigā€ volume. This ties in to point #3 on my blogpost (Source control with GitHub: Backup HA configuration and rules to a git repository.). As I mentioned before HA nowadays relies more in database files than YAML so I had to give up on this. Now if for some reason I have to re-flash my Raspberry Pi I need to import my HA config backup.

Those are my 2c, other than that Iā€™ll ask a colleague thatā€™s much more experienced with Home Assistant to chime in if heā€™s got anything else to add.

Thanks, @tmigone - for the detailed response! I feel like Iā€™m at a decision point - and need to either go all-in on figuring out Home Assistant in the context and deployment model of Balena ā€“ or just go with a more vanilla, HomeAssistantOS running on a RPi4 sort of deployment architecture - at least for my ā€˜Productionā€™ use case (which is subject so significant WAF pressures). Case in point: The fact that:

Alexa- turn on dining room light

no longer behaves as expected desired ā€“ and that is one frequently-invoked home automation routine. So - Iā€™m struggling on a variety of fronts ā€“ from ZWave integrations (and the proposal, from this thread, that in order to migrate to the newer ZWave-js integration - Iā€™d need to install an ā€œjs2MQTTā€ or some such container, along side my HomeAssistant, to facility the configuration (but, apparently, not the actual integration?

I guess one specific question I can appropriately ask here (it feels like the answer can be found in your Medium post - but Iā€™m not finding it where expected).

Where would I find my config files? I do see the /config directory, as mounted in the homeassistant container ā€“ but not finding the corresponding ā€˜persistentā€™ version of it in the Host OS? I suspect Iā€™m missing some key concept :slight_smile:

My goal, currently, is to delete an ā€˜orphanedā€™ ZWave device which didnā€™t seem to add properly (with both of the required entities) - so I was unable to control it. Iā€™ve tried removing (ZWave exclusion) ā€“ and can get rid of the associated entities, but not the actual device.

I know, I know: Thatā€™s a question for the HA forums. I asked it, here:

At any rate - for today, my goal is just to get the current Balena-deployed HA up and operational, and achieving full WAF. Going forward, I hope to detangle some of the various pros and cons and make an informed decision about my target state deployment - for both ā€œproductionā€ and development environments (noting the hardware constraints discussed above). Perhaps an additional Zigbee / ZWave stick, and a few devices confined to just my officeā€¦ :slight_smile:

Thanks again for your detailed write-up. Iā€™m off to read it carefully a third time, while referencing the Dockerfile and docker-compose files - to see if I can enhance my understanding.

Cheers!

where / how would I do UI development? I certainly want to be keeping the config under source control - and am at least comfortable with ā€œbalena pushā€ ā€“ butā€¦ ?

You can simply use a (private) GitHub repo for source control and continue using balena push. There is even a GitHub action to automatically push to balena. For UI development Iā€™d recommend using what is called ā€œmulti-stage docker filesā€. This basically means, you write multiple docker containers (for different purposes) in one file.
So your UI containerā€™s Dockerfile might look something like this

FROM node as build
COPY . .
RUN npm ci && npm run build
# final image, which will get actually deployed
FROM ngix
COPY --from=build . /var/usr/www # you'd better check if that path is correct

Where would I find my config files? I do see the /config directory, as mounted in the homeassistant container ā€“ but not finding the corresponding ā€˜persistentā€™ version of it in the Host OS? I suspect Iā€™m missing some key concept

Volumes in compose are an abstraction of storage that can be mounted. The default (like in your compose file) is using ā€œDocker Volumesā€ which are like containers without running processes, just an empty filesystem.
You can list them with `balena volume ls. There are similar commands to extract the data as well.

Hope this helps as entrypoint to your further research

1 Like