PLEG Motion / Umbrella Topic

This got me thinking…

I have been doing various different things, with various different results.

Bottom line is:
I have a few of the Schlage motion sensors (battery operated), and a bunch of Cooper dimmers. I’d like to detect motion in a room, turn lights on. And then figure out a way to leave them on until no one is in the room. For some rooms, that will be 30 seconds of no action, others, 10 mins.

I’ve got the motion sensors to 4 seconds, rather than 5 mins (whym I don’t know – guess I assumed that I didn’t want the light to stay on for 4:30 if I only was in the room real quick).

I was beating my head against the wall, first trying NOW > 00:01:00, then thinking a starttimer would be better. None of my conditions were set to REPEAT, and so now I want to start over and figure out the best way to do this.

Pretty sure this will be an FAQ by the time it’s over, but I need a little bit of help. I read, and printed out, the PLEG basics where it talks about the starttimer vs now, but am a bit stuck on that too.

Motion-triggered lights seem like a simple application for PLEG. The trouble usually comes in trying to handle options like forcing the light to stay on or other refinements.

Starting with a simple example, consider the following. If it is night, the light is off and motion is detected, AutoOn will fire and turn on the light. When this happens or motion is detected while the light is on, KeepOn will fire and start or restart Timer. When Timer ends and the light is on, AutoOff fires and turns off the light.

Timer can be set for any required interval from a few seconds to several hours. This example will only work with motion sensors that have a short on-time (the time that they stay tripped after detecting motion). I set mine to five seconds or however low they will go. None of the Conditions require Repeats to be checked.

Triggers
LightOn Light is turned on
Motion Motion Sensor is tripped
ItsNight DayTime indicates night

Schedules
Timer On: Self-ReTrigger Off: Interval 5:00

Conditions
AutoOn !LightOn and ItsNight and Motion
KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff LightOn and !Timer and (LightOn; !Timer)

Actions
AutoOn Turn Light on
KeepOn PLEG StartTimer timerName=Timer
AutoOff Turn Light off

Now what if you want to be able to force the light to stay on even if no motion is detected? This can get tricky. If you can reach the wall-switch without tripping the motion detector you can use this:

AutoOff LightOn and !Timer and (LightOn; !Timer) and (AutoOn; LightOn < 10)

AutoOff can only fire if the light was turned on less than ten seconds after AutoOn fired - and was therefore probably turned on by motion. If you turn the light on manually before motion is detected, it should stay on until you turn it off manually. This will only work with switches that report instant status.

If you cannot reach the wall-switch without tripping the motion detector, you could try this:

AutoOff LightOn and !Timer and (LightOn; !Timer) and (!LightOn; LightOn > 10)

This will prevent AutoOff from firing if the light was turned on less than ten seconds after it was turned off. So if you turn the light off and back on quickly, it should stay on until you turn it off. This will only work with switches that report instant status.

One problem with the last change is that, when you try to turn off the light manually, if you trip the motion sensor it will turn it back on until Timer ends. You can prevent this with the following change:

AutoOn !LightOn and ItsNight and Motion and (!LightOn; Motion > 10)

This prevents AutoOn firing for ten seconds after the light was turned off.

There are many other wrinkles that can be added to the logic. My personal favorite for my outside lights is to use the second switch input of Fibaro FGS211 modules to provide a dedicated hold-on or hold-off function.

Triggers
LightOn Light is turned on
Motion Motion Sensor is tripped
ItsNight DayTime indicates night
HoldSw Hold Switch is turned on

Schedules
Timer On: Self-ReTrigger Off: Interval 5:00

Conditions
AutoOn !LightOn and ItsNight and Motion and !HoldSw
KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff LightOn and !Timer and (LightOn; !Timer) and !HoldSw

Actions
AutoOn Turn Light on
KeepOn PLEG StartTimer timerName=Timer
AutoOff Turn Light off

