Is there an example for how to run a system command (shell script in my case) when triggering a CodeDevice in HA-UI (running 2.0.1 rc21)?
Would that be something that has to be combined with CustomUserCodeLoader?
Grateful for any pointer ...
Jonas
CodeDevice to run local code example?
Re: CodeDevice to run local code example?
Did you find out how to do that?
For me it interesting too.
For me it interesting too.
-
- Posts: 9
- Joined: 25 Feb 2014 19:30
Re: CodeDevice to run local code example?
Have you tried anything with CodeDevice? Haven't done this myself yet, but I would have tried first:zimmerleut wrote:nope ...
Code: Select all
system("/fullpath/your_bash.sh")
- make your script executable with
Code: Select all
sudo chmod +x /fullpath/your_bash.sh
- Add a line with: /fullpath/your_bash.sh to file
NOTA BENE: After every update you have to add this line to the .syscommand file
Code: Select all
/opt/z-way-server/automation/.syscommands
-
- Posts: 9
- Joined: 25 Feb 2014 19:30
Re: CodeDevice to run local code example?
Thanks for your reply. Unfortunately, it does not seem to work. (The file executes just fine from command line; it calls a program with the setuid bit set, so I don't think it's a permissions issue).
The logs only say that I pressed the button:
If I change to some non-existent function (e.g. ), there is a complaint in the logs about that.
Is there a way to find out more about what happens when gets called?
Thanks
Jonas
The logs only say that I pressed the button:
Code: Select all
[2015-04-03 00:04:25.215] [I] [core] Creating device toggleButton Code_Device_toggleButton_16
[2015-04-03 00:04:29.342] [I] [core] --- Code_Device_toggleButton_16 performCommand processing: {"0":"on","1":{}}
Code: Select all
system("/fullpath/your_bash.sh")
Code: Select all
os.call("...")
Is there a way to find out more about what happens when
Code: Select all
system()
Thanks
Jonas
Re: CodeDevice to run local code example?
I have used the same method to run a shell script and it works.
One aspect that may not have been considered is related to absolute paths in the ".sh" script. Since z-way code is run from root, you have to specify the absolute path.
A script like:
run from the command line will save the date and time values to the local directory where you launch the script (for example /home/pi)
with code device the script should me modified in the following way:
to find the date information in /home/pi directory
One aspect that may not have been considered is related to absolute paths in the ".sh" script. Since z-way code is run from root, you have to specify the absolute path.
A script like:
Code: Select all
#!/bin/bash
date > date.txt
with code device the script should me modified in the following way:
Code: Select all
#!/bin/bash
date > /home/pi/date.txt