So I’ve received a Flic Twist early and wanted to give it a spin (pun intended) with Home Assistant.
As the twist mechanism only works with IKEA Dirigera, Hue, LIFX and Sonos as of right now, I had to turn a few stones to get it working with Home Assistant. Here’s what I did:
Summary
- Set up the Flic Twist together with the Flic Hub Mini
- Create a dummy light in Home Assistant
- Set up an emulated Philips Hue Bridge, diyHue, and connect it to Home Assistant
- In the Flic app, connect to the dummy Hue bridge and set up Twist to adjust the brightness of the virtual light
This guide assumes Home Assistant and diyHue runs as docker containers and that you’re a bit familiar with Docker Compose.
Set up the Flic Twist together with the Flic Hub Mini
This should be fairly straightforward, just follow the instructions included with the Flic Twist.
Create a dummy light in Home Assistant
We’ll set up a dummy/virtual/fake light in Home Assistant for the Flic Twist to control. In your configuration.yaml file, add something like this:
light:
- platform: template
lights:
flic_twist:
friendly_name: Flic Twist
turn_on:
turn_off:
set_level:
While it looks wrong you can safely omit the values of turn_on
etc, or if you want create a script that does nothing and use that above,
Set up diyHue and connect it to Home Assistant
Now here is where it gets a bit tricky. Hue bridges need to be exposed on port 80 but that clashes with other stuff on my Synology NAS. To circumvent this we’ll create a macvlan network which will make diyHue show up with it’s own IP address on your network.
Check for potential IP conflicts
Open the admin view for your router and check if there’s any range of IP addresses that is safe to use. To be on the completely safe, edit your DHCP settings so that your IPs only goes from e.g. 192.168.1.2 to 192.168.1.239 and then you save 192.168.1.240–192.168.1.255 for diyHue and any other potential docker containers you would like to setup the same way.
Install diyHue
In your docker compose file, add the following:
services:
home-assistant:
container_name: home-assistant
image: homeassistant/home-assistant:latest
network_mode: host
# ...
diyhue:
container_name: diyhue
image: diyhue/core:latest
networks:
10_diyhue_network:
priority: 100
ipv4_address: 192.168.1.242
20_internal: ~
volumes:
- /yourDiyHueConfigFolder:/opt/hue-emulator/config
restart: unless-stopped
privileged: true
mac_address: D6:49:C9:22:BB:34
environment:
- TZ=Europe/Berlin
- MAC=D6:49:C9:22:BB:34 # Make sure this is same as mac_address above
- IP=192.168.1.242 # # Make sure this is same as ipv4_address above
networks:
10_diyhue_network:
driver: macvlan
driver_opts:
parent: eth0
ipam:
config:
- subnet: 192.168.1.0/24
gateway: 192.168.1.1
ip_range: 192.168.1.241/28 # diyHue IP must be within this range
20_internal:
driver: bridge
ipam:
config:
- subnet: 172.18.0.0/30
gateway: 172.18.0.1 # This makes HA available on 172.18.0.1:8123
So what’s going on here?
- This will expose diyHue on
192.168.1.242
, make sure to update both two places above if this needs to be changed - The MAC address is just a random MAC created using a random MAC generator
- The
ip_range: 192.168.1.241/28
specifies what IP addresses should be available for the macvlan network, in this example IPs from192.168.1.241
to192.168.1.254
. If you want a more narrow range, try changing the/28
to/30
, i.e. an IP range of192.168.1.241/30
will only consist of192.168.1.241
and192.168.1.242
. Use an IP calculator to find an IP range that suits you. Important! The IP address chosen for diyHue must be within this range. - The second network,
20_internal
, is for diyHue to be able to talk to Home Assistant. This is because when setting up a macvlan network, containers on it can’t easily access other stuff on the same host easily. Thanks to this GitHub comment for figuring out this simple solution.
When done, run docker-compose up -d
to start up diyHue and the networks. If you encounter an error at this point it’s likely that the IP you chosen for diyHue or the IP range for the macvlan is already taken on your network so try changing to other values.
Connect diyHue with Home Assistant
If everything went fine you should now be able to access diyHue on http://192.168.1.242
.
- Click HA in the side menu.
- Edit the settings:
- Enabled: true
- Home Assistant IP: 172.18.0.1 (the same you set your bridge network gateway to)
- Home Assistant token: in Home Assistant, click your name and create a long-lived access token then enter it here
- Included by default: true
- Enable HTTPS: false
- Click Save
- Restart diyHue:
docker-compose restart diyhue
- From Lights in the side menu, click Scan for lights. Be patient, this takes some time and there’s no progress bar showing you what’s going on.
If all went well you should be able to see Flic Twist (your virtual light) in diyHue, as well as any other lights you have in HA:
Connect Flic Twist with the dummy light
From the Flic app:
- Set Twist (or Push Twist) to control brightness
- Choose Philips Hue under devies
- Click the circled arrow to search for bridges, the diyHue bridge should then appear with the MAC you chosen as its name, click it.
- When asked to “press the link button on the bridge”, go to the diyHue webpage,Link Button in menu and then press LInk App
- Go back one step and your Flic Twist should now appear here. Select it and then save.
Congratulations! If all done correctly you could now use your Flic Twist to control anything your imagination and Home Assistant will allow you to
Examples
I’ll try to collect some example of what you could do with this here.
Control Spotify volume
Given you have the Spotify integration installed in Home Assistant, change your template light code to this to be able to control the volume using your Flic Twist:
light:
- platform: template
lights:
flic_twist:
friendly_name: Flic Twist
turn_on:
turn_off:
set_level:
service: media_player.volume_set
target:
entity_id: media_player.spotify
data:
volume_level: "{{ (brightness / 255 * 100)|int / 100 }}"