Domoticz是一款家庭自动化系统,而lua motion sensor是一种用于监测运动的传感器。

当 Motion Sensor 探测到 X 分钟没有活动时,此脚本将关闭第二客厅的灯光。

脚本确实在运行并且有时能正常工作,大约每天一到两次。但它必须始终工作,我无法弄清楚为什么它不起作用。

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
点赞
用户1881196
用户1881196

如果脚本成功运行,但即使预期关闭灯也没有关闭,则可能的原因不多。

要么otherdevices['Motion']不是 'On'(检查区分大小写),要么差异超出了60..200秒的预期范围。

2015-05-25 09:24:25
用户4329808
用户4329808

解决方案 #1:

...
如果 (otherdevices['Light']=='On' and otherdevices['Motion']~='On' and difference > 120) then
    CommandArray['Light']='Off'
}

解决方案 #2(更好的方法):

配置 Motion 设备使其激活灯光 120 秒,这样当 Motion 传感器停止切换时,灯光就会自动关闭。

2021-03-16 20:18:38