| 1 | |
| 2 | {{{ |
| 3 | -- File: NodOn.lua |
| 4 | -- One click on the remote turns on a device |
| 5 | -- Double click on the remote turns off a device |
| 6 | -- Define the names on your devices here: |
| 7 | local remotecontrol = "NodOn" |
| 8 | local device1 = "Office" |
| 9 | local device2 = "Kitchen" |
| 10 | local device3 = "Garage" |
| 11 | local device4 = "Window" |
| 12 | |
| 13 | -- DO NOT EDIT BELOW THIS LINE -- |
| 14 | |
| 15 | COMMAND_CLASS_CENTRAL_SCENE = 0x5B |
| 16 | CENTRAL_SCENE_NOTIFICATION = 0x03 |
| 17 | |
| 18 | local deviceManager = require "telldus.DeviceManager" |
| 19 | |
| 20 | function scene1(action) |
| 21 | local device = deviceManager:findByName(device1) |
| 22 | if action == 0 then -- Press |
| 23 | device:command("turnon", nil, "Scene") |
| 24 | print("Turning on device: %s", device1) |
| 25 | elseif action == 1 then -- Release |
| 26 | elseif action == 2 then -- Press and hold |
| 27 | elseif action == 3 then -- Doubleclick |
| 28 | device:command("turnoff", nil, "Scene") |
| 29 | print("Turning off device: %s", device1) |
| 30 | end |
| 31 | end |
| 32 | |
| 33 | function scene2(action) |
| 34 | local device = deviceManager:findByName(device2) |
| 35 | if action == 0 then |
| 36 | device:command("turnon", nil, "Scene") |
| 37 | elseif action == 3 then -- Doubleclick |
| 38 | device:command("turnoff", nil, "Scene") |
| 39 | end |
| 40 | end |
| 41 | |
| 42 | function scene3(action) |
| 43 | local device = deviceManager:findByName(device3) |
| 44 | if action == 0 then |
| 45 | device:command("turnon", nil, "Scene") |
| 46 | elseif action == 3 then -- Doubleclick |
| 47 | device:command("turnoff", nil, "Scene") |
| 48 | end |
| 49 | end |
| 50 | |
| 51 | function scene4(action) |
| 52 | local device = deviceManager:findByName(device4) |
| 53 | if action == 0 then |
| 54 | device:command("turnon", nil, "Scene") |
| 55 | elseif action == 3 then -- Doubleclick |
| 56 | device:command("turnoff", nil, "Scene") |
| 57 | end |
| 58 | end |
| 59 | |
| 60 | function onZwaveMessageReceived(device, flags, cmdClass, cmd, data) |
| 61 | if device:name() ~= "NodOn" then |
| 62 | return |
| 63 | end |
| 64 | if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then |
| 65 | return |
| 66 | end |
| 67 | if list.len(data) < 3 then |
| 68 | return |
| 69 | end |
| 70 | local sequence = data[0] |
| 71 | local action = data[1] |
| 72 | local scene = data[2] |
| 73 | print("CENTRAL_SCENE_NOTIFICATION from Device: %s, Scene: %s, Action: %s", device:name(), scene, action) |
| 74 | if scene == 1 then |
| 75 | scene1(action) |
| 76 | elseif scene == 2 then |
| 77 | scene2(action) |
| 78 | elseif scene == 3 then |
| 79 | scene3(action) |
| 80 | elseif scene == 4 then |
| 81 | scene4(action) |
| 82 | end |
| 83 | end |
| 84 | }}} |