We have moved at community.getvera.com

Author Topic: PLEG Basics - An Introduction to the Program Logic Event Generator  (Read 151947 times)

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
PLEG Basics - Another Motion-triggered Light Example
« Reply #60 on: February 24, 2014, 10:09:09 am »
A motion-triggered light should be a good first project for learning PLEG but it does seem to generate a lot of questions. Here is another example of how this may be done. The highlights are:

  • Uses a Self-ReTrigger Schedule (Timer) rather than Now
  • Turns on light when motion detected at night
  • Ignores motion if recently turned off (< 30 seconds)
  • Turns light off automatically if no motion detected for five minutes
  • May be locked on by rapid off/on of light switch

It requires a light switch with instant (or very rapid) status reporting. The motion sensor should be configured with a short on-time (less than the interval time).
 
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 and (!LightOn; Motion > 30)
KeepOn    (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff     LightOn and !Timer and (LightOn; !Timer) and (!LightOn; LightOn > 10)

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

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #61 on: February 25, 2014, 02:49:48 am »
Thank you for your example!
This is exactly what I have been searching for. I tested it yesterday and it works. Just some tuning of the values to fit my needs.

Just a quick question to try understand a bit more of this logic.

Quote
Uses a Self-ReTrigger Schedule (Timer) rather than Now
Is it preferable to use this timer instead of the Now command?
I have in earlier posts been advised to limit the amount of Now commands, is this the reason for using the Timer?



regards

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #62 on: February 25, 2014, 03:38:01 am »
Quote
Is it preferable to use this timer instead of the Now command?
A Condition that includes the term Now will get evaluated at least once per minute (3600 times per day). A Condition using a timer will get evaluated when the timer start and stops or another term changes.

The additional processing caused by Now may not have any noticeable impact on PLEG response. It depends how many Conditions are getting evaluated each minute.

Using a timer gives more-predictable timing. Because Now is really a one-minute interval timer, a term like:

     (LightOn; Now > 5:00)

will become true between 5:01 and 6:00 after LightOn becomes true.

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #63 on: February 25, 2014, 05:28:28 am »
@RexBeckett

Can you explain a little on the last part of the AutoOff condition.

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

Will the last part ensure that the light will not turn off unless it has been on for more than 10 seconds?

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #64 on: February 25, 2014, 05:47:25 am »
Quote
Will the last part ensure that the light will not turn off unless it has been on for more than 10 seconds?
No. It stops it being turned off automatically if it was turned on within ten seconds of being turned off. This is the term that detects the rapid off/on switching to allow the light to be locked on.

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #65 on: February 25, 2014, 07:56:12 am »
Just a practical question to the light logic above.
If a person is sitting in a room, and the light turns off automatically.
Wouldn't it be good if he could wave his hands and make the light turn on again?
As I understand it with the "(!LightOn; Motion > 30)" expression you have to wait 30 seconds before it will turn on automatically again.
I guess this isn't as easy as it sounds :)

regards

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #66 on: February 25, 2014, 08:09:01 am »
Well the thing about home automation is that there is never one solution that suits everybody. PLEG makes it easy to implement whatever logic you want...

If you remove the > 30 from the sequence expression, the light will come back on as soon as motion is detected. It will make it difficult to turn the light off if the motion sensor can see the light-switch, though.

Some folk get around this by sensing that the TV is on and using that as a lock-on term. The principle being that lack of motion (and brain activity) is normal while watching TV.   ;)

Of course, if you did the on/off/on sequence on the light-switch, it wouldn't turn off however long you sat motionless.

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #67 on: February 25, 2014, 09:37:41 am »
hmm
Could you use the timer to detect manual operation?
If something happens before the timer expires cant that indicate manual operation?

If the light is turned off and on before the timer expires the logic could be set to "manual"

Thanks for using your time on this.

regards 

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #68 on: February 25, 2014, 09:53:22 am »
Quote
If the light is turned off and on before the timer expires the logic could be set to "manual"
It already does this. That's what the (!LightOn; LightOn > 10) term is for.

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #69 on: February 25, 2014, 10:22:11 am »
I understand. I am beginning to think that this can not be done the way I was hoping for.
Here is my scenario:

