-
Notifications
You must be signed in to change notification settings - Fork 0
/
blanket.lua
33 lines (31 loc) · 1.29 KB
/
blanket.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
--
-- 自动控制电热毯开关
--
commandArray = {}
print ("All based event fired");
-- loop through all the devices
for deviceName,deviceValue in pairs(otherdevices) do
if (deviceName=='电热毯(s3)') then
if (timeofday['Nighttime']) and otherdevices["OnePlus3"] == "On" then
if deviceValue == "On" and uservariables['bedroomTemp'] >= 20 then
-- print("电热毯处于打开状态")
-- print("当前室内温度:"..tostring(uservariables['bedroomTemp']))
-- print("温度适宜,关闭电热毯")
commandArray['电热毯(s3)'] = "Off"
commandArray['Variable:blanket']='off'
elseif deviceValue == "Off" and uservariables['bedroomTemp'] < 20 then
-- print("电热毯处于关闭状态")
-- print("当前室内温度:"..tostring(uservariables['bedroomTemp']))
-- print("温度偏低,打开电热毯")
commandArray['电热毯(s3)'] = "On"
commandArray['Variable:blanket']='on'
end
else
if deviceValue == "On" then
commandArray['电热毯(s3)'] = "Off"
commandArray['Variable:blanket']='off'
end
end
end
end
return commandArray