Flic Hub SDK -> Web Hook (step by step)

Hi - should this work with the flic twist?
I can see it is sending push button events, but not sure it is picking up any twist events?

No HubLR SDK support for the twist action yet :frowning:

Message malformed: required key not provided @ data[‘action’]

Sorry for beeing a spamming useless noob :slight_smile:
But I copied the code exatly and even called the button “button1” but I get the error message shown on the top.

Can you post the file that you put the code into, there is probably a YAML formatting problem.

I’m having exactly the same issue when I try saving the automation. Here’s the YAML code I pasted into the new automation window:

automation:
  - id: flichub_click_webhook
    alias: Flic button events from Flic Hub - Webhook
    mode: parallel
    
    description: >
      Flic Button commands from flic hub
      Receive as Webhook

    trigger:
      - platform: webhook
        id: "flic"
        webhook_id: abcd1234-flic
  
    variables: 
      button_name: "{{ trigger.json.button_name }}"
      click_type: "{{ trigger.json.click_type }}"

    action:   
      - choose:
          - conditions: "{{ button_name == 'button1' and click_type == 'click' }}"
            sequence:
              - service: counter.increment
                target: 
                  entity_id: counter.button_1_clicks
          
		  - conditions: "{{ button_name == 'button1' and click_type == 'double_click' }}"
            sequence:
              - service: counter.increment
                target: 
                  entity_id: counter.button1_double_clicks

When I try to save, it generates the error:
Message malformed: required key not provided @ data[‘action’]

If you are pasting it i to a new automation it probs it doesn’t need the

Automation:

Line at the top.

That is there because I use “packages” to manage my yaml.

Try removing it.

Hi Bruce
Thanks for these instructions. I created an automation with your coding but home assistant changes it to

alias: Flic button events from Flic Hub
description: Flic button commands Receive as Webhook
triggers:
  - webhook_id: [mywebhook]
    trigger: webhook
    allowed_methods:
      - POST
      - PUT
      - GET
      - HEAD
    local_only: false
    id: flic
actions:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ button_name == 'Office' and click_type == 'click' }}"
        sequence:
          - action: light.turn_on
            metadata: {}
            data:
              brightness_pct: 100
              kelvin: 6500
            target:
              entity_id: light.bedroom_office_light
      - conditions:
          - condition: template
            value_template: "{{ button_name == 'Office' and click_type == 'double_click' }}"
        sequence:
          - action: light.turn_off
            target:
              entity_id:
                - light.bedroom_office_light
            data: {}
variables:
  button_name: "{{ trigger.json.button_name }}"
  click_type: "{{ trigger.json.click_type }}"
mode: restart

and the automation is not triggered. Can you provide any pointers?

Did you create the code on the flic hub to send the webhook ?

Yes, when I click my button the flic hub SDK console reports that the webhook has been sent

// main.js
var buttonManager = require("buttons");
var http = require("http");
var url = "http://[home assistant url]:8123/api/webhook/[webhook1]";
var url2 = "http://[home assistant url]:8123/api/webhook/[webhook2]-";

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("request status-1: " + res.statusCode);
	});
	
	// sends a 2nd seperate 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: " + url2 + button.name);
		console.log("sent: " + button.batteryStatus);		
		console.log("request status-2: " + res.statusCode);
	});	
});

console.log("Started");

Hi Bruce, the console reports

Started
sent: http://[home assistant url]:8123/api/webhook/[webhook2]-Office
sent: 93
request status-2: 200
request status-1: 200

so the Flic Hub part is working. The only reason I can think of why this wasn’t working for me is that I had created the automation in the UI. I’ll try coding it exclusively in automations.yaml and see if I get success

You could try:

A webhook debugger.