Access ZWaveAPI through Python script on Raspberry

Discussions about RaZberry - Z-Wave board for Raspberry computer
michap
Posts: 437
Joined: 26 Mar 2013 10:35
Contact:

a sample for event...

Post 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 ;)



dickymoe
Posts: 10
Joined: 02 Apr 2013 15:00

It will be easier for you to

Post by dickymoe »

It will be easier for you to use resquests module in python
Just to do :
requests.get("...")

:)
rabing
Posts: 31
Joined: 08 Mar 2013 03:00

event

Post 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?
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

You had to replace the line

Post by PoltoS »

You had to replace the line in config.xml. Current is quite useless for now.
holzemile
Posts: 36
Joined: 27 Mar 2013 13:37

getting stored values works

Post 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
rabing
Posts: 31
Joined: 08 Mar 2013 03:00

yes, preplacing the line

Post 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.
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Either the device will send

Post by PoltoS »

Either the device will send you the temperature periodcally, or yu need to poll it using a .Get() function
danilo
Posts: 11
Joined: 16 Feb 2013 00:33

Same with python script - what is wrong here?

Post 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 .
User avatar
PoltoS
Posts: 7562
Joined: 26 Jan 2011 19:36

Please try

Post 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.
danilo
Posts: 11
Joined: 16 Feb 2013 00:33

thanks

Post by danilo »

Thanks for the quick response I will try
Post Reply