Homebridge: Controlling HomeBridge through cURL [Solved w/ documentation]

Created on 25 Apr 2020  路  3Comments  路  Source: homebridge/homebridge

I've been attempting to control HomeBridge accessories through terminal the entire evening, and at this point I simply have no clue what I'm doing wrong.

I must have read through #506 5 times by now, attempting different pastes of commands, with no succes.

I've been attempting to run the cURL commands from the Pi which the HomeBridge server is hosted from. I am running the -I for HomeBridge, and I use homebridge-config-ui-x where accessories work just fine, using same method. I'm getting the accesory ID and AID from homebridge-config-ui-x.

No matter what I do, I get:

  1. "status":-70402
    curl -X PUT http://192.168.1.171:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 589-00-356" --data '{"characteristics":[{"aid":17,"iid":8,"value":false,"status":0}]}'
  2. {"characteristics":[{"aid":"17","iid":"2","status":-70402}]}
`curl -X PUT http://localhost:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 589-00-356" --data "{ \"characteristics\": [{ \"aid\": \"17\", \"iid\": \"2\", \"value\": \"0\"}] }"`
  1. even: >??
    curl -X PUT http://192.168.1.171:51826/characteristics --header 'Content-Type:Application/json' --header 'authorization: 589-00-356' --data '{ \'characteristics\": [{ \'aid\': 2, \'iid\': 9, \'value\': 0}] }'

  2. {"characteristics":[{"aid":17,"iid":9,"status":0}]}
    From changing id's randomly, but only outputs status: 0 sometimes, and other times -70402

I've tried:

  • [x] localhost and IP

  • [x] From a different pc on the network

  • [x] GET and PUT

  • [x] Different id/aid and even random ones

  • [x] I've checked the port, ip and authorization thousands of times

  • [x] There was a suggestion #506 to not use whitespace, which is of cause also tried

  • [x] Pretty much tried copying every single command from #506 and changing ip, port, auth, id's and such.

  • [x] Value/Status both 0/1 and true/false

  • [x] Everything I could think of, except giving up

As I was writing this I was able to return a "status":0 chaning the IID and AID numbers randomly, but it only seems to work sometimes? And doesn't actually alter anything.
{"characteristics":[{"aid":17,"iid":9,"status":0}]}

There is no console output, except for a few times where I crashed HomeBridge as I sent wrong quotes.

Please for the love of god help me

#EDIT:
I realized that passing "value":false changed the name of the accessory even though the result was status":-70402. Although neither On: true or brightness: 20 does anything at all.

question

All 3 comments

On a Mac with bash

Accessory Dump

curl -X PUT http://jesse.localt:51826/accessories --header "Content-Type:Application/json" --header "authorization: 031-45-154"

Or control a device

curl -X PUT http://jesse.local:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 031-45-154" --data "{\"characteristics\":[{\"aid\":5,\"iid\":15,\"value\":0}]}"

from the command line back slashes are important

HI!
I'm in the same situation, rasperry pi 3, buster, Homebridge 1.0, and always the same reponse
{
"characteristics": [
{
"aid": 2,
"iid": 8,
"status": -70402
}
]
}
i also tried a lot combinations, clients, data, Mac, windows, linux, curl...

I think that I found the problem...
The UI says that my device has iid 8, but ... in the response of:
curl -X PUT http://jesse.localt:51826/accessories --header "Content-Type:Application/json" --header "authorization: 031-45-154"
I have the iid 9, not 8, I tried modify the iid to 9, and now it works...

@NorthernMan54 to the rescue, as always!

After copying your example for getting accessories (which worked), I realized that, correct me if I'm wrong, every device has an IID for different purposes, such as name, brightness, "On" and so on.

This means I was simply using the wrong IID (and probably a wrongly formatted command), thus also ending up changing the name of the device, instead of actually turning it on.


So for anyone who may be struggling with this;

If you already have the correct IID and AID's, make sure you're formatting the command correctly, as NorthernMan54 said:

from the command line back slashes are important

Make sure you're calling the correct IID and AID, which you can find by running NothernMan54's example;

Accessory Dump
curl -X PUT http://jesse.localt:51826/accessories --header "Content-Type:Application/json" --header "authorization: 031-45-154"

Where you obviously have to replace jesse.localt:51826 with your IP and Port for HomeBridge (port 51826 is the standard port) and 031-45-154 with your authorization code found in your config.json as "pin: "...".

