Thank you so much for this. I just got my Flic hub and buttons today and ran through all this per your instructions. I got everything going except that the double click automation is not running. Single click does what it’s supposed to do; double click does nothing. I see in the HA automation trigger section that it is receiving the double click trigger input, but it’s not doing any action. Any thoughts? Also, what about the press-and-hold flic action? Thanks!
I have created a similar solution, with more front-end editing capabilities and only 1 webhook call at the flic hub level to update click_type and battery_level attributes. If you are interested, you can check it out here:
Great article but console output in main.js is not an accurate account (for newbies) of what is happening. Please consider replacing the code block with this one.
// main.js
// Webhook trigger fires when a web request is made to the webhook endpoint: /api/webhook/<webhook_id>.
var buttonManager = require("buttons");
var http = require("http");
var url = "http://192.168.xx.xxx:8123/api/webhook/abcd1234abcd123-flic";
var url2 = "http://192.168.xx.xxx:8123/api/webhook/efgh5678efgh5678-";
buttonManager.on("buttonSingleOrDoubleClickOrHold", function(obj) {
var button = buttonManager.getButton(obj.bdaddr);
var clickType = obj.isSingleClick ? "click" : obj.isDoubleClick ? "double_click" : "hold";
http.makeRequest({
url: url,
method: "POST",
headers: {"Content-Type": "application/json"},
content: JSON.stringify({"button_name": button.name, "click_type": clickType, "battery_status": button.batteryStatus }),
}, function(err, res) {
console.log("sent URL: " + url);
console.log("content: " + JSON.stringify({"button_name": button.name, "click_type": clickType, "battery_status": button.batteryStatus }))
console.log("request status-1: " + res.statusCode);
});
// sends a 2nd separate request to allow triggered template sensors to have battery status
http.makeRequest({
url: url2 + button.name,
method: "POST",
headers: {"Content-Type": "application/json"},
content: JSON.stringify({"button_name": button.name, "click_type": clickType, "battery_status": button.batteryStatus }),
}, function(err, res) {
console.log("sent URL: " + url2 + button.name);
console.log("content: " + JSON.stringify({"button_name": button.name, "click_type": clickType, "battery_status": button.batteryStatus }))
console.log("request status-2: " + res.statusCode);
});
});
console.log("Started");
Also could you add to next Create a home assistant automation the words in configuration.yaml or a more specific instruction, again for me. If this is actually where it goes - because I get duplicate key here!!!
Best Regards
I seem to see no action happening in HA i think it might be because of my SSL
Heads up I am going one step further and attempting to update a helper for each button.
I just purchased a new set of buttons. Would I add a new set of variables and a new webhook to the same module to allow for using multiple buttons or a new module for each button?
You don’t need to change or add anything.
The code sends the button name.
So it will just send new button names.
So in your automation that accepts the webhook you create a choose based on the value.
So enjoying this! I now have 9 active buttons controlling a myriad of things. One question. Is there a way to test battery levels (say at a certain time of day) automatically rather that physically pushing the buttons? It seems this shouldn’t be difficult but I can’t wrap my head around it.
They only transmit when you press the button.
The batteries generally won’t go down unless you are using the buttons.
So getting the battery level when they are clicked is more than enough.
Message malformed: required key not provided @ data[‘action’]
Sorry for beeing a spamming useless noob
But I copied the code exatly and even called the button “button1” but I get the error message shown on the top.