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


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

--

Legend:

Unmodified
Added
Removed
Modified
  • Lua/Fibaro/TheButton

    v1 v1  
     1
     2{{{
     3-- File: Thebutton.lua
     4-- Define the names on your devices here:
     5local remotecontrol = "The Button"
     6local device1 = "Button 1 click"
     7local device2 = "Button 2 click"
     8local device3 = "Button 3 click"
     9local device4 = "Button 4 click"
     10local device5 = "Button 5 click"
     11
     12-- DO NOT EDIT BELOW THIS LINE --
     13
     14COMMAND_CLASS_CENTRAL_SCENE = 0x5B
     15CENTRAL_SCENE_NOTIFICATION = 0x03
     16
     17local deviceManager = require "telldus.DeviceManager"
     18
     19function onZwaveMessageReceived(device, flags, cmdClass, cmd, data)
     20        if device:name() ~= remotecontrol then
     21                return
     22        end
     23        if cmdClass ~= COMMAND_CLASS_CENTRAL_SCENE or cmd ~= CENTRAL_SCENE_NOTIFICATION then
     24                return
     25        end
     26        if list.len(data) < 3 then
     27                return
     28        end
     29        local sequence = data[0]
     30        local action = data[1]
     31        local scene = data[2]
     32        print("CENTRAL_SCENE_NOTIFICATION from Device: %s, Scene: %s, Action: %s", device:name(), scene, action)
     33       
     34        if action == 0 then -- 1 Click
     35                local device = deviceManager:findByName(device1)
     36                device:command("turnon", nil, "Scene")
     37                print("Turning on device: %s", device1)
     38        elseif action == 1 then -- Release
     39               
     40        elseif action == 2 then -- Press and hold
     41               
     42        elseif action == 3 then -- 2 Click
     43                local device = deviceManager:findByName(device2)
     44                device:command("turnon", nil, "Scene")
     45                print("Turning on device: %s", device2)
     46        elseif action == 4 then -- 3 Click
     47                local device = deviceManager:findByName(device3)
     48                device:command("turnon", nil, "Scene")
     49                print("Turning on device: %s", device3)
     50        elseif action == 5 then -- 4 Click
     51                local device = deviceManager:findByName(device4)
     52                device:command("turnon", nil, "Scene")
     53                print("Turning on device: %s", device4)
     54        elseif action == 6 then -- 5 Click
     55                local device = deviceManager:findByName(device5)
     56                device:command("turnon", nil, "Scene")
     57                print("Turning on device: %s", device5)
     58        end
     59end
     60}}}