Controlling HomeBridge through cURL [Solved w/ documentation]
See original GitHub issueI’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:
-
`"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}]}'
-
`{"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\"}] }"
-
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}] }'
-
{"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:
-
localhost and IP
-
From a different pc on the network
-
GET and PUT
-
Different id/aid and even random ones
-
I’ve checked the port, ip and authorization thousands of times
-
There was a suggestion #506 to not use whitespace, which is of cause also tried
-
Pretty much tried copying every single command from #506 and changing ip, port, auth, id’s and such.
-
Value/Status both 0/1 and true/false
-
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.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top GitHub Comments
@jandreaucodes - Please keep in mind that there are 2 API here and it looks you have them confused. There is the HAP interface which is what I have been explaining to people, and this is documented in the HomeKit Accessory Protocol specification from Apple. And there is an API which is part on Homebridge-config-ui-x, which is documented here https://github.com/oznu/homebridge-config-ui-x/wiki/API-Reference which is very similar.
And it looks like you are trying to use the HAP message format against the Homebridge-config-ui-x configuration endpoint. Try changing this
http://myhostname:8581/api/characteristics
to your Homebridge instance port, and removeapi
from the url iehttp://jesse.local:51826/characteristics
.Another option to control your homebridge accessories is to install node-red and the Homebridge-automation, that is what I use to control my homebridge accessories. it keeps it simple, and removes the need to determine the AID and IID of you accessory.s
PS This assumes you have enabled insecure mode
@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:
Make sure you’re calling the correct IID and AID, which you can find by running NothernMan54’s example;
Where you obviously have to replace
jesse.localt:51826
with your IP and Port for HomeBridge (port51826
is the standard port) and031-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)
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 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.