At some point in your home automation journey, you will want to trigger events for something that doesn’t have a switch, or button in your home. One example of this would be controlling Spotify from something other than your phone, with something like a Flic – Smart Bluetooth Button.

The cool thing about Flic buttons is that they’re battery powered and you can put them anywhere as long as you have a flat surface to stick them to. For home automation, the downside is that they’re Bluetooth which limits how far away from your receiver you can place them. Flic says their buttons have a range of 150 feet. In my experience that depends up on the strength and class of your Bluetooth receiver. More on that later.

Once you’ve gotten your hands on a few buttons, you’ll need to choose what method you’d like to receive the Bluetooth LE signal they fire off. Home Assistant doesn’t currently have a first class integration for Flic. They do have a Flic component, but it relies on also running Flic’s software to receive and relay the event. Flic gives you a few different options that will work for home automation, the Flic Hub, their Hax with Flic Mac application and their Flic SDK for Linux.

Flic Hub

I haven’t worked with the Flic Hub, but it is supposed to have similar functionality to Hax with Flic that allows you to create your own scripts. The Flic Hub may be your easiest path since it gives you always on hardware and no software to install. The Flic Hub wasn’t available when I created my setup. If I were to start over today, I would probably give it a try.

Hax with Flic

I’ve had success with Hax with Flic, but it requires your Mac to be running to receive the event. So if you shut down your computer, or it’s a laptop that you take with you, this option may not be the best if you live with other people. The application is pretty minimal, it runs in your menubar and allows you to pair the buttons to your Mac and to associate scripts to each button.

The scripts you create for Hax with Flic can be AppleScript, or shell scripts. I chose to go with shell scripts so I can use simple cURL commands to trigger events through Home Assistant’s Rest API. Each button has three possible events, single press, double press  and hold . You will need to create a script for each event type, for each button. If you’re using two buttons, that’s six scripts, but the scripts are the same, with minor modifications. Here’s what they look like:

This is a standard cURL statement for triggering something using the Home Assistant Rest API. Here’s what’s happening:

  • curl -X POST -H "x-ha-access: API_PASSWORD_HERE"  initiates the cURL command and passes along your API password to Home Assistant so that it knows it’s receiving a valid command.
  • -H "Content-Type: application/json"  informs Home Assistant that it is receivng JSON data, which is what the Rest API expects.
  • -d '{"entity_id": "script.flic_kitchen_single"}'  informs Home Assistant that we intend to trigger a script file.
  • http://IP_ADDRESS_HERE:8123/api/services/script/turn_on  informs Home Assistant what service we want to use to trigger the script file.

In plain English, this script essentially says, “Hey Home Assistant, this is a legit request and I would like to turn on script.flic_button_single. Please and thanks!”.

It’s important to note that shell scripts are not executable unless you update their permissions to be so. To update the script’s permissions you’ll need to open a Terminal window, navigate to the directory you’re storing your scripts in and enter chmod u+x .

Once you have created all of the scripts you’ll need, everything else happens in Home Assistant. If you’re using your Flic buttons to control your music in Spotify, you can simply reference the names of the scripts we created in in the previous post.

Flic SDK for Linux

This is the path I have been running for the past year and it has worked reliably for me. The Flic SDK for Linux application as it says in its name, runs on Linux, so it can be installed on the same server as Home Assistant. If you are not comfortable the command line and connecting to remote computers, this is probably not the right option for you. They also have what look to be similar options available on OS X and Windows if either of those is your server OS of preference.

Installing the SDK

Everything on my home automation server is run inside Docker containers, so naturally I wanted this to also. It was a bit difficult back when I was setting this up to track down an existing Docker image, but I eventually managed to find this one and it has worked well for me. The settings for it are pretty simple, here’s how I create the container.

Connecting the Buttons

