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"}'  \

    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).


    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
    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.

  • How do you find the response time using HA?

    I currently have a few FLIC buttons using Alexa integration to manage lights when we don't feel like talking to Alexa. The initial lag can be a few seconds, which while not horrible isn't instantaneous.

    Granted, it does take as long to say "Alexa, turn on the sink light" and have it illuminate as it does to click the button and have the light illuminate. Turning it off and on in the HA dashboard is instantaneous though.

  • 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

    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
        name: flic1_singleclick
        icon: mdi:checkbox-blank-circle
        name: flic1_doubleclick
        icon: mdi:checkbox-multiple-blank-circle
        name: flic1_hold
        icon: mdi:clock
        name: flic2_singleclick
        icon: mdi:checkbox-blank-circle
        name: flic2_doubleclick
        icon: mdi:checkbox-multiple-blank-circle
        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)

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


    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.

    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.

  • This post is deleted!

Log in to reply