Page 1 of 3
tigger shell script automation
Posted: 16 Oct 2014 14:51
by pixi
Hello.
I have read the manual for z-wave-server v1.7 but i don't think i under stand how to use it
What i want is to execute a shell script when a event occur (temperature change, switch status, ....)
I want to add the device id , status , ... as an arguments to the script, is it possible to do thius ??
Can someone point me in the right direction ??
Thanks for a wonderful hardware (razberry) and software
Andreas H
Re: tigger shell script automation
Posted: 16 Oct 2014 22:32
by crayoneater
Hello, I have been trying to figure out how to do something similar with my door sensors and my garage tilt sensor. I really just want to execute a simple command when they change status to true or "on". I thought it would work to do something like this:
Code: Select all
zway.devices[21].instances[0].commandClasses[48].data[1].level.bind(function() {
if (this.value == true)
os.system('command');
});
but I was unable to get this to work. I would like to hear what others have to say about this.
EDIT: I believe that the os.system() reference that I saw in these forums is meant for python, although I do not see how to run python scripts. The post was very old. I was actually trying to run the command 'curl', so I just used http.request which is probably a better way to do what I wanted anyway. I'm still not sure how to run a system command, or if it's even possible.
Re: tigger shell script automation
Posted: 23 Oct 2014 02:48
by pofs
Yes, it is possible. Just use system() without "os" prefix.
But you need to add the scripts you want to run into .syscommands file (one script per line) first. It is made to prevent unauthorized (and possibly dangerous) scripts from running.
Re: tigger shell script automation
Posted: 05 Jun 2015 00:59
by jstaffon
I need even more of a basic explanation. Where do I find the code to add in a system() call or adding my own scripts? Somehow I've missed that in the manuals. Most of the explanations in this forum assume you already know how to find the current scripts and how to link or call scripts you write yourself? Thanks in advance!
Jeff.
Re: tigger shell script automation
Posted: 11 Jun 2015 23:05
by jstaffon
Crayoneater,
crayoneater wrote:Hello, I have been trying to figure out how to do something similar with my door sensors and my garage tilt sensor. I really just want to execute a simple command when they change status to true or "on". I thought it would work to do something like this:
Code: Select all
zway.devices[21].instances[0].commandClasses[48].data[1].level.bind(function() {
if (this.value == true)
os.system('command');
});
but I was unable to get this to work. I would like to hear what others have to say about this.
EDIT: I believe that the os.system() reference that I saw in these forums is meant for python, although I do not see how to run python scripts. The post was very old. I was actually trying to run the command 'curl', so I just used http.request which is probably a better way to do what I wanted anyway. I'm still not sure how to run a system command, or if it's even possible.
I sent you a private message about this post but I'm not sure it was sent. I was wondering which file you edited/created to add the 'if' statement and "system()" command. This will solve a problem I'm having where I send my cell phone a text message when a sensor triggers. Thanks in advance!
Jeff.
Re: tigger shell script automation
Posted: 12 Jun 2015 10:04
by pz1
Do use the Load custom JavaScript code module of Home Automation. Paste the JS code presented here (or similar). Restart Z-Way. PS: Do omit the 'os.' before the system call.
Depends a bit on the Z-Way version you use, where you can find the module
Re: tigger shell script automation
Posted: 12 Jun 2015 16:17
by jstaffon
pz1,
Thanks for the reply. Is the above code the only code needed? I have created a module as you and crayoneater suggested but it doesn't seem to work. I know for a fact the script on my Raspberry Pi works because I modified the Notification module to call the script and send an email. I also know the Ecolink PIR-Zwave2 sensor works because I have it added as a device and its state changes from off to on when motion occurs in the Home Automation UI.
I'm a software developer from the olden days and don't have much experience with classes, etc. My experience is with C and the Unix operating system. I'm trying to understand what triggers the code above. I can see it getting loaded as a module, but does it continue to loop or is there an event that causes the code to execute and check the status or state of the device?
In determining my device id or number, I went into the Expert UI under Configuration/Interview tab and used the DeviceID number and replaced the '21' in zway.devices[] variable with it. Mine happens to be '5'.
Also, is there documentation I should be reading to understand better how the Command Classes works with the Z-Way code and understand the classes, variables or structures that I need to work with. Where are they defined...i.e. the zway.devices....? In looking at the Command Class in the Expert UI under Configuration/Interview for "SensorBinary" I see the following.
UPDATE: I found the Z-Way Developers Documentation. I now understand how the code is executed and how it matches up with the Command Class and how the zway variable is defined.
I still don't quite see the matchup in variable names in the code I'm using. The variable "level" seems to change from 'false' to 'true' on motion. I'm missing something.
-- SensorBinary
/: None (10.06.2015)
1: None (07:10)
sensorTypeString: General purpose (10.06.2015)
level: false (07:10)
supported: true (10.06.2015)
version: 1 (10.06.2015)
security: false (10.06.2015)
interviewDone: true (10.06.2015)
interviewCounter: 9 (10.06.2015)
typemask: 2 (10.06.2015)
--
Here's the code for my sensor:
--
zway.devices[5].instances[0].commandClasses[48].data[1].level.bind(function() {
if (this.value == true)
system('/opt/z-way-server/automation/userModules/security-alert.bash');
});
--
Thanks in advance!
Jeff.
Re: tigger shell script automation
Posted: 12 Jun 2015 16:47
by pz1
I am in a hurry so only a quick reply:
Did you copy script path
Code: Select all
/opt/z-way-server/automation/userModules/security-alert.bash
into file
automation/.syscommands (do mind the dot before syscommands)
Re: tigger shell script automation
Posted: 12 Jun 2015 17:25
by jstaffon
Yes I did. I had to put that entry in so my modified 'Notification' module would work. I've also double-checked the spelling/syntax.
Thanks in advance and thank you for your time on this issue. I feel very close to resolving my problem.
Jeff.
Re: tigger shell script automation
Posted: 12 Jun 2015 17:58
by jstaffon
UPDATE: Problem solved. I cut and pasted the code that wasn't working in the 'CustomUserCode' module and pasted it into a file for the 'CustomUserCodeLoader' module. I deleted the original/non-working 'CustomUserCode' automation module, restarted the zway server and everything works fine. I carefully looked at both code segments, and could not see any difference. The only thing I can figure out is that the copying and pasting process created some unknown hidden characters that the module didn't like. If I find time, I'll hand type the code into the code window to see if that works. Thanks all for your help. This was a very interesting exercise.
Jeff.