bwssytems / ha-bridge

Home automation bridge that emulates a Philips Hue light system and can control other systems such as a Vera, Harmony Hub, Nest, MiLight bulbs or any other system that has an http/https/tcp/udp interface. This is a compact impl to run on small format computers. This is impl started from this project https://github.com/armzilla/amazon-echo-ha-bridge.
Apache License 2.0
1.45k stars 199 forks source link

Script execution #1368

Closed TheFwGuy closed 2 years ago

TheFwGuy commented 2 years ago

Hi, I have a strange problem. Raspberry Pi running Heyu and HA-bridge. All lights works just fine, both from web and via Alexa. I have 1 entry I use to turn on/off a PC. The ON is calling wakeonlan, works just fine. To turn it off I created a ssh key on the server running HA-Bridge so to be able to execute a sudo poweroff toward the PC to turn off. Did put in a script on the server running HA-bridge. If I go on the console of the server and execute the script, the remote PC turn off. All works fine. However if I call the script from HA-bridge the script apparently is called but nothing happens. Same permission used for the script top turn it on, no errors I can see on the HA-Bridge. Did try to call the script with absolute path (/home/pi/./script_name - the same way also to turn it on and it works), using exec, forcing sudo also on the call ... I simply don't get, why only the OFF is not working ? Any suggestions about that ? Some strange parameter to be set up in the HA-Bridge for this script ? Thanks

beandi commented 2 years ago

have you tried setting the execute-bit on the script? (sudo chmod +x scriptname) I'm calling a lot of bash-scripts from my HA installation, no special HA-Bridge-Setup necessary

TheFwGuy commented 2 years ago

Re-reading all the issues gave me the solution. As stated some times, the main key is to remember that HA-Bridge operates as root. The failed script was in /home/pi and it used ssh. In order to access the remote machine to be turned off I did set up a pair of keys (to avoid to have the password asked) and thus these keys were stored in the /home/pi/.ssh When calling the script via console of course it worked because ssh was accessing the created keys. But when the script was accessed by HA-Bridge, the created keys were not used because starting from root, not /home/pi. The solution was simple. I just did add the path for the created keys when calling ssh : -i /home/pi/.ssh/id_rsa Now everything is working fine. I'm closing the issue. Hope my experience can be useful to somebody else :) Cheers STeve