Page 1 of 1
CodeDevice to run local code example?
Posted: 15 Feb 2015 21:10
by zimmerleut
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
Re: CodeDevice to run local code example?
Posted: 31 Mar 2015 18:46
by m_pete
Did you find out how to do that?
For me it interesting too.
Re: CodeDevice to run local code example?
Posted: 31 Mar 2015 18:47
by zimmerleut
nope ...

Re: CodeDevice to run local code example?
Posted: 01 Apr 2015 11:21
by pz1
zimmerleut wrote:nope ...

Have you tried anything with CodeDevice? Haven't done this myself yet, but I would have tried first:
- 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
Code: Select all
/opt/z-way-server/automation/.syscommands
NOTA BENE: After every update you have to add this line to the .syscommand file
You should make the
CodeDevice as a
ToggleButton, which makes you can use it as a scene in schedules rules etc.
Re: CodeDevice to run local code example?
Posted: 03 Apr 2015 07:10
by zimmerleut
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:
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":{}}
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
Re: CodeDevice to run local code example?
Posted: 08 May 2015 15:53
by ha-dummy
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:
Code: Select all
#!/bin/bash
date > /home/pi/date.txt
to find the date information in /home/pi directory