If the Hold switch is turned on while the lights are off, they will not come on when motion is detected. If the Hold switch is turned on while the lights are on, they will not be turned off automatically. Used in conjunction with the primary on/off switch, I can set auto mode, always on or always off.

Wow. OK, this is perfect… at least gets me over the hard part and I can experiment.

one question…

Actions
AutoOn Turn Light on
KeepOn PLEG StartTimer timerName=Timer

How do I set that PLEG action, KeepOn? That part is stumping me… I created my timer, but unsure how to link that action.

How do I set that PLEG action, KeepOn? That part is stumping me... I created my timer, but unsure how to link that action.

After you click the Edit button for the Action in PLEG, select the ADVANCED tab. In the Pick a device drop-down, select the PLEG you are using and then click Add. Now select StartTimer and type in the name of the timer under timerName. Leave intervalTime blank unless you want to override the value set in the Schedule definition.

OK, that worked like a champ! I can’t tell you how much I appreciate this.

Now, say I wanted to set a light on, say randomly while I am not home. I am assuming with this script, the light would eventually turn off with no motion. So if that’s the case, I could set the motion tripped event to armed motion tripped and then simply unarm the motion for that light, right?

And second… if I wanted to have the fan on behaving like a hold… for instance, turn off light if no motion, but if the fan is on, leave on. When fan is off, go back to default of turning off if no motion… is that possible?

KeepOn (LightOn and (Motion or FanTurnedOn) and (LightOn; Motion; FanTurnedOn)) or AutoOn

Now, say I wanted to set a light on, say randomly while I am not home. I am assuming with this script, the light would eventually turn off with no motion.

In my examples, the timer only gets started as a result of the motion sensor triggering. If you turn the light on some other way, it will stay on. You could, of course, add other terms to handle random lighting. Personally I keep my simulated occupation lighting as separate Schedules and Conditions to avoid unnecessary complexity.

And second... if I wanted to have the fan on behaving like a hold... for instance, turn off light if no motion, but if the fan is on, leave on. When fan is off, go back to default of turning off if no motion... is that possible?

If the fan has a separate Z-Wave switch then you can use it as part of your logic.

KeepOn (LightOn and (Motion or FanTurnedOn) and (LightOn; Motion; FanTurnedOn)) or AutoOn

I don’t think that is going to do what you want. Perhaps something like this:

KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn or (LightOn and !FanTurnedOn and (LightOn; !FanTurnedOn))
AutoOff LightOn and !Timer and (LightOn; !Timer) and !FanTurnedOn

In my examples, the timer only gets started as a result of the motion sensor triggering. If you turn the light on some other way, it will stay on. You could, of course, add other terms to handle random lighting. Personally I keep my simulated occupation lighting as separate Schedules and Conditions to avoid unnecessary complexity.

Yeah, that makes sense… most rooms have two sets of lights (main light I use for motion sensors, and recessed lights that have zwave switches, but aren’t controlled with motion…) this sounds like a good approach.

If the fan has a separate Z-Wave switch then you can use it as part of your logic.

Yep

[b]KeepOn[/b] (LightOn and Motion and (LightOn; Motion)) or AutoOn or (LightOn and !FanTurnedOn and (LightOn; !FanTurnedOn)) [b]AutoOff[/b] LightOn and !Timer and (LightOn; !Timer) and !FanTurnedOn

Cool. Going to try this out!

KeepOn (LightOn and Motion and (LightOn; Motion)) or AutoOn or (LightOn and !FanTurnedOn and (LightOn; !FanTurnedOn))
AutoOff LightOn and !Timer and (LightOn; !Timer) and !FanTurnedOn

OK, so on this… KeepOn … doesn’t that say OR light is on and fan turnedoff… Wouldn’t I want to say FanTurnedOn , not !FanTurnedOn

is !FanTurnedOn equal to FanTurnedOff?

OK, so on this... KeepOn ... doesn't that say OR light is on and fan turnedoff... Wouldn't I want to say FanTurnedOn , not !FanTurnedOn

