Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control homebridge with the command line (without an iPhone) #506

Closed
oa- opened this issue Feb 1, 2016 · 68 comments
Closed

Control homebridge with the command line (without an iPhone) #506

oa- opened this issue Feb 1, 2016 · 68 comments

Comments

@oa-
Copy link

oa- commented Feb 1, 2016

When setting up a new configuration I'd like to test it without using Siri all the time.

How can I simulate the command Siri is sending to homebridge simply using the terminal? Thanks.

@KhaosT
Copy link
Contributor

KhaosT commented Feb 1, 2016

Why don't you just test the homebridge with a HomeKit app...?

@oa-
Copy link
Author

oa- commented Feb 2, 2016

…oh, right.

In fact I want to send commands to homebridge without an iPhone/iOS device.

Is there a way to do so from a Mac running OS X?

@oa- oa- changed the title Control homebridge with the command line (instead of Siri) Control homebridge with the command line (without an iPhone) Feb 2, 2016
@cflurin
Copy link
Contributor

cflurin commented Feb 2, 2016

@OA: Take a look here.
homebridge-punt has a build-in simulator. The simulator works in both directions: simulator <-> ios-device and simulator <-> gateway.

@oa-
Copy link
Author

oa- commented Feb 2, 2016

Thank you, I am currently testing homebridge-punt. As of yet I wasn't able to see my other devices in the punt simulator.

Other hints to control homebridge are welcome as well.
(e.g. something like homebridge --setAccessory "Light 1" --setCharacteristic "on")

@yene
Copy link

yene commented Feb 3, 2016

You can run the apple example app in Simulator. https://developer.apple.com/library/ios/samplecode/HomeKitCatalog/Introduction/Intro.html

@KhaosT
Copy link
Contributor

KhaosT commented Feb 3, 2016

@oa- or you can use curl and simulate HomeKit request. For this option, you may want to check here

@cflurin
Copy link
Contributor

cflurin commented Feb 3, 2016

@oa- that's right, the punt simulator is only for the accessories defined in config-punt.json but that's good point. However I'm not sure whether I can access all the homebridge accessories in my plugin. I've to investigate.

@rooi
Copy link

rooi commented Feb 6, 2016

@KhaosT the simulation of a homekit request sounds interesting. However, the link you included is not accessible without a login. Do you have another link or know how I can get it another way? Thanks!

@KhaosT
Copy link
Contributor

KhaosT commented Feb 6, 2016

@rooi You can join the homebridge channel from the README.
Here are the contents I'm referring:

PUT http://<homebridge ip>:51826/characteristics` accepts JSON with a little array of values you wish to set
so to turn a light on: `{ characteristics: [ { aid: 1, iid: 8, value: true } ] }`
you can look through `/accessories` JSON to figure out what the `aid` and `iid` values should be

And if you're using homebridge 0.2.16, you may need to manually edit the hap-nodejs and comment out this part (https://github.com/KhaosT/HAP-NodeJS/blob/3733e7d7274a656c71fe02fd3df4af170dd33c3b/lib/HAPServer.js#L700)

@desvdp
Copy link

desvdp commented Feb 15, 2016

Hi @KhaosT I tried to look at the homebridgeteam.slack but it seems you need to be invited ... could you invite me? Thx !

@KhaosT
Copy link
Contributor

KhaosT commented Feb 15, 2016

Check the project's GitHub page, there is a slack button. Click that and you'll get invitation to the channel ^^

Sent from my iPhone

On Feb 15, 2016, at 9:25 AM, desvdp notifications@github.com wrote:

Hi @KhaosT I tried to look at the homebridgeteam.slack but it seems you need to be invited ... could you invite me? Thx !


Reply to this email directly or view it on GitHub.

@desvdp
Copy link

desvdp commented Feb 16, 2016

@KhaosT Thanks for the hint ! I missed the link the first time...

@rooi
Copy link

rooi commented Feb 17, 2016

@KhaosT This has changed in the latest HAP-NodeJS version right? If I understand the code correctly you should be able to set the auth en get a response. If this is correct, could you please indicate what the commands are?

