Changes between Initial Version and Version 1 of Lua/NodOn/Remotecontrol


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

--

Legend:

Unmodified
Added
Removed
Modified
  • Lua/NodOn/Remotecontrol

    v1 v1  
     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:
     7local remotecontrol = "NodOn"
     8local device1 = "Office"
     9local device2 = "Kitchen"
     10local device3 = "Garage"
     11local device4 = "Window"
     12
     13-- DO NOT EDIT BELOW THIS LINE --
     14
     15COMMAND_CLASS_CENTRAL_SCENE = 0x5B
     16CENTRAL_SCENE_NOTIFICATION = 0x03
     17
     18local deviceManager = require "telldus.DeviceManager"
     19
     20function 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
     31end
     32
     33function 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
     40end
     41
     42function 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
     49end
     50
     51function 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
     58end
     59
     60function 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
     83end
     84}}}