pponce/homebridge-script2

script running issue

Closed this issue · 3 comments

The main objective for me is to toggle power to the USB port of my RBP 3. I wrote two scripts that work when i execute them outside of homebridge, but when using script2 to invoke them, the power toggling capability will not work.
Is there a way to see the error messages popping in the process?

my USBPowerOn.sh:

#!/bin/bash
echo "ON"
echo "This is flag Switch ON" > /home/homebridge/script.flag
sudo /home/pi/uhubctl/uhubctl -l 1-1 -p 2 -a 1

my USBPowerOff.sh

#!/bin/bash
echo "OFF"
rm /home/homebridge/script.flag
sudo /home/pi/uhubctl/uhubctl -l 1-1 -p 2 -a 0

my config file:

"accessories": [
        {
            "accessory": "Script2",
            "name": "Pi USB",
            "on": "/home/homebridge/USBPowerOn.sh",
            "off": "/home/homebridge/USBPowerOff.sh",
            "fileState": "/home/homebridge/script.flag",
            "on_value": "true"
        }
    ], 

What user runs your homebridge instance?
Can you try executing the script as that user? See if it works?

The other common issue is that the script itself references executables that are not in your environments executable path statement.

I've added homebridge to the sudo group.
For some reason, i'm prompted to enter the homebridge user password.
The scripts are working properly when executed by me but are not working when executed using the accessory.
I'm getting this response in my homebridge terminal for self executing:

homebridge@raspberrypi:/var/lib/homebridge $ sudo /home/homebridge/USBPowerOn.sh
[sudo] password for homebridge: 
ON
Current status for hub 1-1 [0424:9514]
  Port 2: 0100 power
Sent power on request
New status for hub 1-1 [0424:9514]
  Port 2: 0100 power

Also, to my understanding, this information might be useful too:

homebridge@raspberrypi:/var/lib/homebridge $ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Solved using this addition to "visudo":

ALL ALL=(ALL) NOPASSWD:ALL