Time to cook: 120min
Difficulty: +++++
The Flic BLE buttons are great as a retrofit solution within your existing home. People still like a physical button or switch to actuate something. Unless you are able to rewire your existing switches in your home making use of some sort of PLC (see recipe about the controllino) The Flic BLE buttons might be an ideal solution, as they do not require any wiring and can last for months on a small coin cell battery. The new gen BLE 5.0 Flic buttons have enough range for an average home to be handled from one central gateway.
Ingredients
BLE Flic Buttons (www.flic.io)
A raspberry Pi
Prerequisites
Installing Node-RED
Tools
Nihil
Intro
We covered the Bluetooth protocol in chapter 3 and highlighted the BLE Flic buttons in chapter 4. In this recipe we will use the Raspberry Pi as a gateway for the Flic Buttons and use them within our connected home set up.
Flic has released his own HUB (the Flic HUB) in 2019. Although the HUB works fine with the pre-configured channels, such as for the Sonos. The HTTP integration which i wanted to use for my system-of-systems architecture did not work in my set up.
After scrolling through the different forums out there, it seemed I was not the only one having troubles with HTTP requests which need some kind of authentication. But in my research for a solution I bumped into their SDK.
This SDK has been revamped (they got rid of the unstable Bluez bluetooth stack). I also discovered that there is actually a Node-RED version available, which was a breeze to set-up.
This recipe will use the same Raspberry Pi we used for the Smart HUB, but you can opt to install this on a seperate Raspberry Pi. A recipe on how to do this and connect it using MQTT to AllThingsTalk Maker can be found here.
The Building Plan
Install the Flic node
As mentioned above, there is a Node-RED implementation available for the BLE Flic button. We will use the Smart HUB and the Node-RED environment, covered in previous recipes in this cookbook to start from in this recipe.
Login to the Node-Red environment by using your browser. The Node-red interface is accessible on port 1880
http://<your Pi IP address>:1880
You should see the following interface:
Note: If you are not familiar with Node-RED, this series of youtube videos give a good introduction. Of course you can also go to the official Node-RED website.
This is a Node-RED node to interact with the flic.io BLE buttons
In the menu (Top right corner), select manage palette
Click the install tab and search for node-red-contrib-flic-buttons
Select the correct package and click install
If everything went well, you should find the node in the nodes list on the left side
Installing the Flic Daemon
This node requires the fliclib-linux-hci daemon to handle the low level communication with the buttons. You will need to install this before you start:
Login to your Pi using an SSH connection
Enter the following commands:
sudo apt install git
sudo git clone https://github.com/50ButtonsEach/fliclib-linux-hci.git
cd ./fliclib-linux-hci/bin/armv6l
sudo ./flicd -f flic.sqlite3
The last instruction will start the Flic daemon manually. The Flic Daemon needs to run in the background to listen to the BLE payloads, so it would be better to run it at startup:
sudo nano /etc/rc.local
Add the following line just before the exit 0:
sleep 10 && /home/pi/git/fliclib-linux-hci/bin/armv6l/flicd -d -l /var/log/flic.log -f /home/pi/git/fliclib-linux-hci/bin/armv6l/flic.sqlite3 &
Reboot your Raspberry Pi to verify if the daemon starts automatically at boot.
Login to your Pi using an SSH connection
Enter the following command:
ps -ef | grep "flicd"
You should see a process running as root called:
/home/pi/fliclib-linux-hci/bin/armv6l/./flicd -d -l /var/log/flic.log -f /home/pi
Pairing Buttons
Buttons need to be paired before you can use them. We do this using the scanwizard.js located in the lib folder.
Ensure that the daemon are running
Ensure that any phones or other devices that your flic buttons were previously paired with are switched off or have bluetooth disabled
cd .node-red/node_modules/node-red-contrib-flic-buttons/lib
node scanwizard.js
press your flic button
If it has previously been paired to another device you will have to hold the flic button down for 7 seconds to put it into public mode
You should see something like this:
Welcome to the add new button wizard. Press your Flic button to add it.
Found a public button. Now connecting...
Button 80:e4:da:76:e1:2f successfully added!
once paired take a note of the bluetooth address
repeat this for all your flic button noting down the address for each button
Using The Flic Button to trigger something
Let’s create a sample Flow in Node-RED to output the message coming from the Flic Button.
Drag the Flic node on the flow
Drag a debug node o the flow and connect it with the Flic node
Edit the Flic button and configure the button
copy the button address discovered from the previous step
The flic node can distinguish several events from the Flic button, such as Single click,double click, hold, button Down and Button Up. Select one of the events in the node.
Deploy the solution
When you press the Physical Flic button, a similar debug information as the one below should appear in the debug window
The Flic button is now connected as a thing on your Smart HUBand can be used for various purposes. For example, you can use the button to turn on a light, select a radio station or as an alarm button to name a few...
Komentar