Flic Button Home Assistant Controller
A node.js module to control Home Assistant entities via Flic smart buttons.
Prerequisties
- At least one Flic button (multiple are supported and can control discrete services)
- Home Assistant
- The
flicd
daemon from Flic's Linux SDK running somewhere accessible to the device running this script
Install
git clone https://git.ethitter.com/open-source/flic-button-home-assistant-controller.git
cd flic-button-home-assistant-controller
git submodule update --init --recursive
npm install
flicd
Preparation
If flicd
and this script are not run from the same device, ensure that flicd
is started with the -s
flag set either to 0.0.0.0
or the IP of the device running the controller.
Configuration
- Register Flic buttons with
flicd
and note the Bluetooth MAC addresses of the various buttons - Rename
config-sample.json
toconfig.json
. Update its values to match your configuration, including the buttons discovered in the last step. - Start the listener with
npm start
.
FAQ
Can I run flicd
as a daemon/at startup?
Yes. See https://ethitter.com/p/9738/ for a systemd
service file.
How is the buttons
property of config.json
structured?
Each object within the buttons
property is structured according what effect the click should have on an entity in its current state. For example, if the light is off, what should a single-click do.
"mac": {
"mac": "mac",
"label": "Lamp",
"status": {
"entity_id": "switch.lamp"
},
"single": {
"on": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_off"
},
"off": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_on"
}
}
}
The above example simply switches a light on and off, depending on its current state. There can be any number of state entries in an individual button's object, however. A button could be configured only to respond to the "on" state by omitting the "off" entry, or if the entity returns other states, those could also be handled. An example of this comes when interacting with Smart Home Assistant, which has three states:
"mac": {
"mac": "mac",
"label": "Smart Home Monitor",
"status": {
"entity_id": "alarm_control_panel.shm"
},
"single": {
"disarmed": {
"entity": "alarm_control_panel",
"entity_id": "alarm_control_panel.shm",
"entity_action": "alarm_arm_home"
},
"armed_home": {
"entity": "alarm_control_panel",
"entity_id": "alarm_control_panel.shm",
"entity_action": "alarm_disarm"
},
"armed_away": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_on"
}
}
}
In this example, if the alarm isn't active, or is set to the "armed home" state, its Flic button will toggle between those states. If, however, one tried to use the button to disable the alarm when no one is home (motion sensors are active, among other changes), the button will simply turn on a light; it won't disarm the alarm, as that's something I only allow for those who have access to Home Assistant or SmartThings directly.
As three click types--single
, double
, and hold
--are supported, adding responses to the new click types is a matter of updating config.json
to define how those clicks are handled.
"mac": {
"mac": "mac",
"label": "Lamp",
"status": {
"entity_id": "switch.lamp"
},
"single": {
"on": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_off"
},
"off": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_on"
}
},
"double": {
"on": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_off"
},
"off": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_on"
}
},
"hold": {
"on": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_off"
},
"off": {
"entity": "switch",
"entity_id": "switch.lamp",
"entity_action": "turn_on"
}
}
}
This isn't a particularly interesting example, as all three click types perform the same action, but it demonstrates what's possible.