bahamas10 / hueadm

A command line management interface to Philips hue
208 stars 13 forks source link

Registering with Bridge #7

Open henri opened 6 years ago

henri commented 6 years ago

I am having some difficulty with registering with the bridge. Is there a way to setup more verbose interaction during this process or perhaps to manually make a request which you are able to suggest?

bahamas10 commented 5 years ago

hm, that's interesting. Unfortunately there is no debug/verbose options for this step... you can however run it manually:

$ echo '{"devicetype":"hueadm#username"}' | curl -d@- -X POST http://10.0.1.80/api

(substitute username for the username you want, and 10.0.1.80 with the IP of your bridge)

You should get an error message (type 101) saying "link button not pressed". Once you get that, press the button, wait a second or two, and then run the curl command again (same exact command) and it should return a randomly generated string for you to use.

henri commented 4 years ago

I did manage to get a key for the Philips Hue bridge. Also, I put together the following script which may be of interest to people using the hue motion sensors : https://gist.github.com/henri/fd7e367d853a3970bdf6c077cf7765da

It may even be possible to monitor lights (for sure) and even switches (not sure). I ended up creating another script which reads this scripts output and that can send push notifications when certain motion events take place and other criteria such as time of day / device presses and more are meet.

I will revisit the registration thing and maybe add an option in the script so that it uses the users saved details rather than including them in the file / separate config file.

henri commented 4 years ago

I can confirm it seems possible to pull the data from the switches so this could be added to the script as could the status changes of lights.

thomas-negrault commented 6 days ago

I also have difficulties adding my bridge. It was working fine then I reset my Mac and tried to reinstall and it does not find my bridge. I know my bridge IP address (from my router and from the Hue app)

Your command works:

echo '{"devicetype":"mbpro"}' | curl -d@- -X POST http://192.168.1.20/api
[{"success":{"username":"XXXXXXX"}}]%

But hueadm search does not find anything, and hueadm -H 192.168.1.20 register mbpro returns:

sending request... press the link button on the hue bridge
error: Error: connect EHOSTUNREACH 192.168.1.20:80 - Local (192.168.1.123:64694)
    at internalConnect (node:net:1097:16)
    at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
    at node:net:1327:9
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11) {
  errno: -65,
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '192.168.1.20',
  port: 80,
  _cmdlnInst: [CLI],
  _cmdlnSubcmd: 'register',
  _cmdlnHandler: [Function]
}

I also tried to put the username generated by the command in the ~/.hueadm.json file and I have the same output when running hueadm --debug lights

> loading config file: /Users/thomas/.hueadm.json
> instantiating client: XXXXX@192.168.1.20
error: Error: connect EHOSTUNREACH 192.168.1.20:80 - Local (192.168.1.123:64745)
    at internalConnect (node:net:1097:16)
    at defaultTriggerAsyncIdScope (node:internal/async_hooks:464:18)
    at node:net:1327:9
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11) {
  errno: -65,
  code: 'EHOSTUNREACH',
  syscall: 'connect',
  address: '192.168.1.20',
  port: 80,
  _cmdlnInst: [CLI],
  _cmdlnSubcmd: 'lights',
  _cmdlnHandler: [Function]
}

I am using hueadm version 1.2.1 and node v22.11.0

thomas-negrault commented 6 days ago

I finally found the issue. It seems to be linked to OSX security. Using OSX build-in terminal I have no issues, the commands work perfectly. Using iTerm2, it does not want to communicate with my bridge.

It seems I need to add iTerm to Settings > Privacy and Security > Local Network, but it's not there.

So quick fix: use osx terminal and not a 3rd party app