Blocks, services, containers, and devices. Whew.

I’m trying to get the balena homeassistant configuration running on a raspberrypi 4 and I’m thinking I need to do some custom work as bluetooth doesn’t work out of the box.

I’m having some challenges understanding where I might need to change this. I see that there is a balenablock for bluetooth for the rpi4, but I don’t really understand what a block means or how it gets deployed on the underlying device. Are blocks each in their own docker containers? If so, how do I get those functions available to other containers? Am I just missing the point?

tl;dr: I want to enable bluetooth on the home automation image but I’m unsure how to start on tackling it.

Hello @cab938 welcome to the balena community!

Could you please point us the homeassistant repository that you are trying to deploy on your fleet?

Thank you!

Hi @mpous , I’m trying to use this one in the incubator: GitHub - balenalabs-incubator/balena-homeassistant: Raspberry Pi + Home Assistant + balenaSense

So really my problem might be better solved (now that I’ve learned more) with setting the network mode to host for the homeassistant container, this way the bluetooth adapter can pass through into the homeassistant. I tried to do that here: Update docker-compose.yml · cab938/balena-homeassistant@6e1929c · GitHub

This made the adapter visible and I could at least query it on the cli in the container. It killed the web interface though, for reasons which are unknown to me :slight_smile: but I confess I am guess and testing in the yaml config files and my knowledge of docker compose and the interplay between different containers is unclear. For instance, if I deploy the bluetooth block from here: GitHub - balenablocks/bluetooth: Optimized bluetooth agent for balenaOS. Based on BlueZ 5.0. as another service in my docker compose file (e.g. this one balena-homeassistant/docker-compose.yml at master · balenalabs-incubator/balena-homeassistant · GitHub ) does this somehow make available to the homeassistant service the bluetooth adapter? I would gather no, e.g. each of the services are run in their own containers.

Regards,

Chris

Hi @cab938 , I understand you’re trying to make bluetooth work with home-assistant, though I am not sure about your exact use case but let me help clear your doubts about the blocks and bluetooth connectivity.

I see that there is a balenablock for bluetooth for the rpi4, but I don’t really understand what a block means or how it gets deployed on the underlying device.

blocks are basically drop-in chunks of functionality built to handle the basics so you focus on solving your main problems, for ex: the audio block allows you to route the audio from different sources to different sinks without you worrying about underlying complex audio architecture (ALSA, Pulseaudio, DACs etc)

Are blocks each in their own docker containers?

Yes each blocks are separate containers in itself which interacts with your main application container to achieve the overall functionality one is trying to get. It is not recommended to change the code of the blocks (start script), however with the help of ENV variables set in the dashboard, we can tweak the functionalities of some blocks wherever needed.

You can read more about the blocks on this blog post

Coming to the experiments you’ve tried, so far from your modified docker-compose file, everything looks okay to me, the network_mode is set to host which is needed for BT, read more here the privileged is set to true which will allow access to host devices/interfaces by the container and you did mention that the adaptor is now visible which is great.

For instance, if I deploy the bluetooth block from here: GitHub - balenablocks/bluetooth: Optimized bluetooth agent for balenaOS. Based on BlueZ 5.0. as another service in my docker compose file (e.g. this one balena-homeassistant/docker-compose.yml at master · balenalabs-incubator/balena-homeassistant · GitHub ) does this somehow make available to the homeassistant service the bluetooth adapter?

The bluetooth block basically ease pairing and connection to other bluetooth devices and has following functionalities:

  • Handle bluetooth pairing and connection with other devices
  • Support for any bluetooth interface (built-in or USB)
  • Uses DBus to communicate with balenaOS bluetooth daemon
  • Reconnect on boot to known and trusted devices

but doesn’t deal with data transport which you need to handle in your main application container only (home-assistant in your case) using the desired bluetooth profiles. So I’m not really sure if bluetooth block is really what you need to make it work with home-assistant, since you already can access the interface. I also wonder why running cli commands accessing BT interface killed the web interface of your home-assistant.

I hope you now have a better understanding of blocks and multi-container workflow, let me know if it still doesn’t work and will definitely help you proceed forward, cheers! :slight_smile: