How to connect Flic Twist to Home Assistant on a Synology NAS

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 from 192.168.1.241 to 192.168.1.254. If you want a more narrow range, try changing the /28 to /30 , i.e. an IP range of 192.168.1.241/30 will only consist of 192.168.1.241 and 192.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.

  1. Click HA in the side menu.
  2. 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
  3. Click Save
  4. Restart diyHue: docker-compose restart diyhue
  5. 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:

  1. Set Twist (or Push Twist) to control brightness
  2. Choose Philips Hue under devies
  3. Click the circled arrow to search for bridges, the diyHue bridge should then appear with the MAC you chosen as its name, click it.
  4. When asked to “press the link button on the bridge”, go to the diyHue webpage,Link Button in menu and then press LInk App
  5. Go back one step and your Flic Twist should now appear here. Select it and then save.:tada:

Congratulations! If all done correctly you could now use your Flic Twist to control anything your imagination and Home Assistant will allow you to :slight_smile:

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

twist

5 Likes

Hmm… just a heads up that this solution is a bit unstable and flaky at best… occasionally twists will not be forwarded to Home Assistant :confused: Not sure if this is on diyHue, HA or the Flic Twist itself but I’ll update the guide if I find out anything.

Wow, great job on getting this working! I ordered a bunch of these trough kickstarter oblivious tot the fact that they would not work out of the box. will be trying your method and thanks for sharing. Hoping to see any updates if you have them.

Hey ! That sounds like a nice idea, but I’ve tried with the latest version of DiyHue (and even with HomeAssistant emulated_hue integration) but none of them worked :frowning:
I was able to add the fake bridge in the flic app, but when trying to control the brightness nothing happened…

Thanks for the idea anyway :pray:
I’ll try to tinker a bit more later…

Thank you for your post! I only found it once I’ve done almost exactly the same thing.
I tried other integrations and addons but only managed to get it work with diyHue.

And, I have exactly the same issue as you. This f***ing buttons randomly stop to send the commands to diyHue ONLY for the Twist events. It continues to work for the button pushes…

I see that because I use tcpdump on my Docker host to monitor what’s coming on the network with the source IP of the Hub.
tcpdump -i enp2s0 'tcp and src host 10.0.0.218'
I don’t have the complexity you have with macvlan, the port 80 and the others were free on my Docker host, so you can exclude things related to your specific setup.

I also have the original Hue Hub so I paired one button to a Hue Lamp on the Hub Hub, and another button to the diyHue hub with HA. Guess what, when the diyHue button fails to send twist commands I can still continue to change the dimming with the “official setup”.

When it works with dyeHue, I’ve also sync issues where the memorized position on the Flic Twist is “reset” so if I move the twist from 10% to 50 %, and 2 seconds after, I try to move it to 60%, it starts again from 10%.

I really don’t get why only the twisting fails only for diyHue, I’ve enabled Remote API and discovery, but it does not seem to help. Maybe this could be related to https://discovery.meethue.com/ and the equivalent https://discovery.diyhue.org/ and the app tries to use it but it fails and there’s a delay before falling back to the original IP.

By the way, here are my examples. I use an empty light template and I use an automation to sync its brightness with the fake light.

alias: Demo - Sync fake Flic Twist brightness with other things
description: ""
trigger:
  - platform: state
    entity_id:
      - light.flic_twist_1
    attribute: brightness
condition: []
action:
  - delay:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
    enabled: false
  # Set a cover position
  - service: cover.set_cover_position
    data:
      position: "{{ 100 - (trigger.to_state.attributes.brightness * 100 / 255) | int }}"
    target:
      entity_id: cover.volet_bureau_julien
  # Change a volume
  - service: media_player.volume_set
    data:
      volume_level: "{{ trigger.to_state.attributes.brightness / 255 }}"
    target:
      entity_id: media_player.mini_salle_de_bain
  # Change brightness of any light
  - service: light.turn_on
    data:
      brightness: "{{ trigger.to_state.attributes.brightness }}"
    target:
      entity_id: light.bureau_julien_grande_lampe
mode: restart

Depending on the automation, I recommend setting a slight delay before the action and set it in restart mode. To control my cover for instance, I don’t want each slight movement on the Twist to send a command to the cover. So I add a 2 seconds delay and then 2 seconds after the last movement, so the last request, the final command is set on the cover. This may be not necessary, or only with a few ms delay for volume and light. It depends on the ability of the device to handle lots of requests.

1 Like

I have similar issues, tried all Hue bridge emulations possible and can get the push button to work reliably but never the twist. Not even once, not for any light. Anybody else gotten more luck yet?

