- 当运动传感器上检测到x min没有移动时,此脚本将关闭第二个起居室的灯光。
- 脚本确实运行,有时可以正常运行,例如每天一次或两次。但它必须始终工作,我无法弄清楚它为什么不起作用。
t1 = os.time()
s = otherdevices_lastupdate['Motion']
year = string.sub(s, 1, 4)
month = string.sub(s, 6, 7)
day = string.sub(s, 9, 10)
hour = string.sub(s, 12, 13)
minutes = string.sub(s, 15, 16)
seconds = string.sub(s, 18, 19)
commandArray = {}
t2 = os.time{year=year, month=month, day=day, hour=hour, min=minutes, sec=seconds}
difference = (os.difftime (t1, t2))
print(difference)
if (otherdevices['Motion'] == 'On' and difference > 60 and difference < 200) then
commandArray['Light']= 'Off'
print('2 minutes no movement, turn off Light 2th Living Room')
end
return commandArray
答案 0 :(得分:1)
如果脚本成功运行但即使预期会关闭它也不会关灯,那么原因并不多。
其他设备[&#39; Motion&#39;]不是&#39; On&#39; (支票区分大小写)或差异超出60..200秒的预期范围。
答案 1 :(得分:1)
解决方案#1:
...
if (otherdevices['Light']=='On' and otherdevices['Motion']~='On' and difference > 120) then
CommandArray['Light']='Off'
}
解决方案 #2(更好):
配置 Motion 设备,使其激活 Light 120 秒,以便在 Motion 传感器停止切换时自动关闭。