The object of the expression or (LightOn and !FanTurnedOn and (LightOn; !FanTurnedOn)) is to start the timer when the fan is turned off while the light is on. While the fan was on, the ConditionAutoOff could not fire so any timer completions get ignored. When the fan goes off, if the light is still on, starting the timer will ensure it gets turned off. Or you could do it differently if you prefer.

is !FanTurnedOn equal to FanTurnedOff?

Well it could be. The exclamation mark is an alternative to using NOT. !FanTurnedOn = Not FanTurnedOn. If the fan is not turned on it is presumably off so if you had a Trigger FanTurnedOff for that state then !FanTurnedOn = Not FanTurnedOn = FanTurnedOff.

OK, that makes sense. And helps me simplify - because if I can use !TurnedOn for things, I can create less conditions…

Will test this out in a bit.

And so I had one more question - as some of these lights are dimmers… Say I wanted to turn them to 100% when motion activates them during the day (I’ve got the day/night plugin, and am pretty good with doing things around that), but wanted them to be 50% at night time. I suppose I could create two different On conditions - but I can see that getting messy if I wanted to make it even more granular.

But I don’t see any other way around it, right? I’d need a separate on action, but wouldn’t need separate off ones, right?

There is a simple way to set dimmer levels according to day or night. You can use a Conditional expression in the Action. On the Advanced tab in the Action editor, place this expression in the field for newLoadlevelTarget: {(ItsNight ? 50 : 100)}

ItsNight is a Trigger set to be true when the DayTime plugin indicates night. The Conditional expression returns the value 50 when ItsNight is true or 100 otherwise. As you say, you only need to do this for the on Action.

I have ItsNight set to be true at sundown.

Instead of setting it to 50 when ItsNight and 100 when !ItsNight, I’d like to set it to:

2 hours after ItsNight to 4 hours after ItsNight… set to 65%
4 hours after ItsNight until !ItsNight… set to 50%

[quote=“johnes, post:12, topic:182444”]I have ItsNight set to be true at sundown.

Instead of setting it to 50 when ItsNight and 100 when !ItsNight, I’d like to set it to:

2 hours after ItsNight to 4 hours after ItsNight… set to 65%
4 hours after ItsNight until !ItsNight… set to 50%[/quote]

The simplest way to do that is to create a Schedule using the offsets from Sunset and use that instead of ItsNight. Your timing has a gap from Sunrise to Sunset + 2hrs. If you want a different value for that period, you will need a second Schedule.

Sweet…

So, I create a schedule with a start type of Day of Week and use the After Sunset, etc. I assume then that I can use the Interval Stop Type and then put in a time there.

So I make my schedules, and then reference them in the Actions > Advanced part? Seems easy enough…

But let’s say I have one for:

[code]
Schedule A
start
Sunset
end
sunset + 2 hours.

Schedule B
start
Sunset + 2 hours
end
sunset + 4 hours[/code]

What happens if the end of ScheduleA overlaps the start of ScheduleB?

What happens if the end of ScheduleA overlaps the start of ScheduleB?

There is no problem for PLEG in having overlapping Schedules. Whether it affects your logic depends on how you use them in expressions.

So I make my schedules, and then reference them in the Actions > Advanced part? Seems easy enough...

Quite so. For example this will set a dim level of 65 between sunset+2 and sunset+4, 50 between sunset+4 and sunrise or 100 for the rest of the day:

Schedules
Dusk Start: Sunset + 2 hrs, Stop: Sunset + 4 hrs
Dark Start: Sunset + 4 hrs, Stop: Sunrise

Actions
CName Light SetLoadLevelTarget newLoadlevelTarget={(Dusk ? 65 : Dark ? 50 : 100)}

RexBecket:
I love this scene. Using it in my Garage and now in the Kitchen.
However, in the kitchen, I need to be able to manually prevent the lights to go on. Meaning, I want to be able to be in the kitchen, but sometimes, I dont want the lights to turn on.
Is it possible to do a double click or something other?
I have a Qubino Flush 2 Relays (using both button to different lights)