I get Insufficient privileges with something like (with different pincode ""' variations and other options):

curl -X PUT http://mac-mini.local:51828/accessories --header "Content-Type:Application/json" --header "authentication: "031-45-154"" -s

Thanks!

@KhaosT
Copy link
Contributor

KhaosT commented Feb 17, 2016

Make sure you're on latest homebridge (0.2.18). Launch homebridge with flag -I and replace "authentication" with "authorization".

@rooi
Copy link

rooi commented Feb 17, 2016

It works, thanks!

@derekmoyes
Copy link

Also, you could try this:
https://github.com/KraigM/HomeBridgeController
works for me, ymmv. :-)

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

@KhaosT I'd like to set a value of an accessory within a bash script. I got the aai/iid for my accessory as discribed above. However, I'm struggling with the correct syntax of the curl command for PUTing a value to the accessory. Could you please indicate how to do this?

My (not working) command is:
curl -X PUT http://localhost:PORT/characteristics --header "Content-Type:Application/json" --header "authorization: \"031-45-XXX\"" --data "{\"aid\":\"AID\",\"iid\":\"IID\",\"value\":\"VALUE\"}"

@snowdd1
Copy link
Contributor

snowdd1 commented Nov 18, 2016

@Samfox2 You missed the "characteristics" part that surrounds your data, see khaosT's post
#506 (comment) from Feb 6

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

Added it now but still no change:

curl -X PUT http://localhost:PORT/characteristics --header "Content-Type:Application/json" --header "authorization: \"031-45-XXX\"" --data "{ characteristics: [{ \"aid\": \AID\", \"iid\": \"IIDl\", \"value\": \"VALUE\"}] }"

@KhaosT
Copy link
Contributor

KhaosT commented Nov 18, 2016

@Samfox2 you need to post what's the error you get...

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

The error is:

{"status":-70401}

@KhaosT
Copy link
Contributor

KhaosT commented Nov 18, 2016

@Samfox2 that means you are not running homebridge in "insecure" mode. In order to send command via a non-HomeKit path, you need to run homebridge with -I option.

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

Hmm, strange, I thought I did as it was working with the accessories-method

@KhaosT
Copy link
Contributor

KhaosT commented Nov 18, 2016

@Samfox2 Huh interesting. If you are sure it's running with -I option then the pincode you send is incorrect... Here is how I check that.

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

No, it's not working 😔

  • started the session with -I
  • hardcoded this.allowInsecureRequest = true;
  • commented out the section with autentification

Would you mind checking it with your config and posting the whole command? Maybe there is a syntax error in my command?

@KhaosT
Copy link
Contributor

KhaosT commented Nov 18, 2016

It looks right to me... Try add stuff to print out the header and see if it actually getting the correct header?

curl -X PUT http://ti.io/characteristics --header "Content-Type:application/json" --header "Authorization: \"031-45-154\""

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

Looks like there are a few spelling errors in (my) HAPServer.js, no idea where they come from.
If I change all "Authorization" strings to "authorization" the error message disappears (although it is not working yet).

@Samfox2
Copy link

Samfox2 commented Nov 18, 2016

After a long debug session the following command deliveres the correct header incl. pin but characteristics is empty {}:

curl -X PUT http://localhost:11111/characteristics --header "Content-Type:Application/json" --header "authorization: 031-11-111" --data "aid: 111" --data "iid: 1" --data "value: 1" -s

Any idea?

@PierfrancescoElia
Copy link

PierfrancescoElia commented Jan 22, 2017

I found that link by chance, as there isn't any documentation about that.
If you look here, you can read that if you try a GET request like /characteristics?id=aid1.iid1,aid2.iid2 you can get a JSON where you can find the actual state [0,1] (value field)..

So in my script I have a GET request to Homebridge, then analyze the response (value filed) and turn on or off the lamp! :)

@agrublev
Copy link

For people having issues with suggested commands, here is how i got it to work:

I ran homebridge using:
DEBUG=* homebridge -D -I

Then i clicked in my Home app on my iPhone to turn a light on or off

In the console it showed me:
EventedHTTPServer [::ffff:10.0.1.29] Sending HTTP event '19.8' with data: {"characteristics":[{"aid":19,"iid":8,"value":true}]} +0ms

Which is the right iid to use.

