Direct Flic Button via Flic Hub MQTT integration - Cloudless

The last time I restarted HA, it appeared to persist. I don’t know what to tell you at this point! I’ll keep an eye on it

I added this to MQTT.js and it resolved the auto discovery issue every time I rebooted my HA machine.

MQTT.on('disconnected', function() {
MQTT.on('error', function() {
  setTimeout(function (){
  }, 1000);

Sorry for slow reply. This worked perfectly! Thanks

Thanks! I’ve added it to the Git repo!

This is great info and I am so grateful for everyone’s support. Something I noticed is that if I have the below added to mqtt.js…

MQTT.on('disconnected', function() {
MQTT.on('error', function() {
  setTimeout(function (){
  }, 1000);

I get the following error

ReferenceError: identifier ‘mqtt’ undefined
at [anon] (duktape.c:81026) internal
at [anon] (root/MQTT/mqtt.js:588) preventsyield

If I remove it it seems to work fine. Any advice would be greatly appreciated as I restart my HA somewhat often. Of note, line 588 for me is


Also not sure if my MQTT is seeing my devices. To confirm, my username is mqtt-user and I put

var username = ‘mqtt-user’;

Same format for the password. I’m very new to this, as I’m sure you can tell. Thanks again for the support.

I am getting the same error as well.

I think this code may need to be added into main.js instead?

@Ingo @heroash88 Can you confirm?

Happy to say I fixed the first part of my issue. Now just dealing with the power setting error.

Oops. It’d be nice if the SDK would talk to Git directly so I don’t have to make changes correctly in one place and then screw them up when updating Git!

Fixed. I updated the the Github code - could someone give it a go and see if I did better this time?

That worked! Thanks for the quick work.

I’m running into an issue with HA though. I can see the button though MQTT, and I can choose it as a device when creating an automation. The problem is when I choose it as a device under Trigger, the trigger option below the “Device” option is greyed out. Any advice would be appreciated. Very new to this. Sorry for the constant questions.

When I open the YAML code for the trigger, this is what I see:

device_id: c6285cefb94clkbbad4d594a0e32acd8
platform: device
domain: ""
entity_id: ""

I feel so close!

Hmmmm… I see. I’ve never actually used the Device as the trigger.

I use the Entity Trigger:

alias: Office Flic
description: Toggle office lights
  - platform: state
      - sensor.office_flic_flic_button
      - sensor.bob_flic_button
    to: click
condition: []
  - service: light.toggle
      color_temp: 350
      transition: 3
      area_id: office
mode: single

I’ll have to see why it doesn’t register properly as a Device… Hopefully I can suss it out on

That worked!! I am up and running. Thank you to all for the help along the way.

This is so good! I have been waiting for this for several years! I was mention this on facebook to the Flic team to add MQTT function to there Flic hub and they sent me a link to a page they have about MQTT and also a github repository for MQTT function. Maybe some inspiration for your setup? GitHub - 50ButtonsEach/flic-hub-sdk-mqtt-js
And the Flic page about MQTT:
Flic MQTT | Flic Smart Button

Today, when I logged into my Home Assistant instance, I saw a repair suggestion:

Do we need to make any changes to main.js?

Running into the same problem. None of my buttons work anymore and I will fully admit I’m not confident enough to start adjusting things on my own.

Ah, did you upgrade to Home Assistant 2023.8? I always wait for the .1 release before upgrading, since I only have my production system. So this is definitely not tested on 2023.8 yet.

The release notes mention breaking changes in MQTT … so maybe back out to 2023.7 until that can be addressed.

I’ll try to get to it this weekend.

Interesting, I haven’t upgraded to 2023.8 yet… and yet mine stopped working, too.


So, on mine it seems like maybe Flic updated something?

The script had been stopped and the “Restart after crash” checkbox was unchecked… and I’m 100% sure I had it checked. Starting it again on my Flic hub (and rechecking the box) made it all work again.

1 Like

I stopped and restarted my Flic Script and also restarted Home Assistant. That got it working again.

this is awesome (or will be when i get it working)

how do i find out my server name? is it “core-mosquitto” ? - at the moment it says “Cannot push beyond allocated stack”

And then how do i get my MQTT server to find the flics?


Got it working thanks to @heroash88

New version released thanks to git contributions! Thank you mikevostrikov and alexander-cato!

What’s Changed

  • Added current state sensor + other improvements by @alexander-cato in #5
  • Strip sensor names off the device name prefix; better error handling by @mikevostrikov in #6