Closed noktulo closed 4 years ago
It looks like the SSH command opens up an interactive prompt or shell, meaning the command will never finish. I think there’s a timeout option you could use, but better yet is to make sure that the SSH channel is terminated as soon as you’ve run your command. You can for example try ssh user@host bash -c 'shutdown && exit'
. This is also quite common if the SSH server prompts for your credentials, so make sure that the user Homebridge is running as has SSH key authentication setup so that it may access the server without a password (and therefore without a prompt).
I think this could be made clearer by the plugin if “executing a command” would translate to a state. That way the plugin would deadlock and make it able to throw errors whenever you try to trigger a state change again whilst the command is still running. Another way to mitigate this is to simply implement a default timeout which will then log a warning if the time runs out. Definitely worth looking into for the next release.
Ah, good call! That makes a lot of sense, and thanks for the quick response. I'm sshing into Windows, and just adding "&& exit" to the end of the command exits without running the first command, so I'll need to do more research.
This is the actual command I'm using for reference: "ssh -f -i /homebridge/pc_id_rsa michael@192.168.1.15 '%windir%/System32/rundll32.exe powrprof.dll,SetSuspendState 0,1,0'"
Actually I lied, it seems that running "ssh -f -i /homebridge/pc_id_rsa michael@192.168.1.15 '%windir%/System32/rundll32.exe powrprof.dll,SetSuspendState 0,1,0 & exit'" or && exit both put the computer to sleep but don't actually exit.
This seems to have fixed it:
ssh -f -i /homebridge/pc_id_rsa michael@192.168.1.15 -o ServerAliveInterval=1 '%windir%/System32/rundll32.exe powrprof.dll,SetSuspendState 0,1,0'
As soon as the PC stops responding, the SSH connection is killed.
Great thing you were able to solve it and thanks for posting the solution here, it's always helpful as a future reference.
I can successfully use homebridge-wol once, and then it will not respond until I restart homebridge.
Hitting the switch successfully turns off the computer, but the switch in the Home app has a spinner for a bit, then shows the device as On but with an exclamation mark. If I hit the button, I can still change the status of the device in Home, but nothing happens.
Here's my relevant debug log:
You can see it shut down the computer, and you can see the triggers from me tapping the button in Home on and off afterwards, with no action taken from Homebridge.
This happens both on the stable and v5 beta release.