-
Notifications
You must be signed in to change notification settings - Fork 11
/
hc3CodeTemplates.lua
158 lines (140 loc) · 3.91 KB
/
hc3CodeTemplates.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local version = "1.0"
local code = {
['Scene template'] =
[[if dofile and not hc3_emulator then
hc3_emulator = {
name = "My Scene", -- Name of Scene
poll = 2000, -- Poll HC3 for triggers every 2000ms
traceFibaro=true, -- Log fibaro.call and fibaro.get
--offline = true,
}
dofile("fibaroapiHC3.lua")
end--hc3
hc3_emulator.conditions = { -- example condition triggering on device 37 becoming 'true'
conditions = { {
id = 37,
isTrigger = true,
operator = "==",
property = "value",
type = "device",
value = true
} },
operator = "all"
}
function hc3_emulator.actions()
local hc = fibaro
jT = json.decode(hc.getGlobalVariable("HomeTable"))
-- Your code
end
]],
['QA template'] =
[[if dofile and not hc3_emulator then
hc3_emulator = {
name = "My QA", -- Name of QA
poll = 2000, -- Poll HC3 for triggers every 2000ms
--offline = true,
}
dofile("fibaroapiHC3.lua")
end--hc3
function QuickApp:onInit()
self:debug(self.name, self.id)
end
]],
['QA template with toolbox'] =
[[if dofile and not hc3_emulator then
hc3_emulator = {
name="My QA",
--proxy=true,
--deploy=true,
type="com.fibaro.deviceController",
poll=1000,
UI = {}
}
dofile("fibaroapiHC3.lua")
end--hc3
--FILE:Toolbox/Toolbox_basic.lua,Toolbox;
-- FILE("Toolbox/Toolbox_child.lua,Toolbox_child;
-- FILE("Toolbox/Toolbox_events.lua,Toolbox_events;
-- FILE("Toolbox/Toolbox_triggers.lua,Toolbox_triggers;
-- FILE("Toolbox/Toolbox_files.lua,Toolbox_files;
-- FILE("Toolbox/Toolbox_rpc.lua,Toolbox_rpc;
-- FILE("Toolbox/Toolbox_pubsub.lua,Toolbox_pubsub;
-- FILE("Toolbox/Toolbox_ui.lua,Toolbox_ui;
----------- Code -----------------------------------------------------------
_version = "0.1"
modules = {
-- "childs",
-- "events",
-- "triggers",
-- "files",
-- "rpc",
-- "pubsub",
-- "ui"
}
function QuickApp:onInit()
self:debug(self.name ,self.id)
end
]],
['Simple backup'] =
[[if dofile and not hc3_emulator then
dofile("fibaroapiHC3.lua")
end--hc3
local fs = "/"
local today = os.date("%x"):gsub("/","")
local qaDir = "QAbackup"..fs..today..fs -- Directory will be created if it doesn't exist.
local sceneDir = "Scenebackup"..fs..today..fs -- Directory will be created if it doesn't exist.
local function printf(...) print(string.format(...)) end
-- This is a script that backs up your QAs and Scenes from the HC3 and store them in a directory
local QAs = api.get("/devices?interface=quickApp")
for _,q in ipairs(QAs) do
printf("Backing up %s",q.name)
hc3_emulator.loadQA(q.id):save("fqa",qaDir)
end
local scenes = api.get("/scenes")
for _,s in ipairs(scenes) do
printf("Backing up %s",s.name)
hc3_emulator.loadScene(s.id):save("fsc",sceneDir)
end
]],
['MultilevelSwitch'] =
[[if dofile and not hc3_emulator then
hc3_emulator = {
name = "MyMultilevelSwitch", -- Name of QA
type = "com.fibaro.multilevelSwitch",
poll = 1000, -- Poll HC3 for triggers every 1000ms
offline = true,
UI = {
{label='info', text=''},
{
{button='turnOn', text='Turn On', onReleased='turnOn'},
{button='turnOff', text='Turn Off', onReleased='turnOff'}
},
{slider='val', min=0, max=99, onChanged='slider'}
}
}
dofile("fibaroapiHC3C.lua")
end--hc3
function QuickApp:turnOn()
self:updateProperty("value",99)
self:info()
end
function QuickApp:turnOff()
self:updateProperty("value",0)
self:info()
end
function QuickApp:slider(ev) self:setValue(ev.values[1]) end
function QuickApp:setValue(value)
self:updateProperty("value",value)
self:info()
end
function QuickApp:info()
local val = fibaro.getValue(self.id,"value")
self:updateView("info","text","Value is "..val)
self:updateView("val","value",tostring(val))
end
function QuickApp:onInit()
self:debug(self.name, self.id)
self:info()
end]]
}
return {version = version, templates = code}