Skip to content
Snippets Groups Projects
Erick Hitter's avatar
Erick Hitter authored
Nice that there's a proper example now, too.
85734809
History

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 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

  1. Register Flic buttons with flicd and note the Bluetooth MAC addresses of the various buttons
  2. Rename config-sample.json to config.json. Update its values to match your configuration, including the buttons discovered in the last step.
  3. Start the listener with npm start.

FAQ

Can I run flicd as a daemon/at startup?

Yes. See https://ethtiter.com/ for a systemd service file.

How is the buttons property of config.json structured?

Each object within the buttons property is structured according to how the button should respond to the entity's current state. For example, if the light is off, what should a button press do.

"mac": {
	"mac": "mac",
	"label": "Lamp",
	"status": {
		"entity_id": "switch.lamp"
	},
	"off": {
		"entity": "switch",
		"entity_id": "switch.lamp",
		"entity_action": "turn_on"
	},
	"on": {
		"entity": "switch",
		"entity_id": "switch.lamp",
		"entity_action": "turn_off"
	}
}

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"
	},
	"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.