Then i used
curl -X PUT http://10.0.1.52:51852/characteristics --header "Content-Type:Application/json" --header "authorization: 031-45-152” --data "{\"characteristics\":[{\"aid\":2,\"iid\”:9,\”On\”:true}]}"

Which turns it on! And to get a list of all lights
curl -X GET http://10.0.1.52:51852/characteristics --header "Content-Type:Application/json" --header "authorization: 031-45-152” -s

@qudarr
Copy link

qudarr commented Aug 23, 2017

For anybody wondering, why the curl statement above doesn't work for you, please check:

  • Don't blindly copy & paste the above curl statement, as the apostrophes will not work correctly. You will need to re-type them. In my case: using chrome on windows as well as safari on mac.
  • Do you have the same homebridge port? Mine was 51826.
  • Check your authorization code
  • I didn't need the "-s" parameter at the end of the curl GET statement

To get all of the available AID and IID values, execute following script:

#!/bin/bash
for ((i = 0; i < 100; i++))
do
  for ((j = 0; j < 100; j++))
  do
    echo "$i $j"
    curl --silent -X GET http://127.0.0.1:51826/characteristics?id=$i.$j --header "Content-Type:Application/json" --header 'authorization: XXX-YY-ZZZ'
  done
done

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Aug 23, 2017 via email

@qudarr
Copy link

qudarr commented Aug 31, 2017

Thanks, this is much better. But harder to parse as a human ^_^

@felipesalomao
Copy link

felipesalomao commented Dec 18, 2017

Hi, i want make script that change device status to opposite when detect especific infrared signal (Hex code), i already am able to get device status, for example: TV
curl -X GET http://localhost:51820/characteristics?id=4.10 --header "Content-Type:Application/json" --header "authorization: 031-45-155"
I have broadlink rmpro that can send and receive ir commands, it have plugin for homebridege and works like charm: https://github.com/lprhodes/homebridge-broadlink-rm
To active it learn IR commands it i use:
curl -X PUT http://localhost:51820/characteristics --header "Content-Type:Application/json" --header "authorization:031-45-155" --data "{\"characteristics\":[{\"aid\":2,\"iid\":10,\"value\":true}]}"

The problem is that it stop learn few seconds latter.. Also i would like get this hex code (i can see it on homebridge debug but cant get it running command), another problem is that if it read same remote button, it aways is different hex code, its similar, but hard be exactly same..
Also could use if needed GPIO ir receiver..


I think will be hard somebody here with experience in rm pro devices (their git is stoped, no updates long time, so is hard discuss with guys in issues list)

But at least could help with that:

curl -X GET http://localhost:51820/characteristics?id=4.10 --header "Content-Type:Application/json" --header "authorization: 031-45-155"

How make script to read it result, change value to opposite ? if its true, change to false, if is false, change to true..

{"characteristics":[{"aid":4,"iid":10,"value":false,"status":0}]}
it have value = false, i need to change that value to true and send command:

curl -X PUT http://localhost:51820/characteristics --header "Content-Type:Application/json" --header "authorization:031-45-155" --data "{\"characteristics\":[{\"aid\":4,\"iid\":10,\"value\":true}]}"

@i3laze
Copy link

i3laze commented May 10, 2018

To summ up:

  1. Make sure you run HomeBridge in Insecure Mode (change it in Web Settings at top right corner).
    Any API control is allowed only in this mode.
    That’s about starting HomeBridge with -I flag. Every time. Otherwise you’ll be getting {"status":-70401} response for any query.
  2. Let’s find IDs of the particular device we want to toggle.
    Output of /accessories is rough to understand:
    curl -X GET http://YOUR_IP_HERE:51826/accessories
    So better use a script by @qudarr for discovery (I've cleared it’s output with grep):
#!/bin/bash
for ((i = 0; i < 10; i++))
do
  for ((j = 0; j < 30; j++))
  do
    curl -s -X GET http://YOUR_IP_HERE:51826/characteristics?id=$i.$j  2>&1 | grep value
  done
  printf "\n"
done
  1. Toggle the state of your device. Run the script again. Compare outputs.

  2. Once you figure out aid and iid of the target device, you can toggle it’s state from cURL setting "value":false or true, like:
    curl -X PUT --header "Content-Type:Application/json" --header "authorization: 031-45-154" http://YOUR_IP_HERE:51826/characteristics --data '{"characteristics":[{"aid":2,"iid":10,"value":false,"status":0}]}'

  3. Here's my final toggle script (uses popular 'jq' parser):

#!/bin/sh
aid=2
iid=10
IP=172.17.0.3
PORT=51826
KEY=031-45-154

result=$( curl -s -X GET http://$IP:$PORT/characteristics?id=$aid.$iid | jq '..|.value?|select(. != null)' )

case $result in
  true)
    echo "Toggling off.."
    state=false ;;
  false)
    echo "Toggling on.." 
    state=true  ;;
  *)
    echo "Invalid cURL response!"
    exit 1 ;;
