Turn a Raspberry Pi or many single-board computers into a plug-in appliance to bridge your Bluetooth Flic smart buttons to your home automation system of choice, like Home Assistant.
Useful if your Flic buttons are located too far from your home automation hub, or if you need to use your hub's bluetooth antenna for something else.
- balena Dockerfile for ARM architecture based on Alpine Linux that weighs less than 40 MiB on a Raspberry Pi. βοΈ
- Regular Dockerfiles are available for traditional Docker stacks. π³
- Pre-built Docker images with multi-platform support are automatically kept updated on Docker Hub: ARM ones are Alpine-based while x86 ones are using Debian.
Why use the balena ecosystem? All the goodness of Docker, plus security handling, IoT hardware optimized images, read-only rootFS, a build pipeline, a device management interface, and continuous deployment, for free (well, first 10 devices on balenaCloud β¦or unlimited if you run your own OpenBalena platform).
Of course you could do all of this on your own, but do you really want to micro-manage, keep secure, always perform clean shutdowns, and generally baby something that should really be just plug-in, set-and-forget hardware? π€ I surely don't! π
- At least one Flic smart button.
- Your favourite Internet of Things (IoT) device that offers both Bluetooth Low Energy (BLE) and network access, like the inexpensive Raspberry Pi Zero W.
- Working access to an MQTT broker, either a public one, your own hosted Mosquitto instance or the Home Assistant addon.
- (Recommended) A free-tier account on balenaCloud along with a properly set SSH public key into your account.
- (Recommended) The balena command-line tools. Do read up on their friendly development guidelines.
Let's play! π€
Follow these simple steps to quickly get your app running on a dedicated device using balenaCloud. If you want more control, try the Docker solution instead.
For reference, the balena framework will build the container using the ./Dockerfile.template
which employs placeholders so that the correct system architecture is picked for you during installation. Easy! π
-
Create a new application on balenaCloud dashboard and select the appropriate IoT hardware.
-
Add a new device to your app. Start with development mode for local testing, or go directly for production mode if you know what you're doing.
-
(Optionally) Configure the downloaded image to give your device a custom hostname instead of the generic balena:
sudo balena local configure /path/to/downloaded/image.img
-
Burn the image to a disk and boot your IoT device.
Your hardware is ready; it's now time to install the project! β¬οΈ
-
Git clone this project's repository:
git clone [email protected]:renemarc/balena-flic.git
-
Add your balena application as a secondary remote to the cloned repo:
git remote add balena <username>@git.balena-cloud.com:<username>/<appname>.git
-
Push the code to balenaCloud and wait for it to build and provision your device:
git push balena master
Great! You are now ready to pair your button. β¬οΈ
Since only one controller can be paired at a time, do make sure that your Flic button is unpaired from your mobile device by using the Flic mobile app to remove the button from its interface.
Configure your Home Assistant (or other automation system) by pointing it to your device, say flic.local or 192.168.0.4, reload your configuration/restart the system, and let its auto-discovery system locate your button by pressing it for 7 seconds.
# Example Home Assistant configuration.yaml entry
binary_sensor:
- platform: flic
host: flic.local
port: 5551
discovery: true
Use this manual approach to pair your button if your home automation solution requires a more hands-on configuration.
-
SSH into your device's main container or use the balenaCloud dashboard terminal by starting the configuration tool:
simpleclient localhost
-
Start the manual pairing procedure by issuing the following command to simpleclient and pressing on your Flic button for 7 seconds (or until something positive comes up on screen).
startScanWizard
-
Take note of the MAC address shown to help you differentiate your various Flic buttons, then quit simpleclient by using
CTRL+C
then you are done. -
Restart your home automation hub to have the changes be recognized.
All buttons paired to your bridge have their configuration stored in the SQLite database found at /data/flic.sqlite
. To unpair a button requires those entries to be removed and the changes be recognized.
Note: this method isn't currently working. Bummer. Use the manual approach below instead.
-
SSH into your device's main container or use the balenaCloud dashboard terminal and start the configuration tool:
simpleclient localhost
-
List verified buttons:
getInfo
-
Remove the unwanted button from the verified list, using its MAC address:
removeButton 80:e4:da:XX:XX:XX
-
Restart your home automation hub to have the changes be recognized.
Don't mind getting your hands a bit dirty? Dive in!
-
SSH into your device's main container or use the balenaCloud dashboard terminal and install SQLite:
apk add sqlite
-
Open the database:
sqlite3 /data/flic.sqlite
-
Delete your button's corresponding row from the database, using its MAC address:
DELETE FROM buttons WHERE bdaddr = "80:e4:da:XX:XX:XX"; .quit
-
Restart the bridge's main container.
-
Restart your home automation hub to have the changes be recognized.
Patience, you must have. Use the Force, my young Padawan. β¨
- Temporarily stop the main container, or turn off the bridge altogether, or walk out of range with your Flic (50+ meters).
- Click the button once to see its light pulse red.
- Use the Flic mobile app and follow their instructions to reclaim control.
- Restart your home automation hub to have the button sensor removed from its list.
Want more control or wish to run this container on some multi-purpose shared hardware? Here are some useful steps.
The project has automated builds available on Docker Hub, along with a multi-platform manifest to automatically download the appropriate image based on the detected architecture.
-
Run the Docker image as an auto-starting container:
docker run --detach --restart=unless-stopped \ --net=host --cap-add=NET_ADMIN \ --name=flic \ renemarc/balena-flic
-
Explore the container:
docker logs flic
docker exec -it flic bash
-
Proceed to the pairing steps above. β¬οΈ
See additional image instructions on Docker Hub. π
If you prefer more control, you sure can build your own images.
Compared to the balena solution, here there are two possible Dockerfiles:
-
./Dockerfile
: Alpine-based version, used for ARM architectures. This file supports QEMU virtualization so that ARM images can be built on non-ARM hardware.Docker Hub uses this file to create automated builds; different architectures are supported through arguments in to the
./hooks/build
Docker hook. -
./Dockerfile-debian.Dockerfile
: A Debian-based version, meant to support the x86_64 architecture as well as i386 through the same Docker build hook.
-
Fork or clone this project's repository.
-
Build the image:
For a Raspberry Pi or Zero:
docker build --tag=flic .
For everything else, specify the ARCH_NAME argument with the relevant lowercase architecture name from balena base images.
For a Raspberry Pi 3 for instance:
docker build --build-arg ARCH_NAME=armv7hf \ --tag=flic .
To run Debian on an Intel NUC:
docker build --build-arg ARCH_NAME=amd64 \ --file Dockerfile-debian \ --tag=flic .
-
Run the project as an auto-starting container:
docker run --detach --restart=unless-stopped \ --net=host --cap-add=NET_ADMIN \ --name=flic \ flic
--net=host
gives the container access to the host's network devices, including Bluetooth.
--cap-add=NET_ADMIN
gives the container network privileges. -
Perform the pairing steps above β¬οΈ while inside the container:
docker exec -it flic bash
Other options exist, should you wish to try something else:
- The official Flic hub: Commercial solution, plug-n-play, supported. While it runs the same SDK as this balena project, it's likely a better solution if you have the money to spend.
- Flicd Hass.io addon by @pschmitt: for Home Assistant running on the HassOS stack. Requires exclusive access to Bluetooth antenna.
- Raspberry Pi 3 Docker image by @superkikim: based on Raspbian.
- Or this guy:
Want to suggest some Docker improvements? Got some fringe hardware that you used to run this balena/Docker container on and had to tweak some config for it to work? Fork this repo and open a pull request so that all can benefit! π
This Docker container is based on the Hass.io addon by Philipp Schmitt (@pschmitt) and uses the official Flic SDK by Shortcut Labs (@50ButtonsEach).
Don't forget to βοΈ this repo! π
Assembled with β€οΈ in MontrΓ©al.