AutoWeb LIFX

Discussion in 'AutoApps' started by tismondo, Sep 12, 2016.

  1. tismondo

    tismondo New Member

    Joined:
    Sep 1, 2016
    Messages:
    6
    Likes Received:
    0
    Having settled my Harmony confusion, km now trying to get my LIFX bulbs to work.

    I can't find how to authenticate in autoweb using my LIFX token. (I have one)

    The harmony api asked me to authenticate as soon as I added the API to autoweb; LIFX doesn't seem to do this.

    Would appreciate any help!
     
  2. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Can you try long-clicking the API in AutoWeb -> scroll down -> fill in the Username and Password fields with your own values. Thanks
     
  3. tismondo

    tismondo New Member

    Joined:
    Sep 1, 2016
    Messages:
    6
    Likes Received:
    0
    Hm, when using the LIFX API in the past with another connected service (IFTTT) it did not require a user/pass to connect. Just a manually generated token.

    At any rate, I just did the following:

    Open autoweb > long press LIFX API > Edit API configuration > scroll down to section "User and Password Specific" > entered my credentials for the LIFX cloud API (which I note are written in plain text)

    Next, I created a test task in tasker using Autoweb to "list lights", and get errors

    Code (Text):
    04.04.33/ActionArgBundle key: JoinOutputArray: replace <null> String value with null
    04.04.33/E FIRE PLUGIN: AutoWeb Web Service / com.twofortyfouram.locale.intent.action.FIRE_SETTING: 14 bundle keys
    04.04.33/E AutoWeb Web Service: plugin comp: com.joaomgcd.autoweb/com.joaomgcd.autoweb.broadcastreceiver.BroadcastReceiverFire
    04.04.33/E add wait type Plugin1 time 120
    04.04.33/E add wait type Plugin1 done
    From autoweb log:

    Code (Text):
     version 0.0.30b

     OS Build NRD90U
     OS Code 24
     Device Nexus 6P
     Manufacturer Huawei
     Product angler

    Api Calls - 2016-09-13 04:08:33.016 - Calling GET: https://api.lifx.com/v1/lights/all
    And finally, the autoweb action error notification says

    Code (Text):
    {"error":"Invalid token"}
    Which makes me believe I do need to use a token somewhere.
     
    Last edited: Sep 12, 2016
  4. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    By looking at the API docs you should use the token as your username and anything else as the password :)
     
  5. tismondo

    tismondo New Member

    Joined:
    Sep 1, 2016
    Messages:
    6
    Likes Received:
    0
    This solved my problem and I've got things working great, but some of the API actions need fixing. I'm doing my best to help out, and have shared many fixes back to the server already.

    However, one of the API actions I'm trying to fix uses the "body" input in json format, and it's a mess (two of the input parameters don't function properly, and there is no way to specify which bulb to target) - the original author appears to have done things all wrong.

    1) Is there a way to duplicate an API action so that I can sandbox my experimentation? I don't want to make a further mess of what is for now at least a mostly-functional Web Service. If I have a sandbox I can happily experiment away and not fear ruining things.

    2) I'll include my thoughts below, but feel free to ignore the following if you don't have the time to delve into this (I know you don't own a LIFX bulb yourself, and can't test what is being discussed)


    Thoughts...
    • LIFX has made two API endpoints that achieve a similar goal - the first ("set state") applies the input color/brightness/transition time options across a group of selected bulbs. (ex: all selected bulbs will be blue, all 50% brightness, all will have a 2 second transition)
    • The second ("set states") is more complex and uses an array of strings to select specific, unique settings for each bulb. Ex:
      • Selected bulb 1 will be blue, 50% bright, 4 second transition
      • Selected bulb 2 will be Red, 100% bright, 10 second transition
      • Selected bulb 3 will be orange, 20% bright, 30 second transition
    • The second option seems useless because there's already a feature of LIFX bulbs to set all of the individual settings for a group of bulbs ("scenes"), which can easily be set using the LIFX app and then activated using Autoweb.
    • I'd like to focus on the first option (set state) because it is the only way the API allows the user to set the on/off state for individual or groups of bulbs. The API documentation for this endpoint is here: https://api.developer.lifx.com/docs/set-state

    Working to fix "set state"
    • The first parameter listed in the documentation ("selector") is required, and you use it to select which bulbs the endpoint will target. It's a path param - I taught myself how to do these. All good there.
    • The second parameter listed in the documentation uses JSON formatting, and its how you tell the bulb(s) what state/color/brightness/transition duration to use. JSON is tough for me. Here's what the original API author created (note, this was originally intended for the "set states" endpoint, but it was done wrong and was written to target "all" bulbs.
    Code (Text):
    {   "states": [     {       "selector": "all",       "power": "
    =:==:=
    options
    state
    State
    Select On/Off
    on:On,off:Off
    =:==:=
    ",
    "color": "
    =:==:=
    options
    color
    Color
    Select a color
    red:Red,yellow:Yellow,orange:Orange,blue:Blue,green:Green,purple:Purple,white:White,cyan:Cyan,pink:Pink
    =:==:=
    "   },     {       "selector": "all",       "brightness":
    =:==:=
    text
    bright
    Brightness
    Set the brightness (0.0 to 1.0)
    =:==:=
    ,
    "duration":
    =:==:=
    text
    duration
    Duration
    How long you want the power action to take (seconds)
    =:==:=
    }   ] }
    • When I test the original version in Tasker, the brightness and duration inputs don't seem to work - For color, 0.0 makes no changes, though curiously 0.5 will set my bulb brightness to 58%. For duration, it always seems to take the same amount of time (even when selecting 120 seconds)
    • I'll work on removing the references to the selector "all" (which bulbs the API is targeting) since the "set state" endpoint does that using the "path" param. But I have little experience with this sort of thing so I'll need to experiment as i go.
    Hoping there's a good option for sandboxing!

    Cheers, and thanks again for all your help.
     
    Last edited: Sep 14, 2016
  6. joaomgcd

    joaomgcd Administrator Staff Member

    Joined:
    Feb 3, 2015
    Messages:
    9,479
    Likes Received:
    806
    Thanks for helping out with the API! :)

    There's a good way to sandbox: disable sharing for the API. That way you can mess around all you want and nothing will be sent to the server ever.

    When you feel everything's ok you can re-enable sharing :)

    Hope this clarifies it.
     
: Lifx, Autoweb

Share This Page