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


Ignore:
Timestamp:
Oct 31, 2016, 2:33:19 PM (7 years ago)
Author:
Fredrik Gullberg
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • Lua/Fibaro/Swipe

    v1 v1  
     1
     2{{{
     3-- Define the names on your devices here:
     4local remotecontrol = "Swipe"
     5local device1 = "Swipe up/down"
     6local device2 = "Swipe left/right"
     7
     8-- DO NOT EDIT BELOW THIS LINE --
     9
     10COMMAND_CLASS_CENTRAL_SCENE = 0x5B
     11CENTRAL_SCENE_NOTIFICATION = 0x03
     12
     13local deviceManager = require "telldus.DeviceManager"
     14
     15function 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
     21end
     22
     23function 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
     29end
     30
     31function 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
     37end
     38
     39function 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
     45end
     46
     47function 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
     70end
     71}}}