esac

data={\"characteristics\":[{\"aid\":$aid,\"iid\":$iid,\"value\":$state,\"status\":0}]}

curl -s -X PUT http://$IP:$PORT/characteristics --data $data --header "Content-Type:Application/json" --header "authorization: $KEY"

Also here's another version of the script, using only native 'sed' & 'awk' parser from here:

Bash only (should work in Shell when you rewrite For loop with While) #!/bin/bash aid=2 iid=10 IP=192.168.1.128 PORT=51826 KEY=031-45-154

function jsonValue() {
KEY=$1
num=$2
awk -F"[,:}]" '{for(i=1;i<=NF;i++){if($i~/'$KEY'\042/){print $(i+1)}}}' | tr -d '"' | sed -n ${num}p
}

result=$( curl -s -X GET http://$IP:$PORT/characteristics?id=$aid.$iid | jsonValue value )

case $result in
true)
echo "Toggling off.."
state=false ;;
false)
echo "Toggling on.."
state=true ;;
*)
echo "Invalid cURL response!"
exit 1 ;;
esac

data={"characteristics":[{"aid":$aid,"iid":$iid,"value":$state,"status":0}]}

curl -s -X PUT http://$IP:$PORT/characteristics --data $data --header "Content-Type:Application/json" --header "authorization: $KEY"

@christiansassano
Copy link

Sorry but
aid
and
iid
is the identification of my accessory?

@i3laze
Copy link

i3laze commented May 10, 2018

Seems so) mine device had aid=2, and state value was contained in string iid=10.
Run the discovery script to figure out own values.

@ebaauw
Copy link
Contributor

ebaauw commented May 10, 2018

They're like index numbers for the accessory (aid) and service/characteristic (iid), within the accessory. I suppose to avoid having to pass lengthy UUIDs with every HAP call. They're mapped to the UUIDs, see ~/.homebridge/persist/IdentifierCache.username.json.

@christiansassano
Copy link

Run the discovery script to figure out own values.

Thank you very much, and sorry for this message, but what discovery script can I run to figure out my values?
Sorry sorry

@christiansassano
Copy link

They're mapped to the UUIDs, see ~/.homebridge/persist/IdentifierCache.username.json.

