| 1 | |
| 2 | {{{ |
| 3 | local deviceManager = require "telldus.DeviceManager" |
| 4 | |
| 5 | function control_device(device, action) |
| 6 | local device = deviceManager:findByName(device) |
| 7 | if device == nil then |
| 8 | return |
| 9 | end |
| 10 | if action == "ON" and device:state() == 2 then |
| 11 | print("%s - %s", device:name(), action) |
| 12 | device:command("turnon", nil, "RGB") |
| 13 | elseif action == "OFF" and device:state() == 1 then |
| 14 | print("%s - %s", device:name(), action) |
| 15 | device:command("turnoff", nil, "RGB") |
| 16 | end |
| 17 | end |
| 18 | |
| 19 | |
| 20 | function onZwaveMessageReceived(device, flags, cmdClass, cmd, data) |
| 21 | if cmdClass ~= 0x26 or cmd ~= 3 then |
| 22 | return |
| 23 | end |
| 24 | name = device:name() |
| 25 | print("%s - %s", name, data[0]) |
| 26 | name = string.gsub(name, "IN", "OUT") |
| 27 | if data[0] < 50 then |
| 28 | action = "OFF" |
| 29 | else |
| 30 | action = "ON" |
| 31 | end |
| 32 | control_device(name, action) |
| 33 | end |
| 34 | }}} |