Hi,
I manage to access my Z-Wave Sensors through the ZWaveAPI with JSON commands from my Webbrowser.
Now I would like to log data with a Python Script on the Raspberry directly.
How do I access the ZWaveAPI from a Python Script on the Raspberry?
(E.g in the browser I write something like this http://IP_OF_RASPBERRY:8083/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x31].data.val.valueOf() . How would that line have to look if I want to read the same data in a Python script right on the Raspberry?)
Any hints or sample code is most appreciated
Regards,
danilo
Access ZWaveAPI through Python script on Raspberry
Easy... here is a simplistic example...
import httplib
class ZWay:
def __init__(self, address):
self.address = address
def __performGetRequest(self, requestString):
response = None
try:
self.conn = httplib.HTTPConnection(self.address)
self.conn.request('GET', requestString)
res = self.conn.getresponse()
except:
print 'ERROR: __performGetRequest'
res = None
if res:
if res.status == 200:
response = res.read()
else:
print 'ERROR:', res.status, res.reason
return response
def getSensorBinary(self, nodeID):
v = None
if type(v) != None:
nodeID, instanceNr = nodeID.split(':')
response = self.__performGetRequest('/ZWaveAPI/Run/devices[%s].instances[%s].commandClasses.SensorBinary.data.level.valueOf()' % (nodeID, instanceNr))
if type(response) == str:
if response == 'true':
v = True
elif response == 'false':
v = False
return v
z = ZWay('rpi1:8083')
nodeID = '21:0' # node 21, instance 0
print('NodeID=%s -> value=%s' % (nodeID, z.getSensorBinary(nodeID)))
Greets,
Stefan
Catch an event
Hi,
is there a way to catch an event (like a move detector) with a python script?
Lutz
is there a way to catch an event (like a move detector) with a python script?
Lutz
Two ways:
Two ways:using polling from python (bad way)using JS callback with system callExample:zway.devices[X].instances[0].commandClasses.SwitchBinary.data.level.bind(function() {
system("python scrypt.py", this.value);
});This assumes SwitchBinary report is received on motion event.Make sure to have the first argument to system in .syscommands file (the list of allowed commands in the shell).Please consult bind() and system() description.
system("python scrypt.py", this.value);
});This assumes SwitchBinary report is received on motion event.Make sure to have the first argument to system in .syscommands file (the list of allowed commands in the shell).Please consult bind() and system() description.
OK, but where is the best
OK, but where is the best place to put the JS bind() to make "z-way-server" call
it in case of an event? Looks like a new module in the "automation" dir would be
a good place?
it in case of an event? Looks like a new module in the "automation" dir would be
a good place?
Yes, it is the right place,
Yes, it is the right place, but we are changing these modules right now.
Please use temporary .js file and place it directly in config.xml for startup. later on you will need to incorporate it in our engine (if you will want to use it)
Please use temporary .js file and place it directly in config.xml for startup. later on you will need to incorporate it in our engine (if you will want to use it)
About what API documentation
About what API documentation do you write? Can you give me a link?
Was using your suggestion - and get this error:
[2013-04-02 16:18:28.872] SETDATA devices.10.instances.0.commandClasses.48.data.level = True
Failed to execute command: System commands are not configured
(simple echo command was used)
Any idea?
Was using your suggestion - and get this error:
[2013-04-02 16:18:28.872] SETDATA devices.10.instances.0.commandClasses.48.data.level = True
Failed to execute command: System commands are not configured
(simple echo command was used)
Any idea?
Forgot to mention: create
Forgot to mention: create .syscommands file and put exact file name on each line to allow execution
and the syntaxt of the call is a nit different: system(script, param1, param2, ...)
and the syntaxt of the call is a nit different: system(script, param1, param2, ...)
to make a long story short ...
It would be really nice to have a short working example. What is needed to have the binary sensor
with ID: 5 commandClass: 0x30 call the the script "/opt/test.sh " in case of an event?
with ID: 5 commandClass: 0x30 call the the script "/opt/test.sh " in case of an event?