Changes between Initial Version and Version 1 of Lua/Fibaro/RGBin


Ignore:
Timestamp:
Nov 22, 2016, 3:34:04 PM (7 years ago)
Author:
Fredrik Gullberg
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Lua/Fibaro/RGBin

    v1 v1  
     1
     2{{{
     3local deviceManager = require "telldus.DeviceManager"
     4
     5function 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
     17end
     18
     19
     20function 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)
     33end
     34}}}