Direct Flic BUTTON via Flic Hub MQTT integration - Cloudless

If anyone is interested in using the Flic buttons with the Flic Hub but without cloud, I’ve got it working using their newish Flic SDK. This is basically a small bit of Javascript that runs directly on your Flic Hub which then connects to your MQTT network.

It supports MQTT Discovery, so your Flic buttons will appear as individual new devices, and it includes your Flic button battery level.

Let me know if you use this and if there’s anything else you can think of to add. (Right now you have to restart it when you add new buttons, but I’ll add something to do that automatically soon.)

I didn’t want to have yet another Bluetooth daemon running since I already have the Flic Hub, so this suits my needs. Your needs may differ and you may prefer using flicd on yet another Rpi.

Source code and very basic instructions at GitHub - id628/flic2hass: A Flic SDK utility to publish all Flic buttons to Home Assistant via MQTT

NOTE: The Flic SDK only supports Buttons. The Twist is not supported.



I was using the Flic hub SDK to trigger automations with webhooks (thanks to here and there), but using MQTT should be even better, thank you !

But I can’t get it connected with my MQTT. Could you tell exactly what to change in the Main.js file ?
I just changed variable “server” with the name of my MQTT broker “core-mosquitto”, but actually I don’t really know what I’m doing here…

1 Like

I see in the mqtt.js file that I should use “options”, with the host, username and password. But how do I pass it in the main.js ?
Sorry I don’t know anything about JavaScript…

1 Like

Got it working, I think…

1 - install the linked files in a module on the hub, there should be 2, mqtt and main, changing the mqtt server
2 - I think I needed to add in MQTT to my HA setup to get it to detect the flic’s on MQTT, is this right?
3 - Something odd happens, I had to restart the hub a couple times to get it to publish to the flic topic, but I cannot figure out why

Cool hack, I love it!

Glad to hear it, sorry I’ve been offline - on vacation for a bit.

I’ll try to update it when I return in a coupla weeks.

Hi folks - just giving this a whirl.

I have setup the module with both files. Its showing the button info int he console, but not sending any msgs. I added the mqtt broker ip in the server variable, but it isnt sending msgs (broker is recieving other msgs I have being sent so broker is working etc).

broker is using default ports, no username / pwd etc.

Any tips?


Try using the IP address of the MQTT server. It may not be getting your local DNS.

I updated the ReadMe a bit.

I’m also having some problems with it not working consistently, I sometimes have to restart my hub to get it to execute even though it’s set to do that automatically if it should crash…

This is a work-in-progress, but it’s making my Flic buttons useful again.

1 Like

thanks - already have the ip address actually…but not sending messages…assume I dont need to include the protocol, i.e. mqtt://, I just have: ‘var server = “”’

tried a restart of the hub a few times also but no success.

Ingo, you are a superstar!

I’ve had a Flic hub for an absolute age now, and have been bitterly disappointed in the fact that there’s no direct HA connectivity. The webhook options were a bit hit and miss, and very cumbersome to set up. But, a couple of teething troubles aside (like me using the wrong password for the MQTT server) I’ve managed to get three of these buttons recognised in MQTT, and one of them is now turning a light on and off!

Thanks for all your hard work. I’m now looking forward to those Flic Twists I bagged on Kickstarter finally turning up!

I’m tying to make this work and am not very good with java. This is the part I’ve changed in the script.
var server = (My server info);
var hatopic = “homeassistant (kept this the same)”;
var flictopic = “flic” (kept this the same);
var username = ‘mqtt-user’ (changed this to my user name);
var password = ‘XXXX’ (I put my password here);

var buttonManager = require(“buttons”);

var mqtt = require("./mqtt").create(server {‘username’:username,‘password’:password});

I didn’t adjust the mqtt.js file at all. I’m not very good at this. thank you for all the help.

Here is what worked for me using the instruction the amazing Ingo put together but adding a little more details in case someone find them useful or not sure what to change.

1- Go to
2- Create a new module and rename it to MQTT
3- Create two new files by or rename the default files to main.js and mqtt.js
4- Copy the code from the files main.js and mqtt.js from Github GitHub - id628/flic2hass: A Flic SDK utility to publish all Flic buttons to Home Assistant via MQTT
5- If your MQTT has a password. Edit the main.js using the below.

