
"on state of device" not working as expected.
I am trying to use the "on state of variable" syntax to poll a device, and I'm a little confused about the following behavior. I have the following script as an attachment.
- Code: Select all
on motion(_timedelta)
if on state of device "Hallway Motion detector" then
return true
else if on state of device "2nd Floor Hall Motion detector" then
return true
else if ((current date) - (date value of variable "lastmotion") as real < _timedelta) then
return true
else
return false
end if
end motion
the purpose is to check for motion within a given amount of time, and return true if there was motion, and false if there was not. I have trigger actions set up for the motion detectors to place the (current date) into the variable "lastmotion" whenever their state changes to "on." When there is a lot of motion, the motion detectors never send an off event, and therefore it could have bee a long time since their state changed to "on", but there is still motion happening. That's why I check the state of the motion detector as well. If it's still on, then there's still motion.
Now to the unexpected behavior. If the state of "Hallway Motion detector" is "on" the program returns true, as expected. However, if the state of "Hallway Motion detector" is "off" then I get the following error.
Error script error: Can't get value.
Error error dispatching event to attachment script (-1753)
Error script error: Can't get value.
I've narrowed it down to the first statement "if on state of device "Hallway etc."
if I embed the following script into an action group...
- Code: Select all
if on state of device "Hallway Motion detector" then
log "it's on"
end if
it works properly for both "on" and "off" states of the "Hallway Motion detector device"
Is there an explanation or way around this?
Thanks,
Scott.