Motion Sensor Advice

Hi all,

After some advice on the best / most efficient / easiest way to write this rule…

I have multiple motion sensors, all are individual switch items in OH so give an on/off result.

All are grouped into a gMotion group from which I run my presence detection, ie if motion is detected is someone home etc…all good here.

What I want to do is capture which motion sensor it was that detected motion so I can have it message me ‘motion detected in xxxxx room’ and then I can run location rules off the back of it.

Any ideas?

I use this…

Thanks, I’ve done a crude if statement for the moment but was hoping that I could interrogate a group option so I don’t have to keep updating the rule for each new motion sensor etc…

I’ll also take a read through your link, looks really interesting.

rule "What motion sensor updated"
	Item gMotion changed
    if(GF_HW_MotionSensor_Motion.state == ON) vLastMotionSensor.postUpdate("Ground Floor Hallway") // GF HW Sensor
    if(GF_LR_MotionSensor_Motion.state == ON) vLastMotionSensor.postUpdate("Ground Floor Living Room") // GR LR Sensor
    if(FF_HW_MotionSensor_Motion.state == ON) vLastMotionSensor.postUpdate("First Floor Hallway") // FF HW Sensor

This just updates a string dummy variable with the text to determine which was the last sensor to receive an ON command, I might modify it to a number and then I can case statement case 1, case 2, case 3 etc and then I can run rules from there…

Still looking for a more elegant solution!

If you are going to stick with the DSL, use this for the trigger…

Member of gMotion changed to ON

And then use triggeringItem to get the Item that triggered the rule. From there, run through a mapping of Item name to friendly name. Or setup some metadata. Or parse out the name into a friendly name, like this…

rule "What motion sensor updated"
	Member of gMotion changed to ON
    val last_item_name ="GF", "Ground Floor").replace("FF", "First Floor").replace("HW", " Hallway").replace("LR", " Living Room")

That’s exactly what I hoped was possible with Groups…I need to do some more research on what groups can do :+1:

Just reading through your lighting posts…some very impressive stuff in there, it’s making me re-think some of my lighting thoughts…

As you seem to be a bit of a grouping guru, is there a site / post that shows the various options like triggeringItem etc for grouping as I’ve gone through the docs on here and searched the forum and while there are different posts within rules I’d like to do some learning as to the hows and whys…


Note to self, (and anyone else)…lot’s of useful info here:

Implicit variables like triggeringItem are documented here. triggeringItem in particular is useful when using Member of rule triggers. Putting it all together you can do stuff like Design Pattern: Associated Items.

1 Like

Thanks, I’m actually just revisiting your various excellent DP tutorials, lots of good info in there :+1:

You might link to think about what happens when a whole sequence of detectors are triggered, a Group state may not reflect that. Depending what your trying to do, you might not care. But if you want to deal with every event, the Member of trigger works rather differently.

Thanks, my gMotion is a number in this case, I use it for presence detection / security, and I just want to run something when gMotion > 0, ie any motion is detected.

However, now I’m delving into the various group options I’m starting to see that there is a whole lot more to groups that I first thought. There is a lot of good stuff in there that will really help my rule making going forward…and unfortunately a lot that will mean some old rule rewriting!

It’s all for the better though and the next step on my OH learning journey.