The accessory dump is a json dump with no whitespace, so it's not very readable, but what you're looking for is first of an AID which has the "value": of the manufactorer, in my case 17. Below that there will be the device IID's for the certain device, this is where you have to locate the correct IID depending on what you're trying to do, in my case the "On": IID as indicated by "Description": "On"

Example of accessory dump snippet: (formated with whitespace for readability)

{"aid":17,"services":[{

    "iid":1,"type":"0000003E-0000-1000-8000-0026BB765291","characteristics":[{"iid":2,"type":"00000014-0000-1000-8000-0026BB765291","perms":["pw"],"format":"bool","description":"Identify"},

    {"iid":3,"type":"00000020-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"MiLight","description":"Manufacturer"},

    {"iid":4,"type":"00000021-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"rgbww","description":"Model"},

    {"iid":5,"type":"00000023-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"Desktop","description":"Name"},

    {"iid":6,"type":"00000030-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"Default-SerialNumber","description":"Serial Number"},

    {"iid":7,"type":"00000052-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"1.0","description":"Firmware Revision"}],"primary":false,"hidden":false},

    {"iid":8,"type":"00000043-0000-1000-8000-0026BB765291","characteristics":[{"iid":9,"type":"00000023-0000-1000-8000-0026BB765291","perms":["pr"],"format":"string","value":"Desktop","description":"Name"},

    {"iid":10,"type":"00000025-0000-1000-8000-0026BB765291","perms":["pr","pw","ev"],"format":"bool","value":false,"description":"On"},

    {"iid":11,"type":"00000008-0000-1000-8000-0026BB765291","perms":["pr","pw","ev"],"format":"int","value":100,"description":"Brightness","unit":"percentage","maxValue":100,"minValue":0,"minStep":1},

    {"iid":12,"type":"00000013-0000-1000-8000-0026BB765291","perms":["pr","pw","ev"],"format":"float","value":0,"description":"Hue","unit":"arcdegrees","maxValue":360,"minValue":0,"minStep":1},

    {"iid":13,"type":"0000002F-0000-1000-8000-0026BB765291","perms":["pr","pw","ev"],"format":"float","value":0,"description":"Saturation","unit":"percentage","maxValue":100,"minValue":0,"minStep":1},

    {"iid":16,"type":"3c2684ee-d18c-460c-bec6-250b147b3e6f","perms":["pr","pw","ev"],"format":"bool","value":false,"description":"White mode"}],"primary":false,"hidden":false}
  ]
},

So you'll see AID and IID as the first value of the object, and at the end you'll see "description": indicating what the AID/IID is for. As mentioned, I was trying to change the value "On" for my device which had the AID 17, and "On" has the IID 10. So in that case, my command would be:

curl -X PUT http://192.168.1.171:51826/characteristics --header "Content-Type:Application/json" --header "authorization: 589-00-356" --data "{\"characteristics\":[{\"aid\":17,\"iid\":10,\"value\":true}]}"


More on accessory dump iid/aid's: _(from issue #506, comment by @ebaauw)_

  • I think iid 1 is reserved for the Accessory Information service, hence not present in the file;
  • iids 2-8 are the characteristics of the Accessory Information service (03E): Identify (014), Manufacturer (020), Model (021), Name (023), Serial Number (030), and Firmware Revision (052);
  • iid 8 is for the Service Label service (0CC);
  • iids 9, 10, 12, 13 are for standard characteristics of the Service Label service: Name (023), Service Label Namespace (0CD), Status Fault (077), Status Active (075);
  • iids 11, 14 and 15 are custom characteristics for the Service Label service (see: https://github.com/ebaauw/homebridge-hue-utils/blob/master/lib/MyHomeKitTypes.js): _Last Updated (023), Enabled (022), Resource (021);
  • iid 16 is the fist Stateless Programmable Switch service (089) for the first button (subtype "On");
  • iids 17-19 are the characteristics for the fist Stateless Programmable Switch service: Name (023), Programmable Switch Event (073), and Service Label Index (0CB);
  • This repeats for the other three buttons;
  • iid 32 is the Battery (096) service;
  • iids 33-36 are the characteristics fo the Battery service: Name (023), Battery Level (068), Charging State (08F), and Status Low Battery (079).

I felt like there should be some more documentation on this matter for anyone like me who may be new with this kind of stuff, or for anyone else just struggling. I hope some of you find it useful, and if you have any questions feel free to ask.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

morilm picture morilm  路  6Comments

mgcrea picture mgcrea  路  3Comments

StefanMeGit picture StefanMeGit  路  4Comments

dcaccount picture dcaccount  路  5Comments

jeffl78 picture jeffl78  路  4Comments