var server = “192.168.0.x”;
var hatopic = “yourMQTTusername”;
var flictopic = “flic”;
var username = ‘homeassistant’;
var password = ‘yourMQTTpassword’;
var buttonManager = require(“buttons”);

var mqtt = require("./mqtt").create(server,{‘username’:username,‘password’:password});

var myButtons = {}; //Dictionary of Button objects

you can replace the first lines, change the values between the quotes to:

  • var server is the IP address of your HA or MQTT server if different.
  • var hatopic, keep as homeassistant.
  • var username of your MQTT username that you can find in HA under Settings > Devices & Services > MQTT > Configure > Re-configure MQTT > copy the username and password from there
  • var password is your MQTT password you can get from step 3
  • keep var mqtt and var myButtons as is (just copy them)

6- Click the play button.
7- if everything works you should see a list of your buttons and some details. press it once and you should see the name and button details and the type of click.
8- Go back to HA and MQTT integration and search for “flic” and you should see all your buttons listed and use them from there in your automations. States are 'click", “double_click”, and “hold”.

It is a hit and miss and I also had to restart the module and the flic hub couple times. But it should work fine after that.

I hope this helps. Thanks Ingo again for the work. Very much appreciated.


Okay, I appear to have hit a snag…

If my HA instance restarts for any reason (such as an upgrade or the like) then this stops working and stays that way until I restart the module on the SDK. Which is okay if I’m at home, less so if I’m not (as I can’t log on to the Flic hub). I suspect this is because I’m running the MQTT broker from within HA.

It looks like the restarted MQTT doesn’t then discover the Flic hub, which I suspect is down to the hub itself mistakenly believing it’s already connected. We could do with a way of checking if the MQTT link drops and, if it does, poll until it comes back and then re-register.

Hmmm… I think maybe I need to add a retention flag to the registration MQTT messages. Otherwise, a new instance of HA won’t be able to see those.

Should be an easy fix. Gimme a day or two, I’m out of time to do any hacking today.

1 Like

@leopold005 Actually, I took a quick look and am sending “retain: true”.

Is it possible your MQTT broker isn’t honoring that? I’ll still try to take a look tomorrow, but that’s something to check on your end.

Hey - thanks for this, sounds perfect :slight_smile:

I think I followed everything, I have a single module call “MQQT” and in the folder “tree” I have “main.js” and “mqqt.js” copied from the repo.

I have adjusted the IP address only, and my MQQT allows anonymous so no need for user/pass.

I press the play icon and i get an error in the log showing “Error: Module not found” …

Error: Module not found
    at moduleNotFound (init.js:47)
    at require (init.js:124)
    at [anon] (root/MQQT/main.js:7)
    at require (init.js:131)
    at [anon] (init.js:139) preventsyield
    at runInit () native strict preventsyield
    at handlePacket (pipe_communication.js:48)
    at readCallback (pipe_communication.js:93) preventsyield

Not sure what I missed, seems it cannot find the mqqt JS file? I tried rebooting, code remains there but error still the same.

That filename should be mqtt.js, not mqqt.js

MQTT stands for Message Queueing Telemetry Transport - a real mouthful.

Doh! Pretty embarrassed… thanks!

So it worked as soon as I fixed my silly spelling error!

However I do not get the battery status in HA? It just stays as “Unknown”

Console log in the Flic shows it correct … any ideas?

|flic/AG45-C15282/action:   |click|
|flic/AG45-C15282/battery:  |21|

EDIT: Commenting out the “obj.device_class” line pushes the value to HA, but then its just a “value” and doesnt show properly as a battery :frowning:

No idea why it is not working when set as a battery.

Try changing this line:

	mqtt.publish(btntopic + "/battery", button.batteryStatus+"%");


	mqtt.publish(btntopic + "/battery", button.batteryStatus+"");

At one time, it seemed to want the percent symbol, but now it doesn’t. But don’t forget the empty string “”, since that causes the integer to string conversion to happen that it also seems to want.

The docs for the MQTT Auto Discovery are here: MQTT - Home Assistant - but unfortunately I’ve got a full load at the office right now and can’t really delve into it.

Let me know if that helps!