forked from AntorFr/SmartVT
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathL_SmartVT1.lua
More file actions
executable file
·162 lines (136 loc) · 6.32 KB
/
L_SmartVT1.lua
File metadata and controls
executable file
·162 lines (136 loc) · 6.32 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
-- Fonction permettant de surveiller les variables presentes dans "inhibit Sensors"
function register_watch(Sensors)
for index = 1, #Sensors, 1 do
local device = math.abs(Sensors[index])
local type_device = luup.devices[device].device_type -- On determine le SID en fonction de l'ID.
if type_device == DOOR_DID or type_device == MOTI_DID then -- En fonction du SID, on determine la variable a lire.
luup.variable_watch("watch_callback", DOOR_SID, "Tripped", device)
elseif type_device == BIN_DID then
luup.variable_watch("watch_callback", SWP_SID, "Status", device)
elseif type_device == VSW_DID then
luup.variable_watch("watch_callback", VSW_SID, "Status", device)
end
end
return true
end
function Consigne(data)
if data.EnergyModeStatus == "EnergySavingsMode" then
return data.coolSp
else
return data.heatSp
end
end
function AvgTemperature(t,TimeSecu)
local sum = 0
local count= 0
local temp = {}
if TimeSecu == nil or tonumber(TimeSecu) == nil then
TimeSecu = 0
end
-- BatteryDate ("urn:micasaverde-com:serviceId:HaDevice1")
for k,id in pairs(t) do
local invert = false
if (0 > id) then
id = 0 - id
invert = true
end
local temp, time = luup.variable_get(TEMP_SID, "CurrentTemperature", id)
temp = tonumber(temp)
local BatDate = luup.variable_get(HAD_SID, "BatteryDate", id)
local MasterId = luup.devices[id].device_num_parent
if tonumber(MasterId) ~= nil and BatDate == nil then
BatDate = luup.variable_get(HAD_SID, "BatteryDate", MasterId)
end
if (temp ~= nil) then
if (TimeSecu == 0) or (os.time()-time <= TimeSecu) then
sum = sum + temp
count = count + 1
elseif BatDate ~= nil and (os.time()-BatDate <= (TimeSecu * 4)) then
sum = sum + temp
count = count + 1
elseif invert then -- désactivation sécurité
sum = sum + temp
count = count + 1
else
-- Attention, la sonde n'a pas prise en compte
end
end
end
if count > 0 then
return round((sum / count),1)
else
return false
end
end
function SetTargetTable(target,t)
for k,id in pairs(t) do
local devicetype = luup.devices[id].device_type
if (devicetype == BIN_DID) then
heaterStatus = luup.variable_get(SWP_SID, "Status", id) -- On recupere la variable du module
if heaterStatus ~= target then
luup.call_action(SWP_SID, "SetTarget", { newTargetValue= target }, id)
end
elseif (devicetype == VSW_DID) then
heaterStatus = luup.variable_get(VSW_SID, "Status", id) -- On recupere la variable du module
if heaterStatus ~= target then
luup.call_action(VSW_SID, "SetTarget", { newTargetValue= target }, id)
end
elseif (devicetype == PIL_DID) or (devicetype == DIM_DID) then
local DIM_target = tostring(tonumber(target) * 100)
heaterStatus = luup.variable_get(DIM_SID, "LoadLevelStatus", id) -- On recupere la variable du plugin pilotwire Antor
if heaterStatus ~= DIM_target then -- Si la variable du plugin pilotwire Antor est different du Target, on envoie la commande
luup.call_action(DIM_SID, "SetLoadLevelTarget", { newLoadlevelTarget= DIM_target}, id)
end
elseif (devicetype == HEAT_DID) then
heaterStatus = luup.variable_get(HVUOM_SID, "ModeStatus", id) -- On recupere la variable du module
if target == "1" and heaterStatus ~= "HeatOn" then -- Si la variable du plugin pilotwire Antor est different du Target, on envoie la commande
luup.call_action(HVUOM_SID, "SetModeTarget", { NewModeTarget= "HeatOn" }, id)
elseif target == "0" and heaterStatus ~= "Off" then
luup.call_action(HVUOM_SID, "SetModeTarget", { NewModeTarget= "Off" }, id)
end
end
end
end
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 fromListOfNumbers(t)
return table.concat(t, ",")
end
function toListOfNumbers(s)
t = {}
for v in string.gmatch(s, "(-?[0-9\.]+)") do
table.insert(t, tonumber(v))
end
return t
end
function tableMean( t )
local sum = 0
local count= 0
for k,v in pairs(t) do
if type(v) == 'number' then
sum = sum + v
count = count + 1
end
end
return round((sum / count),1)
end
function round(num, idp)
local mult = 10^(idp or 0)
return math.floor(num * mult + 0.5) / mult
end
function GetTime(TimeStamp,Sec)
local dr = os.date("*t",TimeStamp) -- Referece date
local newSec = os.time({year=dr.year, month=dr.month, day=dr.day, hour=dr.hour, min=dr.min, sec=(dr.sec+Sec)})
return newSec
end
function debuglog(log)
if debug then
luup.log( "SmartVT : " .. log)
end
end