Bash Script - Virtual switch not starting bash script

All kinds of 'OS' scripts
Post Reply
krizzz
Posts: 171
Joined: Wednesday 20 November 2013 21:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Bash Script - Virtual switch not starting bash script

Post by krizzz » Wednesday 22 February 2017 23:51

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.

SweetPants
Posts: 2158
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.9866
Location: The Netherlands
Contact:

Re: Bash Script - Virtual switch not starting bash script

Post by SweetPants » Sunday 26 February 2017 12:04

How did you configure the ON/OFF action? Have you searched the forum, this has been handeled numerous times before.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (source)

krizzz
Posts: 171
Joined: Wednesday 20 November 2013 21:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Bash Script - Virtual switch not starting bash script

Post by krizzz » Monday 27 February 2017 22:17

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.

SweetPants
Posts: 2158
Joined: Friday 12 July 2013 21:24
Target OS: Linux
Domoticz version: V4.9866
Location: The Netherlands
Contact:

Re: Bash Script - Virtual switch not starting bash script

Post by SweetPants » Monday 27 February 2017 22:52

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.
Ubuntu 16.04.3 LTS, Intel NUC, MySensors 2.3.0-alpha, Pro Mini 3.3/8M RFM69(HW), ESP8266 (SDK2.2.0), Sonoff, RFLink, RFXcom, MQTT, NodeRed, Domoticz Beta (source)

krizzz
Posts: 171
Joined: Wednesday 20 November 2013 21:36
Target OS: Linux
Domoticz version:
Location: The Netherlands
Contact:

Re: Bash Script - Virtual switch not starting bash script

Post by krizzz » Monday 27 February 2017 22:54

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

RezzZ
Posts: 12
Joined: Friday 15 September 2017 17:33
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: Bash Script - Virtual switch not starting bash script

Post by RezzZ » Friday 13 October 2017 8:22

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest