CodeDevice to run local code example?

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
zimmerleut
Posts: 9
Joined: 25 Feb 2014 19:30

CodeDevice to run local code example?

Post 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
m_pete
Posts: 5
Joined: 15 Mar 2015 15:47

Re: CodeDevice to run local code example?

Post by m_pete »

Did you find out how to do that?
For me it interesting too.
zimmerleut
Posts: 9
Joined: 25 Feb 2014 19:30

Re: CodeDevice to run local code example?

Post by zimmerleut »

nope ... :(
pz1
Posts: 2053
Joined: 08 Apr 2012 13:44

Re: CodeDevice to run local code example?

Post by pz1 »

zimmerleut wrote:nope ... :(
Have you tried anything with CodeDevice? Haven't done this myself yet, but I would have tried first:

Code: Select all

system("/fullpath/your_bash.sh")
  1. make your script executable with

    Code: Select all

     sudo chmod +x /fullpath/your_bash.sh
  2. 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.
zimmerleut
Posts: 9
Joined: 25 Feb 2014 19:30

Re: CodeDevice to run local code example?

Post 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

Code: Select all

 system("/fullpath/your_bash.sh")
to some non-existent function (e.g.

Code: Select all

os.call("...")
), there is a complaint in the logs about that.
Is there a way to find out more about what happens when

Code: Select all

system()
gets called?

Thanks
Jonas
ha-dummy
Posts: 4
Joined: 29 Jan 2015 00:01

Re: CodeDevice to run local code example?

Post 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:

Code: Select all

#!/bin/bash
date > date.txt
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
Post Reply