Thanks, I find the file but, into the file, there is so much number :-(

@ebaauw
Copy link
Contributor

ebaauw commented May 10, 2018

It's an object with key/values pairs, where

  • the key is the accessory UUID and the value the aid;
  • the key is the accessory UUID followed by |, followed by the service (type) UUID and |, optionally followed by the service subtype and |, followed by the characteristic (type) UUID and the value is the iid.

See https://github.com/KhaosT/HAP-NodeJS/blob/master/lib/gen/HomeKitTypes.js for the UUIDs of the standard services and characteristics.
The accessory UUID is created by homebridge when the accessory is created: https://github.com/nfarina/homebridge/blob/d5691fd19e8b9395b3120500217178c4728bfade/lib/server.js#L404-L406

@christiansassano
Copy link

Thanks, I suppose to find my data
.....ca|nextIID":12,

.....ca|nextIID":12,

but onece aid

....."|nextAID":19,

Is correct?

@christiansassano
Copy link

I update my string:
curl -X PUT http://IP:PORT/characteristics --header "Content-Type:Application/json" --header "authorization:XXX-XX-XXX" --data "{"characteristics":[{"aid":19,"iid":12,"value":1}]}"
But: {"status":-70401}pi@raspberrypi:

@ebaauw
Copy link
Contributor

ebaauw commented May 10, 2018

Thanks, I suppose to find my data

No, these are just references to the next aid to be assigned and to the next iid to be assigned for the accessory. You need to look for your accessory UUID (I wouldn't know how to retrieve that) and the service and characteristic UUIDs.

If you run DEBUG=* homebridge -D, you'll see debug messages of the HAP protocol including the aid and iid values.

For example, here's one of my Hue dimmer switches, as exposed by homebridge-hue:

    "3979a1a8-fcb5-4abe-abea-d07911ecaa74": 187,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|nextIID": 37,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000014-0000-1000-8000-0026BB765291": 2,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000020-0000-1000-8000-0026BB765291": 3,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000021-0000-1000-8000-0026BB765291": 4,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-0026BB765291": 5,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000030-0000-1000-8000-0026BB765291": 6,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|0000003E-0000-1000-8000-0026BB765291|00000052-0000-1000-8000-0026BB765291": 7,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291": 8,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-0026BB765291": 9,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|000000CD-0000-1000-8000-0026BB765291": 10,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-656261617577": 11,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000077-0000-1000-8000-0026BB765291": 12,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000075-0000-1000-8000-0026BB765291": 13,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000022-0000-1000-8000-656261617577": 14,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|000000CC-0000-1000-8000-0026BB765291|00000021-0000-1000-8000-656261617577": 15,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|On": 16,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|On|00000023-0000-1000-8000-0026BB765291": 17,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|On|00000073-0000-1000-8000-0026BB765291": 18,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|On|000000CB-0000-1000-8000-0026BB765291": 19,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Up": 20,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Up|00000023-0000-1000-8000-0026BB765291": 21,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Up|00000073-0000-1000-8000-0026BB765291": 22,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Up|000000CB-0000-1000-8000-0026BB765291": 23,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Down": 24,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Down|00000023-0000-1000-8000-0026BB765291": 25,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Down|00000073-0000-1000-8000-0026BB765291": 26,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Dim Down|000000CB-0000-1000-8000-0026BB765291": 27,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Off": 28,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Off|00000023-0000-1000-8000-0026BB765291": 29,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Off|00000073-0000-1000-8000-0026BB765291": 30,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000089-0000-1000-8000-0026BB765291|Off|000000CB-0000-1000-8000-0026BB765291": 31,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000096-0000-1000-8000-0026BB765291": 32,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000096-0000-1000-8000-0026BB765291|00000023-0000-1000-8000-0026BB765291": 33,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000096-0000-1000-8000-0026BB765291|00000068-0000-1000-8000-0026BB765291": 34,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000096-0000-1000-8000-0026BB765291|0000008F-0000-1000-8000-0026BB765291": 35,
    "3979a1a8-fcb5-4abe-abea-d07911ecaa74|00000096-0000-1000-8000-0026BB765291|00000079-0000-1000-8000-0026BB765291": 36,

Parsing this (note that standard services and characteristics have UUID 00000xxx-0000-1000-8000-0026BB765291):

  • The aid is 187;
  • The next iid to be assigned will be 37;
  • 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).

@ebaauw
Copy link
Contributor

ebaauw commented May 10, 2018

I update my string:
curl -X PUT http://IP:PORT/characteristics --header "Content-Type:Application/json" --header "authorization:XXX-XX-XXX" --data "{"characteristics":[{"aid":19,"iid":12,"value":1}]}"
But: {"status":-70401}pi@raspberrypi:

Did you run homebridge -I?

@christiansassano
Copy link

Yes, but there is an error:

`Or enter this code with your HomeKit app on your iOS device to pair with Homebridge:

┌────────────┐     
│ 012-55-234 │     
└────────────┘     

events.js:183
throw er; // Unhandled 'error' event
^

Error: listen EADDRINUSE :::51826
at Object._errnoException (util.js:1022:11)
at _exceptionWithHostPort (util.js:1044:20)
at Server.setupListenHandle [as _listen2] (net.js:1351:14)
at listenInCluster (net.js:1392:12)
at Server.listen (net.js:1476:7)
at EventedHTTPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/util/eventedhttp.js:60:19)
at HAPServer.listen (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/HAPServer.js:158:20)
at Bridge.Accessory.publish (/usr/local/lib/node_modules/homebridge/node_modules/hap-nodejs/lib/Accessory.js:607:16)
at Server._publish (/usr/local/lib/node_modules/homebridge/lib/server.js:126:16)
at Server.run (/usr/local/lib/node_modules/homebridge/lib/server.js:96:10)`

@christiansassano
Copy link

I suppose because I use this for a quick install of Homebridge server:

https://itunes.apple.com/it/app/homebridge-for-raspberrypi/id1123183713?mt=8

I think the structure of the directory is different :-(

@ebaauw
Copy link
Contributor

ebaauw commented May 10, 2018

Error: listen EADDRINUSE :::51826

You're already/still running homebridge. Make sure to stop any service before starting homebridge manually from the command line.

@i3laze
Copy link

i3laze commented May 11, 2018

The discovery script by @qudarr, which I posted in step 2, provides a very clear aid/uid output.
#506 (comment)

{"status":-70401} means you’re not running InSecure mode.
I mentioned in Step 1. That’s about starting HB with -I flag. Every time.
So better modify homebridge startup script (/etc/init.d/homebridge ?) or probably just change it in WebGUI:
(I’m using a Docker version, which has such GUI setting).
65df444f-e390-45cd-a227-0f3cb20a24ce
How to actually enable InSecure mode in your HomeBridge for RPi.app, ask it’s developer: support@nvw-dev.com

@i3laze
Copy link

i3laze commented May 11, 2018

IMHO, HomeBridge developers should publish some straightforward CLI script or more simplified HTTP API for this Topic (listing devices and switching their state).

Currently, I’m not using HomeBridge to toggle.
For example, it's much easier to control a device with Tasmota f/w directly via HTTP.
My whole Tasmota toggle script is now:

#!/bin/sh
IP=192.168.1.129

result=$( curl -s http://$IP/cm?cmnd=Power | jq -r '.POWER?' )
            
case $result in
  ON)          
    echo "Switching off.."
    curl -s http://$IP/cm?cmnd=Power%20Off ;;
  OFF)                                       
    echo "Switching on.."
    curl -s http://$IP/cm?cmnd=Power%20On ;;
  *)                                        
    echo "Invalid cURL response!"
    exit 1 ;;                    