For me it looks like this:

  • Emulated Hue > Discovery works, no light is available in Flic though, although it is available in the API endpoints
  • DIYhue > Discovery works, Lights available, Push button works, no twist possible. Essential Hue app crashes on connection
  • HASS Emulated Hue > Discovery works, Lights available, button works, twist never works. Essential hue app works (mostly)

I was in contact with Flic support and they told me that they plan to add Matter support soon-ish (first half of 2024) but I would rather have a hacky solution now then wait that long.

Is it possible to make the template with a real hue light? So that the brightness value controls the volume off a media player? I could use a bulb behind the media player that follows the volume level in brightness

I have more or less the same question:

Would this work with a REAL Hue bridge. I.e. can I add a fake light to an existing real Hue bridge?

If so, that would maybe also fix the inconsistencies?

I think you could try an automation like this

alias: Sync volume with brightness
trigger:
  - platform: state
    entity_id: light.my_light
    attribute: brightness
condition: []
action:
  - service: media_player.volume_set
    data:
      entity_id: media_player.my_media_player
      volume_level: "{{ (trigger.to_state.attributes.brightness / 255 * 100)|int / 100 }}"
2 Likes

Incredible to see people jumping in to get this working…

I got my flic twist today and keen to implement it into home assistant, looking forward to seeing this progress!

I have a real Hue bridge here as well and can confirm that it does work in there. It could be a nice hack to have one of your lights on the bridge and the react to it with a script like above from @oscarb

EDIT: I am like 90% sure you can’t add a fake light to a real hue bridge but if anybody knows better I would be amazed

How do you add a fake light to your bridge via Home Assistant which also appears in other “works with hue” apps? (I.e. flic)?

Sorry I might have been unclear, hence the edit. I don’t think you can add a fake light to a hue bridge to use, but what you could do is to find the absolute cheapest zigbee bulb, extract the control board from it, power that up (minus the LEDs) and hide it somewhere. That seems very hacky and I think I would rather wait for Matter support by Flic

I confirmed with the support that the Twist Action requires the Hue V2 API. So that is the problem why it doesn’t work with any emulated Hue bridge. There is some work in the Hass Emulated Hue to get it done but it’s not yet part of the release. Willing to jump in there to test but yet have to discover how to get HASS to install from a branch.

Has anyone found a way to make these bricks work properly with HA?

The closest I had was with diyHue but it was too buggy.
I did not find a way to add a fake / virtual bulb to the official Hue Bridge. Even with that, I would not expect great experience from that with the possible lag.

The latest “news” from their forum is from October, 23rd.

Hi. The Hub SDK does not (yet) support the rotation event of the Flic Twist.

That’s the last time I back a Kickstarter project… I’ve learned the hard way the mantra: “Buy it for what it does, not what they say it will do” .

From the campaign page:


And even on the shop it says it supports Matter. Liars…

Apart from diyHue, Emulated Hue - HA and hass-enulated-hue I think I’ve found a fourth way to emulate a Hue bridge:

I haven’t yet had the time to try it out myself but will report back once I get around to it to see how well it works with the Twist.

I don’t have too much hope because it does not seem to support v2 from what I see in the Issues and based on the latest release date.

Latest update from Flic forums:

Emulated hue - Couldn’t get any devices to show in the Flic app (Due to being V1 only)

diyHue - Couldn’t get any devices to show in the Flic app - Possibly due to not being able to setup the emulaed bridge with the Hue app. Unsure why but the pairing/link doesn’t work

hass-emulated-hue - Had the most success, can add my lights to the Flic app using the emulated bridge. Can also turn the lights on/off, but not able to dim or change colours from Flic twist.

I’ve currently got 3 of these and a mini hub, which I’m feeling sorely ripped off with at the minute :frowning:

For those who are interested, I’m working on an alternative software for the Flic Twist based on BTHome v2 (flic-twist-bthome-v2) which directly integrates with Home Assistant instead of using the Flic Hub.

So far reverse engineered the HSI and peripherals (still have to create the schematics) and implemented a LED driver (PWM multiplexed). The original software is erased so there is no going back.

The weird thing is that the Flic Twist is based on the EFR32BG22 micro controller. This micro controller is Bluetooth only and as there is no such thing as Matter over Bluetooth (Bluetooth is only used during commissioning). Meaning that you will always need the hub once the Matter support update launches…

This is the reason why I’m creating the custom firmware (omitting the need of the Hub).

I’ll post updates when more progress is done :slight_smile:

Thank you so much for this :pray: