Page 2 of 2
a sample for event...
Posted: 19 Mar 2013 02:59
by michap
Hi,
this is working for me (just a simple sample) :
create test1.js and place it into automation directory
content of test1.js:
zway.devices[5].instances[0].commandClasses[48].data.level.bind(function() {
try {
system("sh /opt/test.sh " + this.value);
} catch(err) {
debugPrint("Failed to execute command: " + err);
}
});
(if any error you will see it in log)
-----------
edit the config.xml in /opt/z-way-server/:
..
automation/test1.js
..
-----------
create test.sh:
TODAY=`date '+%F %H:%M:%S'`
echo "$TODAY - param1: $1" >> /var/log/test.txt
-----------
in /opt/z-way-server/htdocs create the file .syscommands with one line only:
sh
-----------
restart Z-Way : /etc/init.d/Z-Way restart
-----------
you will get in test.txt (for motion sensor):
2013-04-03 09:29:29 - param1: true
2013-04-03 09:29:48 - param1: false
Hope this helps
It will be easier for you to
Posted: 19 Mar 2013 02:59
by dickymoe
It will be easier for you to use resquests module in python
Just to do :
requests.get("...")
event
Posted: 19 Mar 2013 02:59
by rabing
Thanks, for the nice example. It did not work exactly as described. I had to put
the callback function in the "automation/main.js" file. I'm not sure if you can have
2 lines with:
...
in config.xml?
You had to replace the line
Posted: 19 Mar 2013 02:59
by PoltoS
You had to replace the line in config.xml. Current is quite useless for now.
getting stored values works
Posted: 19 Mar 2013 02:59
by holzemile
getting stored values works perfect!
-- response = requests.post("http://.../ZWaveAPI/Run/devices[3].data.isFailed.value")
But how would I get a fresh value(like temperature) in python?
Because this returns just the last value I got when getting the value vie the demo UI:
-- .instances[0].commandClasses[48].data.level.value
yes, preplacing the line
Posted: 19 Mar 2013 02:59
by rabing
yes, preplacing the line worked. It seems like I can't ask for another value via http request
while I'm in the event handler script? I tried to make a curl request to read the status of a
binary switch. But it always returned null (empty string). Outside the event script the curl
request works fine.
Either the device will send
Posted: 19 Mar 2013 02:59
by PoltoS
Either the device will send you the temperature periodcally, or yu need to poll it using a .Get() function
Same with python script - what is wrong here?
Posted: 19 Mar 2013 02:59
by danilo
I am trying the same with a python script and a sensor value but somehow fail. I do this:
1.)--------Write automation file my_main.js --------------------
zway.devices[2].instances[1].commandClasses[0x31].data[4].val.bind(function() {
try {
system("python /home/pi/Desktop/my_script.py " + this.value);
} catch(err) {
debugPrint("Failed to execute script system call: " + err);
}
});
2.) --------------replace main.js in config.xml with my_main.js--------
3.)-----------create .syscommands line --------------
I put the python script file pathname in the .syscommands file:
/home/pi/Desktop/my_script.py
4.) -------- restart Z-Way server --------
However my_script.py gets never called. Where would I find the errorlog of the system call?
I there anything fundamentally wrong with my approach above?
I am bit lost .
Please try
Posted: 19 Mar 2013 02:59
by PoltoS
Please trysystem("python /home/pi/Desktop/my_script.py", this.value);and edit .syscommandspython /home/pi/Desktop/my_script.pyThe path in .syscommands should match the first argument passed to system.This was my error - I mislead people on the forum with a wrong exmaple.
thanks
Posted: 19 Mar 2013 02:59
by danilo
Thanks for the quick response I will try