Once the SDK is installed, you’ll need to compile the application and pair your Flic buttons. This part gets a bit technical, so if you get stuck, I suggest looking at Flic’s quick start instructions. They include additional information that could be useful for debugging.

  1. On the server, or the Docker container you installed it on, navigate to the simpleclient  directory and compile the directory using make. To do so, simply type make  and press enter. It will scan the directory for what it needs and run on its own.
  2. Run the utility by typing ./simpleclient localhost  and pressing enter.
  3. To add a button, type startScanWizard and press enter. The utility will start listening for new buttons.
  4. Press your Flic button (making sure that it isn’t still connected to another device) and follow the instructions in the console.
  5. After your button has been added, type connect <BDADDR> <id> , where <DBADDR>  is the address that appeared during the scan, and for <id>  use any unqiue number that you haven’t previously assigned to a button. It will be used later if you decide to remove the button.

Configuring Home Assistant

The easiest part of using the Flic SDK for Linux is configuring Home Assistant. If you installed the SDK on the same server, this is all you need to add to your configuration.yaml  file. Once added, reload your configuration file, or reboot Home Assistant. Each Flic button will show up as a binary_sensor  in Home Assistant.

If you installed it on a different server, changed the port, or want to ignore any events, check out Home Assistant’s documentation for the Flic Smart Button for more configuration options.

Connecting Button Events to Scripts

Great! I have button events, and I have scripts to control Spotify (if you’re coming from the previous post), how do I make them talk? We will be achieving this through automations in Home Assistant. Here is an example automation for the single button press of a Flic button in the kitchen.

In this automation there are three things you can configure.

  1. The button_name  corresponds to the Flic button. You can find the entity_id  of your button in the HA dev tools, just use the part after the period following binary_sensor .
  2. The click_type  represents which one of the three click/press types. The options are single , double  and hold .
  3. The entity_id  refers to the script that you want to run when the button and click/press type you have configured is triggered.

Choosing Your Bluetooth Hardware

If you are working with a server that does not have Bluetooth built in, like I was, you will need to enable it with Bluetooth super powers. The easiest way to do that is to buy a USB Bluetooth dongle. Flic offers a list of Bluetooth devices they have tested the SDK with. The list is a bit confusing, and there are topics they don’t touch on, so here’s some info that will help you make your decision.

Concurrent vs Pending Connections

It is not necessary to get a device that has as many concurrent connections as you have Flic buttons. Concurrent connections refers to how many buttons can communicate with the Bluetooth devices at the exact same time.

Say you have a BT device that supports three concurrent connections and you have three buttons. If you press all three buttons at the exact same time, they will be able to talk to the device at the same time

Say you have the same BT device that supports three concurrent connections, but you have five buttons, and you were to press all five at the exact same time… you have five fingers, it’s possible… that’s where pending connections come in. Two of your events would be queued up in a line and executed as space frees up. These events are quick, so having to wait in line isn’t a big deal.

Class 1 vs Class 2 Bluetooth Devices

Bluetooth is a short-range wireless technology, so when it comes to home automation you want to get as much range as possible. There are two types, class 1 and class 2. Class 1 can stream up to 300 feet and class 2 up to 30 feet. Those numbers are “line of sight” and your home has walls and other obstructions. Realistically you can expect 150-240 feet from class 1 and 15-30 feet from class 2.

Class 2 devices are good for close range devices, like Bluetooth mice. You’ll want to select a class 1 device. I didn’t know this when I purchased my first Bluetooth adapter and went with the Plugable USB device from the top of Flic’s list. The specs sounded good to me, but after connecting my Flic buttons, I couldn’t be very far away from the server and have them still work.

I contacted Flic’s support team and they said out of the devices they tested, the Sena Technologies Parani-UD100-G03 gave them the best range. However, that device is a serial connection, not available on Amazon and over $100.

Ultimately I decided to go with a TRENDnet Low Energy Micro Bluetooth USB Adapter which has worked well for me.

Leave A Comment

Your email address will not be published. Required fields are marked *