Current Motion State

having a hard time getting the current motion state to work…

def motionState = motion1.currentState("motion")
log.debug "$motionState.value"
if (motionState.value == "inactive") {
    } else {

debug returns [inactive], but my if statement never matches…

Currently doing a work around by defining state.motion true/false in an event handler, and it works… but why is the above method broken for me?


How about this instead?

log.debug "$motionState"

I don’t think you want the .value.

BTW, shorthand for motion1.currentState("Motion") is motion1.currentMotion

1 Like

debug returns [physicalgraph.device.cassandra.DeviceStateCache@52c8d6b4] if I only change the debug line.

If I change to def motionState = motion1.currentMotion it goes back to returning [inactive]

But if (motionState.value == "inactive") or if (motionState == "inactive") still don’t work

[quote=“qwertypo, post:1, topic:18674”]
[/quote]the [] indicate an array of values, which means motion1 has multiple:true and there just happens to be only one motion sensor in there. In other words, you might have an array of them.

So, you could test for montionState.contains(“inactive”) which will work so long as any of the motion detectors has no motion. If you want to make sure ALL of them have no motion, you’d need to check


if (motionState.contains("inactive"))

That works. Thanks. I don’t have multiple motion sensors installed, but multiple:true just for the possibility. So that is what was killing me.

I will test it out with multiple and single sensors using the !montionState.contains("active") to make sure that can work as intended.

Thank you!

Very welcome. Groovy is kinda nice because it “just works” most of the time - but it actually hides a lot of subtleties (as does the SmartThings models of devices and how you use them) that kinda bite you in the behind at first :smile:

1 Like