| | 1 | |
| | 2 | {{{ |
| | 3 | -- Define the names on your devices here: |
| | 4 | local remotecontrol = "Swipe" |
| | 5 | local device1 = "Swipe up/down" |
| | 6 | local device2 = "Swipe left/right" |
| | 7 | |
| | 8 | -- DO NOT EDIT BELOW THIS LINE -- |
| | 9 | |
| | 10 | COMMAND_CLASS_CENTRAL_SCENE = 0x5B |
| | 11 | CENTRAL_SCENE_NOTIFICATION = 0x03 |
| | 12 | |
| | 13 | local deviceManager = require "telldus.DeviceManager" |
| | 14 | |
| | 15 | function scene1(action) |
| | 16 | local device = deviceManager:findByName(device1) |
| | 17 | if action == 0 then -- UP |
| | 18 | device:command("turnon", nil, "Scene") |
| | 19 | print("Turning on device: %s", device1) |
| | 20 | end |
| | 21 | end |
| | 22 | |
| | 23 | function scene2(action) |
| | 24 | local device = deviceManager:findByName(device1) |
| | 25 | if action == 0 then -- DOWN |
| | 26 | device:command("turnoff", nil, "Scene") |
| | 27 | print("Turning off device: %s", device1) |
| | 28 | end |
| | 29 | end |
| | 30 | |
| | 31 | function scene3(action) |
| | 32 | local device = deviceManager:findByName(device2) |
| | 33 | if action == 0 then -- LEFT |
| | 34 | device:command("turnon", nil, "Scene") |
| | 35 | print("Turning on device: %s", device2) |
| | 36 | end |
| | 37 | end |
| | 38 | |
| | 39 | function scene4(action) |
| | 40 | local device = deviceManager:findByName(device2) |
| | 41 | if action == 0 then -- RIGHT |
| | 42 | device:command("turnoff", nil, "Scene") |
| | 43 | print("Turning off device: %s", device2) |
| | 44 | end |
| | 45 | end |
| | 46 | |
| | 47 | function onZwaveMessageReceived(device, flags, cmdClass, cmd, data) |
| | 48 | if device:name() ~= remotecontrol then |
| | 49 | return |
| | 50 | end |
| | 51 | if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then |
| | 52 | return |
| | 53 | end |
| | 54 | if list.len(data) < 3 then |
| | 55 | return |
| | 56 | end |
| | 57 | local sequence = data[0] |
| | 58 | local action = data[1] |
| | 59 | local scene = data[2] |
| | 60 | print("CENTRAL_SCENE_NOTIFICATION from Device: %s, Scene: %s, Action: %s", device:name(), scene, action) |
| | 61 | if scene == 1 then |
| | 62 | scene1(action) |
| | 63 | elseif scene == 2 then |
| | 64 | scene2(action) |
| | 65 | elseif scene == 3 then |
| | 66 | scene3(action) |
| | 67 | elseif scene == 4 then |
| | 68 | scene4(action) |
| | 69 | end |
| | 70 | end |
| | 71 | }}} |