-
Notifications
You must be signed in to change notification settings - Fork 0
/
livingRoomLighting.lua
71 lines (61 loc) · 2.73 KB
/
livingRoomLighting.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
-- devices
local livingRoomMultiSwitch = nil
local diningRoomTableLight = nil
local livingRoomLightStrip = nil
-- groups
local standingLamp = nil
local livingRoomLighting = nil
-- for getting messages from the multi-light switch
local switchChan = nil
-- for determining which device(s) to apply dial actions to
local lastAction = nil
function setup ()
livingRoomMultiSwitch = register("0x001788010d35f25f")
diningRoomTableLight = register("0x001788010bfadf37")
livingRoomLightStrip = register("0x680ae2fffe4577ac")
standingLamp = registerGroup(5)
livingRoomLighting = registerGroup(2)
switchChan = subscribe(livingRoomMultiSwitch.topic)
end
function loop ()
resp = switchChan()
-- I'm sure there's a better way to do this, but I am not a very
-- good Lua programmer, yet
if resp.action == "button_1_press_release" then
publish(livingRoomLightStrip.topicSet, { state = "TOGGLE" })
elseif resp.action == "button_2_press_release" then
publish(diningRoomTableLight.topicSet, { state = "TOGGLE" })
elseif resp.action == "button_3_press_release" then
publish(standingLamp.topicSet, { state = "TOGGLE" })
elseif resp.action == "button_4_press_release" then
publish(livingRoomLighting.topicSet, { state = "TOGGLE" })
elseif resp.action == "dial_rotate_left_step" or resp.action == "dial_rotate_left_slow" then
if lastAction == "button_1_press_release" then
publish(livingRoomLightStrip.topicSet, { brightness_step = -10 })
elseif lastAction == "button_2_press_release" then
publish(diningRoomTableLight.topicSet, { brightness_step = -10 })
elseif lastAction == "button_3_press_release" then
publish(standingLamp.topicSet, { brightness_step = -10 })
elseif lastAction == "button_4_press_release" then
publish(livingRoomLighting.topicSet, { brightness_step = -10 })
end
elseif resp.action == "dial_rotate_right_step" or resp.action == "dial_rotate_right_slow" then
if lastAction == "button_1_press_release" then
publish(livingRoomLightStrip.topicSet, { brightness_step = 10 })
elseif lastAction == "button_2_press_release" then
publish(diningRoomTableLight.topicSet, { brightness_step = 10 })
elseif lastAction == "button_3_press_release" then
publish(standingLamp.topicSet, { brightness_step = 10 })
elseif lastAction == "button_4_press_release" then
publish(livingRoomLighting.topicSet, { brightness_step = 10 })
end
end
if (resp.action == "button_1_press_release" or
resp.action == "button_2_press_release" or
resp.action == "button_3_press_release" or
resp.action == "button_4_press_release")
then
lastAction = resp.action
end
microSleep(1000)
end