Z-Way configuration tips. Home automation with Z-Way

Tips, Tricks and Scripts to enhance your home automation and workaround known device bugs, limitations and incompatibilities
Locked
User avatar
PoltoS
Posts: 4738
Joined: 26 Jan 2011 19:36

Z-Way configuration tips. Home automation with Z-Way

Post by PoltoS » 15 Feb 2011 20:02

Terms used in this documentation Buttons are devices used to send commands to dimmers, switches and other devices in Z-Wave network. Dimmers are devices used to vary the brightness of a light. Can have buttons. Switches are devices used to switch On and Off the light. Can have buttons. Use correct light levels for dimmers To set light level of a dimmer to 100% use Full or 99 value. To restore light level to last value use On value. Schedules are very flexible Schedules in Z-Way are made exactly as cron in Unix. If you are not familar, don't worry — there are not much to understand: There are tags Minute, Hour, Day, Weekday, Month Each tag consist of To–From/Every combination. If you set up Minutes 20–40/5 the schedule will be executed each hour at 20, 25, 30, 35, 40 minutes. 0–59/1 means every minute. 0–59/2 — every two minutes. To specify exactly 33 minute use 33–33/1 (/Every may be any) You can specify the same tag multiple times. In this case schedule is executed if either of them matches: Minute 1–5/1 and Minute 40–50/2 means execute schedued task at minute 1, 2, 3, 4, 5, 40, 42, 44, 46, 48 and 50. In other words, same tags are ORed You can specify different tags for the schedule. In this case the schedule is executed if all groups of tags are matched: Minute 0–59/30 [same as 0–30/30] and Hour 9–15/2 means every half an hour at odd hours: 9:00, 9:30, 11:00, 11:30, 13:00, 13:30, 15:00, 15:30. In other words, different tag groups are ANDed Note that in To–From sentence the From is included: in previous example the last execution time is 15:30! Finally, Minute 5–5/1 Hour 7–7/1 Weekday Monday-Monday/1 Month June-August means exactly at 7:05 on Monday during summer only Automatic switch off after 5 minutes This is a pretty basic scenario. Add two scenes switching the desired device on/off. Add two rules that will trap events from some button (it may be even the same device if it has buttons). The rule that traps Off would just activate scene Off, the rule On should activate scene On and do a delayed activation of scene Off. That's all! Always set up Scenes Even if the device is switched on directly, we encourage you to set up a scene for this and add appropriate rules. Why? Because you will not only see the device status on the map, but also see the room status correctly (current active scene). Suppose you have one switch with buttons in the hall. These buttons controls the switch directly. If you will not set up scenes, rules and associations from this device to Z-Way, you will never be able to see hall's state on the map. More over, you will not be able to use the state of hall light in other rules (for example, if you switch off the light in bathroom during the night, turn the light in the hall on for 1 minute only in case it was off, otherwise do nothing). Intercept dimmer commands Dimmers change their level slowly. This can be used to to send interceptor commands: two different commands can be sent one after another: 100% and 50%. Only 50% would apply. The user would not notice that 100% was sent. In contrast, relays (switches) acts faster and you can not send two subsequent On, Off commands. Where can this be used? See next tip. Do as much direct associations as you can This is important for failover configurations. Suppose you have a dimmer that control lights in a room and a button. You want some smart scenes in this room: set the dimmer brightness to 30% from 0:00 till 6:00 and to 100% from 6:00 till 0:00. To do this associate the button to the dimmer and to Z-Way set up three scenes: dimmer set to 0% (off) dimmer set to 30% (night scene) dimmer set to 100% (day-evening mode) set up three rules that will trap the button presses: Off press: event source = button, event value = 0 (off), activate scene 1 On press: event source = button, event value = 255 (on) and time is from 0:00 to 6:00, activate scene 2 (see another tip about time conditions) On press: event source = button, event value = 255 (on) and time is from 6:00 to 0:00, activate scene 3 Everything is obvious except for the direct association of the button with the dimmer. What is it for? If everything is OK, the button will send a direct command to the dimmer (0% or 100%) and another to Z-Way. Z-Way will send another command to the dimmer and override previous command depending on the current hour. So, direct association seems to be useless. But if your controller goes down for some reason (power failure, misconfiguration, etc) the light in this room will be still operable: you will lose smart scenes, but the light will work. More over with this direct association button can dim/brighten the dimmer directly (bypassing Z-Way, since no rule trap this event). Know last value sent to Z-Way by a device In condition scripts you can check for the last value sent by a device to Z-Way due to association. For this use the following path: ZWaveAPI.devices[the device node Id].instances[0].Basic.data.lastset[Z-Way node Id][Z-Way instance].value The array lastset[][] have subscripts [destination node Id][destination instance Id]. The destination node Id can be set to Z-Way's node Id or it's Virtual devices' node Id. Z-Way instance should usually be 0, but if case of multi instance association it may be equal to the instance Id of Z-Way you used in the association. Note that the you have to check that these subscript exists (using .lastset.has_key(some id) and .lastset[some id].has_key(some instance)). Otherwise an exception will be raised and the rule would not be executed. Control light from two motion detectors Where is the problem? Suppose you have two basic motion detecotors (like Express Control E-Z Motion or ACT ZIR) that can turn the light off after some delay after last motion seen. Let's call them MD1 and MD2. Ususally you want the light to be turned off after 1 minute after the last motion seen by both detectors. If you are moving slowly and you escaped from the range of the first motion detector (MD1), to the range where MD2 will still see you, the MD1 will try to turn the light off (after timeout of one minute) regardless that MD2 still sees you. How to correct this? There are two cases: mains powered and battery powered motion detectors. Mains powered If mains powered, some motion detecotrs (like E-Z Motion) are configured to send commands on each motion seen. Both detectors should be associated to sends commands to Z-Way. As described above, do automatic switch off of you lights. For On event use events from both motion detectors as source (use OR logical operator in rule condition). Upon receive of new motion event Z-Way will activate the scene On (even if it was alredy active) and override the timer for the scene Off (restart the timer). The Off event from motion detectors can just be ignored and there should be no direct accotiation between detectors and light (you may keep this direct association if the target light is a dimmer and you handle Off events correctly to override them from Z-Way — see corresponding tip about interception of dimmer commands). Battery powered Thr above schema would not work with battery powered devices. Why? Consider the following example. As described in the example above, if you have escaped from the range of the first detector and you are dancing half an hour in front of the second one, the former will send Off event (certainly ignored by automation engine), but the latter will not send On event, since it still sees you. In that case you have to do the following trick in rules: As usually switch on the light in On events on On events from motion detectors. Do not use timers to siwtch off. Instead do a rule Logic AND
Logic OR
Event
Source: first detector (MD1)
Event
Source: first detector (MD2)
Event
New Value Off (0)
Script
(not ZWaveAPI.devices[MD1].instances[0].Basic.data.lastset.has_key(2) or not ZWaveAPI.devices[MD1].instances[0].Basic.data.lastset[2].has_key(0) or ZWaveAPI.devices[MD1].instances[0].Basic.data.lastset[2][0].value == 0) and (not ZWaveAPI.devices[MD2].instances[0].Basic.data.lastset.has_key(2) or not ZWaveAPI.devices[MD2].instances[0].Basic.data.lastset[2].has_key(0) or ZWaveAPI.devices[MD2].instances[0].Basic.data.lastset[2][0].value == 0)
Activate
Activate your scene to switch your light Off
This will use the Off event from detectors to switch the light off only if both of them reported Off. If the last command from one of them was On, skip this rule. Of course the same can be done using two zones that saves the event from each detector (activate scenes On and Off on appropriate events) and one more rule that will switch the light off if both of these two zones have scenes Off. Adjust light level depending on natural luminosity level Once it becomes darker in the room, Z-Way can change dimmer level to compensate the missing natural light. If the level of natural light will become sufficient, Z-Wave can dim the light approprierely. For this to work you need a luminosity sensor. For example, Express Control E-Z Motion. To configure all this magic you need to have the luminosity sensor present in the Polling schedule (or make a new schedule explicitely to run a scene with appropriate Get command: for Express Controll E-Z Motion it would be Instance 2, Command Class SensorMultilevel, Get command. Make a rule that will trap the Report from the device Logic OR
Event
Source: luminosity sensor
Source Instance: 2
Report
Activate
Activate your scene to adjust light level
You can also add more conditions to the AND block, for example check for the current state of a zone to adjust light level only in some special mode. The scene activate should only have a script: ZWaveAPI.devices[DIMMER_DEVICE_ID].instances[0].Basic.Set(100 - int(ZWaveAPI.devices[LUMINOSITY_SENSOR_DEVICE_ID].instances[2].SensorMultilevel.data.val.value) Cyclic scenes. Control more than one group of light with one button If you have from two to four groups of light in your room, you usually you don't want to control each group separately — you want scenes. And ususally you want 2–4 scenes: Off, Comfort, TV, Full. Is it possible to control all these groups from one button? Yes! Try cyclic scenes: each time you press On button, the active scene is switched to next one. The light is turned off at any time you press Off button. To set it up do the following: prepare four scenes with appropriate devices states: Off, Comfort, TV, Full create 4 rules on Off event activate scene Off on On event check active scene on your area and if it is Off, Full or undefined, activate scene Comfort on On event check active scene on your area and if it is Comfort activate scene TV on On event check active scene on your area and if it is TV, activate scene Full Note the undefined state in rule 2! The state of a zone would be undefined only after software reboot, but you have to handle this to enter into the cycle correctly. Vacancy, Away and other global modes To set up some global mode create a zone in technical subtree (or whereever you want, let's call it At home) and create two (or more) scenes, for example, Family at home, Bruce only at home, Away. Duplicate all events that should differ depending on that global mode and insert into AND condition one more check: active scene for zone At home is ... Don't forget to include undefined value in one of the rules. The mode can be swotched manualy from the interface or by any button in the network as a simple scene activation. Remember, that zone = global mode, active scene = currently selected mode. Execute external command You can run external commands and scripts from Z-Way. This can be used to control some external software/hardware, send E-Mails and SMS or even make SIP calls via Asterisk! To run command append script to a scene and add the following into the script os.system("my_favorite_program_to_play_music") Send an Email The following command can be used on Linux to send an E-Mail /usr/sbin/sendmail address@example.com <<END
To: address@example.com
From: mymail@example.com
Subject: Subject
Text message...
Long text message...
END
Se above how to execute external commands. Some external software may be required to install and configure. Send an SMS The following command can be used on Linux to send an SMS via SIP operator: sipsak -a <password> -u <user> -M -v -s sip:+79261234567@sip.voipdiscount.com -B "My first messge"
Se above how to execute external commands. Some external software may be required to install and configure. Control VLC multimedia player on distant PC from Remotec remote control Recent version of Remotec remote Z-URC 550X is able to send A/V button presses to Z-Way via Z-Wave network. Z-Way is able to convert them into commands to Z-Wave to IR device or to TCP/IP commands for network players like VLC. To configure it first run VLC with some additional parameters. These can be also stored in VLC config file: vlc --extraintf rc --rc-host <ip>:<port> Create a new scene in some zone (preferably in technical subtree). Name it VLC Add script with the following content: #print ev.value # for debug purpose

button = None
if ev.value[2] == "Pause":
button = "pause"
elif ev.value[2] == "Volume up":
button = "volup"
elif ev.value[2] == "Volume down":
button = "voldown"

if button is not None and ev.value[0] == "Key Down":
import os
os.system("echo '" + button + "' | /bin/nc <ip> <port>")
make new rule VLC with the following condition Logic AND
Event
Source node = remote with A/V buttons
Script
ev.eventId == ZWaveAPI.events.types['AV']
In action add activate scene VLC. This demo script shows how to map Pause, Volume up and down buttons to VLC functionality. Not that VLC can be run on another computer and is controlled via TCP/IP. More buttons can be mapped and more player can be controlled this way. Emulate key press in Unix X Window Sometimes it may be useful to control some software via keypress emulation. Here is an example how to emulate key Up on :0 screen: os.system('xmacroplay-keys :0 Up Left')
Technical. Polling devices To know the state and meters of every device you have to poll them. The polling is done by running a special scene. Create in some thechical subtree a zone (call it Polling) and make a scene in this zone having only one script: devices = ZWaveAPI.devices
pollCCs = [0x30, 0x31, 0x32, 0x25, 0x26] # sensorB, sensorML, Meter, switchB, switchML
skipNodes = [ZWaveAPI.controller.data.nodeId.value, 255]

for nodeId in filter(lambda (nodeId): nodeId not in skipNodes and not devices[nodeId].data.isVirtual.value, devices.keys()):
for instanceId in filter(lambda (instId): instId > 0 or len(devices[nodeId].instances) == 1, devices[nodeId].instances.keys()):
for ccId in filter(lambda(x): devices[nodeId].instances[instanceId].commandClasses.has_key(x), pollCCs):
logging.rules.info("Poll #%d.%d CC %d @ %2d:%2d utc" % (nodeId, instanceId, ccId, time.gmtime().tm_hour, time.gmtime().tm_min))
devices[nodeId].instances[instanceId].commandClasses[ccId].Get()
Activate this scene from schedule as frequent as you want. We recomment to use polling interval of 5–10 minues if you are not particulaty interested in devices states. If you need to track changes in states, use interval of 1 minute. For big networks it is recommended to make it every 2 minute and separate interview on two or more parts not to stuck the queue during polling to allow fast execution of user interactive commands (such as switching on/off the light). You can edit this script as you like, for example, excluding some nodes from polling (add these nodes to skipNodes list). Techincal. Device data autosave Z-Way software stores information about all devices in memory. This information is used not only to save devices capabilities, but also to remember current devices states and light levels. During clean shutdown this information is stored on the disc. It is a good idea to autosave this information every 10 minutes or something about that. This depends on the type of your disk storage (Flash, HDD, network disc etc) and intensity of changes in your network. To enable autosave have a schedule that runs every 10 minues and that triggers a special scene, having only a script: ZWaveAPI.devices.SaveData() We recommend to always keep this schedule active. To store the scene create a subtree for technical scenes and try to store one scene in one zone (So, you will have Flat with childs: Floor1, Floor2, ..., Technical. Technical should have Save Devices Data, Polling, ...) Technical. Update Z-Wave Device Description Records (XML) To be more user friendly and show human readable description of devices and their configuration parameters Z-Way uses Z-Wave Device Description database. This database was created by PepperOne certification center in collaboration with us. We are constantly trying to maintain this database up to date and describe all new comming as well as existing devices. To keep Z-Way updated you have to run a special script from time to time. We propose to use schedules to do this task for you. For this you have to set up a weekly schedule and run a special scene with the following script: os.system("cd ZDDX; ./UpdateXMLs.sh") Of course you can activate the scene manualy if you would like to be updated immediatelly. Techincal. Request network updates from SUC/SIS If Z-Way is not primary, SUC or SIS and SUC/SIS is present in the network, to keep routes updated it is strongly recommended to get network toppology updates from SUC/SIS. For this create everyday schedule (Minutes = 0-0/1, Hours=0-0/1 will be every day at midnight) and activate a newly created scene having only the following script: ZWaveAPI.RequestNetworkUpdate() Techincal. Reporting values to CSV or DB ... Advanced knowledge about timers in Z-Way rules engine Timers can be set only in actions of rules and schedules, but never in scenes. This is because a scene defines some current state, while schdules and rules are for user actions (button is pressed, action is triggered from web interface or scheduled timer has fired). It is important to remember that all timer set up for delayed scenes are purged on scene change. But delayed events are kept and will raise even if the scene has changed since the timer was set up. To be continued... Scripting with Z-Way Z-Way allows you to write Python scripts in rule condition and in script action. There are some general rules to follow: scripts used in conditions are eval–scripts — they have to return value and be one line scripts used in scenes are exec–scripts —they can be multiline namespace used in scripts is the following ev — current event { eventId, srcNodeId, srcInstanceId, dstNodeId, dstInstaneId, value }. ev.value is an array. ZWaveAPI — Z-Wave API object RulesManager — rules manager object time — Python time module (to obtain current time) os — Python os object to execute external software using os.system("shell_script") logging — to write into log file: use logging.program.info("Hello world") Python uses idention to mark blocks of code, so don't use idention (spaces or tabs) at the beginning of lines except for blocks inside if, for, while statements. everything from # to the end of line is a comment to obtain information about a device use ZWaveAPI.devices[5].instances[0].Basic.data.level.value for last reported Basic Report value ZWaveAPI.devices[5].instances[0].Basic.data.lastset[1][0].value for last value send to controller as Basic Set value. [1][0] means to controller nodeId = 1 (there may be virtual nodes, but usually this is the controller nodeId), instanceId = 0 (controller have multiple instances to distinguish between different buttons of one device). to get time of the value update (Unix timestamp) use .updateTime instead of .value at the end Send commands into Z-Way from outside It is possible to control Z-Way from outside: activate scenes, change devices states, send Z-Wave commands and even do network management. All interaction is done via HTTP protocol and can be done from any authenticated computer. The protocol is quite complex. To get more information about how to set up interaction between Z-Way and your software please contact Z-Way developers team.

Locked