I am using this in my bathroom. If the timer expires while someone is in the bathroom it is acceptable to wave their hands.
But it is not very good WAF to have to wait 30 seconds berfore one can wave to the sensor. So lets say I remove this part of the logic. Then when the person waves right after the room goes dark, the light would be locked on (if the person does not sit in the dark for 10 seconds first).

As we all know bad WAF kills all HA projects :)
So it might be that the manual override is to hard to implement with the required WAF.
That is when I thought one could use the timer to detect that if something happens before it expires a manual operation has happened. But this might be the same as you have done.

Thanks for your effort!

regrads

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #70 on: February 25, 2014, 10:51:12 am »
You might want to incorporate more state into your logic.
In particular instead of going    OFF - ON 5 minutes  - OFF
Maybe you need    OFF - ON - Blink - OFF
You can still extend the ON time if you have motion during the blink interval.
This way people do not get into the 30 second wait cycle unexpectedly.
Split your ON time into a 4 1/2 Min On + Blink + 30 seconds. If you have a dimmer you can momentarily dim the lights.
You might also customize the on times based on time of day ... are their certain times of day/week where long showers/bathes are common ?


Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #71 on: February 25, 2014, 12:17:06 pm »
@haavard, I haven't tested this but see if it does what you want:

Conditions
AutoOn     !LightOn and ItsNight and Motion and (!LightOn; Motion)
KeepOn    (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff     LightOn and !Timer and (LightOn; !Timer) and ((!LightOn; LightOn > 10) or (AutoOn; LightOn < 5))


Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #72 on: February 26, 2014, 06:50:54 am »
@RexBeckett
Thanks for your update!
I have implemented the logic and done some light testing (late last night) and so far I looks good.
What is the philosophy with this logic?
I know a little about logic, but I find it difficult to understand the AutoOff condition.. :)

regards


Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #73 on: February 26, 2014, 09:21:23 am »
Quote
What is the philosophy with this logic?
I know a little about logic, but I find it difficult to understand the AutoOff condition..
Only half of it is logic. The real power is in the sequence expressions. [imho]This is one of PLEG's greatest features.[/imho]

AutoOff     LightOn and !Timer and (LightOn; !Timer) and ((!LightOn; LightOn > 10) or (AutoOn; LightOn < 5))

AutoOff will become true if:

The Light is on AND Timer has ended AND Timer ended after the Light was turned on AND EITHER the Light was last turned on more than ten seconds after it was turned off (i.e. not by rapid off/on) OR the Light was last turned on less than five seconds after AutoOn became true (i.e. it was turned on by motion).

Does that help?
 

Offline haavard

  • Full Member
  • ***
  • Posts: 162
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #74 on: February 27, 2014, 01:45:35 am »
@RexBeckett
Thank you for your explanation. It helps a lot.
I tested a bit more yesterday. And when the light turned off while I took a shower, I waved at the sensor and the light turned on again, only to turn off 10-20 seconds later. I dont see how this can happen? My Pleg is now setup as follows:

Triggers
Name   Description
Motion    Sensor Bad is tripped
LightOn    Spotter Bad 3 etg is turned on

Schedules
Name   Type   Time   Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay
NightLevel   Weekly   23:30:00   1,2,3,4,5,6,7   None   Weekly   05:45:00   1,2,3,4,5,6,7   None
Timer   Self ReTrigger         None   Interval   20:00      None

Conditions
Name   Expression
AutoOn    !LightOn and Motion and (!LightOn; Motion)
KeepON   (LightOn and Motion and (LightOn; Motion)) or AutoOn
AutoOff   LightOn and !Timer and (LightOn; !Timer) and ((!LightOn; LightOn > 10) or (AutoOn; LightOn < 5))

Actions

Actions for Condition: AutoOn
Immediate
Device   Action   Arguments
Spotter Bad 3 etg   SetLoadLevelTarget    newLoadlevelTarget=100

Actions for Condition: KeepON
Immediate
Device   Action   Arguments
Smartlys Bad   StartTimer    timerName=Timer intervalTime=

Actions for Condition: AutoOff
Immediate
Device   Action   Arguments
Spotter Bad 3 etg   SetLoadLevelTarget    newLoadlevelTarget=0

regards