I have used this script succesfully with the Philips hue sensor, but is i use the Xioami sensor it gives a error on the last update:
Code: Select all
attempt to index a nil value (field 'lastUpdate')
Code: Select all
return {
on = {
timer = {'every 1 minutes'},
devices = {'Schuursensor'}
},
execute = function(dz, Sensor)
local Schuur = dz.devices('Schuur')
if Sensor.state == 'On' then
Schuur.switchOn().checkFirst()
print('Schuursensor is ' .. Sensor.state .. '. Schuur is aangezet omdat er beweging in de Schuur is. ')
elseif Sensor.lastUpdate.minutesAgo >= 5 and Schuur.state == 'On' then
Schuur.switchOff()
print('Schuurverlichting is uitgezet omdat er 5 minuten geen beweging in de Schuur is geweest')
else
print('Nothing changed. Schuursensor updated ' .. Sensor.lastUpdate.minutesAgo .. ' minutes ago')
end
end
}
I tried to debug with Sensor.dump() but it gives a error with nil value on dump too. Why it is giving a nil value and can i do something about it?