Page 1 of 1

Bash Script - Virtual switch not starting bash script

Posted: Wednesday 22 February 2017 22:51
by krizzz
I am trying to get my Wemo switch up and running through Domoticz. See the thread viewtopic.php?f=17&t=4971&start=20for more explanation.
Because these are my first steps in scripting and running a script. I will try and explain my best.

- I go to a particular folder within my scripts folder in domoticz with

Code: Select all

cd home/pi/domoticz/scripts/wemo
There are 2 scripts within this folder

Code: Select all

pi@raspberrypi:~/domoticz/scripts/wemo$ ls
wemo_off.sh  wemo_on.sh
For example, the code within one of these scripts is the following:

Code: Select all

#!/bin/sh
sudo wemo switch "espresso" ON
When I run manually this script within the commandline, the script runs fine and when I check the status of my wemo switch it says that it is on. No problem here, everything works.

Code: Select all

pi@raspberrypi:~/domoticz/scripts/wemo$ ./wemo_on.sh 
And then to check if the script worked, the status is confirmed as ON

Code: Select all

pi@raspberrypi:~/domoticz/scripts/wemo$ wemo -v switch "espresso" status
on
The point is that, when I make a virtual switch through Hardware --> create a virtual sensor and than add in the configuration of this virtual switch. That for the ON action the script wemo_on.sh has to be started and for the off action the wemo_off.sh script has to be started. And I save this configuration, the script does not work. Because my Wemo switch is not activated on or off.

The Domoticz log is recording some action, and it looks like the script is activated:

Code: Select all

2017-02-22 22:48:41.648 User: Admin initiated a switch command (61/Wemo/On)
2017-02-22 22:48:46.648 (Dummy1) Light/Switch (Wemo)
But again, the switch is not activated. What am I doing wrong? The script is working from the commandline, but not through the virtual switch.

Re: Bash Script - Virtual switch not starting bash script

Posted: Sunday 26 February 2017 11:04
by SweetPants
How did you configure the ON/OFF action? Have you searched the forum, this has been handeled numerous times before.

Re: Bash Script - Virtual switch not starting bash script

Posted: Monday 27 February 2017 21:17
by krizzz
Sorry for the inconvenience I caused :). I did everything exactly right, instead of 1 thing. When calling a ON or OFF command you can program a script to be triggered. I had

Code: Select all

script://home/pi/domoticz/scripts/wemo/wemo_on.sh
. What was missing of course, that I needed to have three forward slashes like so

Code: Select all

script:///home/pi/domoticz/scripts/wemo/wemo_on.sh
.

Now it works and it is solved.

Re: Bash Script - Virtual switch not starting bash script

Posted: Monday 27 February 2017 21:52
by SweetPants
Glad it works, that is Why I said "Have you searched the forum". Depending where your script is located, you need to use 2 or 3 slashes.

Re: Bash Script - Virtual switch not starting bash script

Posted: Monday 27 February 2017 21:54
by krizzz
SweetPants wrote:Glad it works, that is Why I said "Have you searched the forum". Depending where your script is located, you need to use 2 or 3 slashes.
Searched it yes, only did not crossed my mind to specifically check this. Sometimes it is hard to make the connections in your head :). Thanks for the help though. Let it be a lesson for the rest :D

Re: Bash Script - Virtual switch not starting bash script

Posted: Friday 13 October 2017 8:22
by RezzZ
Hi Guys, to continue on this topic, I have the exact same problem.
I created a bash script to turn down my nas over ssh. I made sure the pi user can login to the nas without specifying un/pw by copying ssh keys.

I created the script here:
/home/pi/domoticz/scripts/bash/poweroff_nas.sh

and it works when I execute it from the folder.

In domoticz I created a dummy hardware switch in the hardware section and created a dummy switch in the switch tab based on it. I changed the type to an off button and gave the 'Off Action:' the following path:

Code: Select all

script:///home/pi/domoticz/scripts/bash/poweroff_nas.sh
In the switch log it says the button is pushed but the script is not executed. Is there something I'm missing? Can I check some logs to see what is going on?

alright, I've been to quick, found the log and a possible solution:
viewtopic.php?t=6733

lets try to get a new ssh key for my root user then.

update:
ok, after a 'sudo su' and generating and copying the root ssh keys to my nas all works fine. yeah!