Help Needed: Motion Sensor Rule

Hi All,

I’m still coming to terms with how to setup and use OpenHab fully. Although I have a good few ideas of what I want to do I’ve not totally worked out how to achieve them, so have a need for a little help.

I have a motion sensor on the landing and a bed side light in the master bed room. What I’d like to do is have the bed side light come on when the motion sensor is triggered. That’s the easy part and have that working fine. But that just means that no matter what the time of day it is the bed side light comes on, which isn’t really very good.

The bed side light is part of my Phillips Hue setup and it also controlled by separate Hue switch. Here’s what I’d like help with, How do I create a rule that when I switch the light off at night it’s not switched on by the motion sensor. But also is only switched on by ht emotion sensor after dark.

I’ve not managed to find what I’m looking for among the examples on the forum.

Thanks in advance for your help.

Have a look at time based triggers.

Thanks Paul,

I’ve already read that part of the Wiki and it doesn’t really help me. I’d like the motion sensor rule to only be active when it’s night time, but not work after I have switched the bed side light off.

The time based trigger can be used to set the time frame the rule can fire:

 rule "switch on lights at 8:15pm"
 when
     Time cron "0 15 20 * * ?"
 then
     MyLights.sendCommand(ON)
 end

 rule "switch off lights at 12:00am"
 when
     Time cron "0 0 0 * * ?"
 then
     MyLights.sendCommand(OFF)
 end

Or you could look at using the Astro binding to define periods of time (day, night etc) and use those to limit the rule to fire only during night time (based on the Astro binding configuration)

Your rule will end up being an when-then-if-else-end style statement. Essentially it would ask if the bedside light is off before doing anything else, and if it was, it would run the rest of the rule, if not it would return a log comment stating the light is off so not going to do anything. I’m not proficient enough to type you an example without an hour or so of fiddling, but someone else will no doubt have a better way to do it, or have something already written.

Check this out for a way to have Astro set up.

Also check out the Time of day triggers design pattern

@pahansen and @gpbenton point to a slightly older version of the Time of Day design pattern. I’ve since updated it to use a single String Item to store the current time of day as opposed to a series of switches. It is way more maintainable and the rules are simpler using this approach.

Its just a little further down the list in that same thread.