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:
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.
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.
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!
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:
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!
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
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.
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.
Last edited by jstaffon on 12 Jun 2015 16:52, edited 1 time in total.
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.