esac 

By the way, jq isn't really necessary (not available for arm64). Without jq case with wildcard substring still works fine:

#!/bin/sh
IP=192.168.1.129

result=$( curl -s http://$IP/cm?cmnd=Power )
            
case $result in
  *ON*)          
    echo "Switching off.."
    curl -s http://$IP/cm?cmnd=Power%20Off ;;
  *OFF*)                                       
    echo "Switching on.."
    curl -s http://$IP/cm?cmnd=Power%20On ;;
  *)                                        
    echo "Invalid cURL response!"
    exit 1 ;;                    
esac 

@i3laze
Copy link

i3laze commented Mar 10, 2019

My values doesn't follow toggle state anymore - they are just 0, not false or true.
Was prior to 0.4.4x:
{"characteristics":[{"aid":4,"iid":10,"value":false,"status":0}]}
Now:
{"characteristics":[{"aid":4,"iid":10,"value":0,"status":0}]}

Probably, there were some changes in HomeBridge recently.. or in HAP-NodeJS.

@NorthernMan54
Copy link
Contributor

@i3laze I’m a big user of insecure mode and have not noticed anything recently. It is the backbone of my Alexa plugin, and has been working for over a year. Can you elaborate further on your issue?

@i3laze
Copy link

i3laze commented Mar 13, 2019

My fault.. looks like every device has own unique aid.
A year ago it looked like devices were placed under single aid (between 1 and 3) and differ by iid only.

14 9; {"characteristics":[{"aid":14,"iid":9,"value":"Kodi Playback","status":0}]}
14 10; {"characteristics":[{"aid":14,"iid":10,"value":true,"status":0}]}

Current walk through /characteristics might take several minutes.
Seems, parsing curl -s -X GET http://localhost:51826/accessories is the only reliable solution.
Some nice jq script might do it (above my average skills):
https://stedolan.github.io/jq/manual/
https://jqplay.org/

Even better if we get a better HomeBridge API.

@NorthernMan54
Copy link
Contributor

NorthernMan54 commented Mar 14, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests