Clarify Python things with ZWay/Razberry

Discussions about RaZberry - Z-Wave board for Raspberry computer
Colin
Posts: 15
Joined: 13 Sep 2013 22:00

Python Code for Razberry

Post by Colin » 02 Apr 2013 15:59

Here is a simple/crude piece of Python code for Z-wave Razberry [The Node ID of my Z-wave device is 2, the Command Class of a Binary Switch is 0x25, you can get these command class codes from "http://wiki.micasaverde.com/index.php/Z ... nd_Classes" by the way].

NOTE: You could add some code that makes this sort of thing run every say 1 second in an infinite loop and then write the results to a database or have an email alert sent out if a value changes or whatever:

Copy and paste the below 3 code blocks into 3 separate files (e.g. TurnOnSwitch.py, TurnOffSwitch.py, SwitchStatus.py, and then run them from the Raspberry Pi's command line (via Putty). e.g. python SwitchStatus.py

Turn on a Binary Switch (GE 45604 Z-Wave Technology Outdoor Module for Lighting Control):

import urllib2
print('Turn On Binary Switch...')
response = urllib2.urlopen('http://192.168.1.7:8083
/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].Set(255)')
html = response.read()
print html

Turn off a Binary Switch (GE 45604 Z-Wave Technology Outdoor Module for Lighting Control):

import urllib2
print('Turn Off Binary Switch...')
response = urllib2.urlopen('http://192.168.1.7:8083
/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].Set(0)')
html = response.read()
print html

To Get the Status (i.e. on or off) of the Binary switch (if the device is switched on the python code returns 255, if the device is switched off the code returns 0):

import urllib2
print('Binary Switch Status:')
response = urllib2.urlopen('http://192.168.1.7:8083
/ZWaveAPI/Run/devices[2].instances[0].commandClasses[0x25].data.level.valueOf()')
html = response.read()
print html

Post Reply