Flic Home

    Community

    • Login
    • Search
    • Popular
    • Users
    1. Home
    2. ff0000wizard
    3. Posts
    • Profile
    • Following 0
    • Followers 0
    • Topics 2
    • Posts 4
    • Best 0
    • Controversial 0
    • Groups 0

    Posts made by ff0000wizard

    • RE: HTTP Home Assistant API

      After refreshing the entire process and starting over (including adding more fluff to my curl command)

      curl -k -X POST  -H "Accept-Encoding: gzip" -H "Authorization: Bearer SECRETTOKEN" -H "User-Agent: Google-HTTP-Java-Client/1.23.0 (gzip)"-H "Button-Serial-Number: SERIAL" -H "Button-Battery-Level: 53" -H "Button-Name: Flic2" -H "Timestamp: 2021-05-25T23:03:26Z" -H "Accept: */*" -H "Content-Type: application/json"-H -H "Cache-Control: no-cache" -H "Pragma: no-cache" -H "Connection: close" -d '{"entity_id":"input_boolean.flic2_singleclick"}' https://HOMEASSISTANT:8123/api/services/input_boolean/toggle
      

      To get almost matching posts (using a local netcat Listener on Port 8080 (ncat.exe can be found with nmap on windows installations)

      c:\PATH\TO\ncat.exe -l -p 8080
      

      867900f5-414f-46c8-a3dc-540c6745cdd6-image.png
      Somehow this last time around of starting all over from scratch worked, I can only assume that something was messed up in the Authorization header that was having issues (the string is so long you cant even see the delete button).
      I honestly have no clue why it is now working considering i've set up and deleted these api requests a couple times even with new tokens.

      For anyone who comes across this in the future or has issues/wants to integrate flic button HTTP requests to the Home Assistant API I will leave some notes. (this is running off a new install for a home-assistant VM).

      Configuration.yaml file:

      #flic v2 buttons
      input_boolean:
        flic1_singleclick:
          name: flic1_singleclick
          icon: mdi:checkbox-blank-circle
        flic1_doubleclick:
          name: flic1_doubleclick
          icon: mdi:checkbox-multiple-blank-circle
        flic1_hold:
          name: flic1_hold
          icon: mdi:clock
      input_boolean:
        flic2_singleclick:
          name: flic2_singleclick
          icon: mdi:checkbox-blank-circle
        flic2_doubleclick:
          name: flic2_doubleclick
          icon: mdi:checkbox-multiple-blank-circle
        flic2_hold:
          name: flic2_hold
          icon: mdi:clock
      

      Adding by Entity in the lovelace UI creates visible toggles and these can be used by Node-Red to trigger whatever you want (including MQTT messages or other triggers)
      2ae8eba4-a48d-49a2-8d04-e12af816ab0b-image.png

      Flic button Settings:
      Post
      URL: https://HOMEASSISTANTLOCATION:8123/api/services/input_boolean/toggle
      add a Header String with the following information
      Key: Authorization
      Value: Bearer LONGLIVEDAPITOKEN
      Body: {"entity_id":"input_boolean.flic2_singleclick"}
      Content type: application/json
      Timeout:10
      Validate Certificates: Toggle yes (do this only if using https with a valid cert and using FQSN/DNS)

      5948f05c-fdc6-4a70-aa7f-97957bd77f85-image.png
      d72e8df5-b7e1-4cfd-8314-f15fe4210fd6-image.png

      Here is an example on how to get that data into node-red and making changes for an example i am using the wled2 library to change to colors on a light strip.

      EXAMPLE NODE-RED :
      The Event State node is what is used to pull the boolean value. This leads into two change nodes that set the msg.payload to either red or green based on the boolean value of true or false. (also included are 2 Debug nodes to make sure the msg.payload actually changed before it hit the switch). This leads to a switch node that sends a signal based on the msg.payload being either red or green. If red it uses the WLED2 library to set the lights to red.
      be860fd5-0054-4026-95d9-92794674776c-image.png
      90531b56-b326-47d3-bbe5-0f9be3549b05-image.png
      bbf30d24-defb-482d-857a-30692297c77e-image.png
      021dc018-147b-43e7-a661-73e54c10126c-image.png
      b1341bd7-0e45-482c-8c82-6529441010c7-image.png

      posted in Flic Hub
      ff0000wizard
      ff0000wizard
    • HTTP Home Assistant API

      I am trying to get the Flic button (via the hub) to work with the home assistant api via the http request but the flic hub seems to be sending the header data incorrectly making authentication fail.

      Here is the curl that works:

      curl -k -X POST -H "Authorization: Bearer ACTUALTOKEN" \
      -H "Content-Type: application/json" \
      -d '{"entitiy_id":"input_boolean.flic2_singleclick"}'  \
      https://HOMEASSISTANT:8123/api/services/input_boolean/toggle
      

      4acedfaa-e7ad-4292-a867-c933207a0616-image.png
      This toggles an input_boolean called flic2_singleclick

      So far so good, but when I try to do the same thing using an http request via a flic button and using the hub it fails to auth. (The IP when attempting is NOT banned).
      8cf15f28-9d26-4235-9524-7efc73cca08e-image.png

      da34c1ed-c0a9-446b-a8e8-6909a1e3b7fb-image.png
      5ee9b7b0-4291-441a-9489-10164548a3c4-image.png

      The Authorization field is exactly the same for both the curl and the flic post request. I copied the raw data being sent and hashed them and they are exactly the same
      Top is the Curl request, bottom is what Flic sends
      e0c18192-4970-41b6-aae5-784ebc470aa1-image.png
      Anyone have any ideas/thoughts? There are no extra spaces or locations. The raw data being sent under authorizations for my long lived bearer token hashes to exactly the same. I can get this working via curl but not working via flic, something thats added or changed via flic is causing the authorization to not work.

      posted in Flic Hub
      ff0000wizard
      ff0000wizard