-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathI_PilotWire1.xml
More file actions
261 lines (202 loc) · 9.27 KB
/
I_PilotWire1.xml
File metadata and controls
261 lines (202 loc) · 9.27 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
<?xml version="1.0"?>
<implementation>
<functions>
-- Pilote your electric heating with the pilote wire
--
-- Author: Antor
-- Date: 01/28/2012
--
-- You can set the following:
-- SwitchPositive : set of device id's with the led let pass positive signal
-- SwitchNegative : set of device id's with the led let pass positive signal
local PWITEM_SID = "urn:antor-fr:serviceId:PilotWire1"
local SWPOWER_SID = "urn:upnp-org:serviceId:SwitchPower1"
local DIM_SID = "urn:upnp-org:serviceId:Dimming1"
function initItem(lul_device)
log("Starting MetaItem device " .. tostring(lul_device))
-- to initialize the variables
readSettings(lul_device)
-- to sync de status with controlled item
sync(lul_device)
log("Pilot Wire device started " .. tostring(lul_device))
return true,"ok","PilotWire1"
end
function readSettings(lul_device)
local data = {}
data.status = readVariableOrInit(lul_device,PWITEM_SID,"Status",0)
data.target = readVariableOrInit(lul_device,PWITEM_SID,"Target",0)
data.lastStatus = readVariableOrInit(lul_device,PWITEM_SID,"Last Status",0)
data.SwitchPositive = tonumber(readVariableOrInit(lul_device,PWITEM_SID,"SwitchPositive", ""))
data.SwitchNegative = tonumber(readVariableOrInit(lul_device,PWITEM_SID,"SwitchNegative", ""))
return data
end
-- COMMUN FUNCTION
function readVariableOrInit(lul_device, devicetype, name, defaultValue)
local var = luup.variable_get(devicetype,name, lul_device)
if (var == nil) then
var = defaultValue
luup.variable_set(devicetype,name,var,lul_device)
end
return var
end
function writeVariable(lul_device,devicetype, name, value)
luup.variable_set(devicetype,name,value,lul_device)
end
-- END COMMUN FUNCTION
function getStatus(id)
if ( id == "") then return "0"
else return luup.variable_get(SWPOWER_SID,"Status", id) end
end
function sync(lul_device)
lul_device = tonumber(lul_device)
local data = readSettings(lul_device)
local SwPos = getStatus(data.SwitchPositive)
local SwNeg = getStatus(data.SwitchNegative)
if (SwPos == "0" or SwPos ==nil ) and (SwNeg == "0" or SwNeg == nil) then
luup.variable_set(PWITEM_SID, "Target", "3", lul_device)
luup.variable_set(PWITEM_SID, "Status", "3", lul_device)
elseif SwPos == "1" and (SwNeg == "0" or SwNeg == nil) then
luup.variable_set(PWITEM_SID, "Target", "0", lul_device)
luup.variable_set(PWITEM_SID, "Status", "0", lul_device)
elseif (SwPos == "0" or SwPos ==nil ) and SwNeg == "1" then
luup.variable_set(PWITEM_SID, "Target", "1", lul_device)
luup.variable_set(PWITEM_SID, "Status", "1", lul_device)
elseif SwPos == "1" and SwNeg == "1" then
luup.variable_set(PWITEM_SID, "Target", "2", lul_device)
luup.variable_set(PWITEM_SID, "Status", "2", lul_device)
end
end
function SetTarget(lul_device,value)
local data = readSettings(lul_device)
local lul_resultcode, lul_resultstring
luup.call_timer("sync", 1, "1m", "", tostring(lul_device))
if (value == 0 or value == "0" ) then
local lul_resultcodeP = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 1}, data.SwitchPositive)
local lul_resultcodeN = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 0}, data.SwitchNegative)
if (lul_resultcodeP == -1 or lul_resultcodeN == -1) then
return -1,"Wrong value"
end
MemoriseLastStatus(value,data.status)
luup.variable_set(PWITEM_SID, "Target", value, lul_device)
luup.variable_set(PWITEM_SID, "Status", value, lul_device)
luup.variable_set(DIM_SID, "LoadLevelTarget", "0", lul_device)
luup.variable_set(DIM_SID, "LoadLevelStatus", "0", lul_device)
return 0,"Shutdown set"
elseif (value == 1 or value == "1" ) then
local lul_resultcodeP = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 0}, data.SwitchPositive)
local lul_resultcodeN = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 1}, data.SwitchNegative)
if (lul_resultcodeP == -1 or lul_resultcodeN == -1) then
return -1,"Wrong value"
end
MemoriseLastStatus(value,data.status)
luup.variable_set(PWITEM_SID, "Target", value, lul_device)
luup.variable_set(PWITEM_SID, "Status", value, lul_device)
luup.variable_set(DIM_SID, "LoadLevelTarget", "33", lul_device)
luup.variable_set(DIM_SID, "LoadLevelStatus", "33", lul_device)
return 0,"Frost Protection set"
elseif (value == 2 or value == "2" ) then
local lul_resultcodeP = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 1}, data.SwitchPositive)
local lul_resultcodeN = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 1}, data.SwitchNegative)
if (lul_resultcodeP == -1 or lul_resultcodeN == -1) then
return -1,"Wrong value"
end
MemoriseLastStatus(value,data.status)
luup.variable_set(PWITEM_SID, "Target", value, lul_device)
luup.variable_set(PWITEM_SID, "Status", value, lul_device)
luup.variable_set(DIM_SID, "LoadLevelTarget", "66", lul_device)
luup.variable_set(DIM_SID, "LoadLevelStatus", "66", lul_device)
return 0, "Economy set"
elseif (value == 3 or value == "3" ) then
local lul_resultcodeP = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 0}, data.SwitchPositive)
local lul_resultcodeN = luup.call_action(SWPOWER_SID, "SetTarget", {newTargetValue = 0}, data.SwitchNegative)
if (lul_resultcodeP == -1 or lul_resultcodeN == -1) then
return -1,"Wrong value"
end
MemoriseLastStatus(value,data.status)
luup.variable_set(PWITEM_SID, "Target", value, lul_device)
luup.variable_set(PWITEM_SID, "Status", value, lul_device)
luup.variable_set(DIM_SID, "LoadLevelTarget", "100", lul_device)
luup.variable_set(DIM_SID, "LoadLevelStatus", "100", lul_device)
return 0, "Comfort set"
else
return -1,"Wrong value"
end
end
function MemoriseLastStatus(target,status)
local NbTarget = tonumber(target)
local NbStatus = tonumber(status)
if(NbTarget ~= nil and NbStatus ~= nil ) then -- and NbTarget ~= NbStatus
luup.variable_set(PWITEM_SID, "Last Status", status, lul_device)
end
end
function SetLevel(lul_device,value)
value = tonumber(value)
if(value == 0 ) then
return SetTarget(lul_device,0)
elseif(value > 0 and value < 50 ) then
return SetTarget(lul_device,1)
elseif(value > 49 and value < 75 ) then
return SetTarget(lul_device,2)
elseif(value > 74) then
return SetTarget(lul_device,3)
else
return -1, "Wrong value"
end
end
function SetLastTarget(lul_device)
local data = readSettings(lul_device)
return SetTarget(lul_device,data.lastStatus)
end
function log(msg)
luup.log("PilotWirer : " .. msg)
end
</functions>
<startup>initItem</startup>
<actionList>
<action>
<serviceId>urn:antor-fr:serviceId:PilotWire1</serviceId>
<name>SetTarget</name>
<job>
log("SetTarget called")
SetTarget(lul_device,lul_settings.newTargetValue)
return 4, 5
</job>
</action>
<action>
<serviceId>urn:antor-fr:serviceId:PilotWire1</serviceId>
<name>Sync</name>
<job>
log("Sync called")
sync(lul_device)
return 4, 5
</job>
</action>
<action>
<serviceId>urn:antor-fr:serviceId:PilotWire1</serviceId>
<name>SetLastTarget</name>
<job>
log("SetLastTarget called")
SetLastTarget(lul_device)
return 4, 5
</job>
</action>n>
<action>
<serviceId>urn:micasaverde-com:serviceId:HaDevice1</serviceId>
<name>Poll</name>
<job>
log("Poll called")
sync(lul_device)
return 4, 5
</job>
</action>
<action>
<serviceId>urn:upnp-org:serviceId:Dimming1</serviceId>
<name>SetLoadLevelTarget</name>
<job>
log("SetLoadLevelTarget called")
SetLevel(lul_device,lul_settings.newLoadlevelTarget)
return 4, 5
</job>
</action>
</actionList>
</implementation>