The Vera Community forums have moved!

Advanced => Plugins & Plugin Development => Programming => Program Logic Plugins => Topic started by: RexBeckett on January 02, 2014, 05:44:48 am

Title: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2014, 05:44:48 am
Program Logic Event Generator (PLEG) is an amazingly powerful and flexible tool that can be used to implement almost any automation scenario on Vera. This forum has many examples of creative and ingenious PLEG applications. Once you learn to use PLEG, you will wonder how you managed without it - and why you didn't try it sooner!  ;D

PLEG Basics is intended to provide newcomers with an explanation of how PLEG works and how to use its many features. Each feature is described in detail with examples of how it may be used. The guide is in the form of a pdf document with bookmarks to help with navigation.

Edit: 24/01/2014 09:30 New version attached. Updated to include new features of PLEG V5.6
Edit: 29/01/2014 13:40 New version attached. Updated to include new features of PLEG V5.7
Edit: 12/02/2014 18:00 New version attached. Updated to include new features of PLEG V5.9
Edit: 05/03/2014 11:25 New version attached. Updated to include new features of PLEG V6.2
Edit: 29/01/2015 16:42 New version attached. Updated to include new features of PLEG V7.35
Title: Re: PLEG Basics - An Introduction to PLEG
Post by: flyveleder on January 02, 2014, 06:14:42 am
Beautiful work! This is how documentation should be done - always ;-)

Brgds,
Martin
Title: Re: PLEG Basics - An Introduction to PLEG
Post by: mikee123 on January 02, 2014, 06:30:43 am
Could not agree more with @flyveleder

Great work, very good manual, even for someone like me who has some understanding of PLEG, it is great just to be able and check things I have not used for a while.

This should be made sticky
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Vreo on January 02, 2014, 11:51:27 am
Hey Rex, nice PDF! Thanx! I only one to make sure of one thing.
Quote
Remember that PLEG will only perform an evaluation cycle when some Trigger, Device Property or
Schedule has changed and is used in one of the Condition expressions. When an evaluation cycle is
triggered every minute because the special term Now has been used in a sequence expression, the
information displayed by the Status report will not be updated. It is updated when an evaluation
cycle is triggered by a change in a Trigger, Device Property or Schedule.

Does this means that if I have in a PLEG, say a 100 triggers. And in the conditions, I am only using 2 of those, it will only run when any of those two works?? If this is entirely true, it is a very good new, I thought that it run anytime any trigger changes regardless if it is or not in a condition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2014, 06:24:46 pm
Thanks for the feedback, guys. I appreciate it.   :D

Quote
Does this means that if I have in a PLEG, say a 100 triggers. And in the conditions, I am only using 2 of those, it will only run when any of those two works?? If this is entirely true, it is a very good new, I thought that it run anytime any trigger changes regardless if it is or not in a condition.
PLEG will have to perform some processing when any of its Triggers occur even if it doesn't result in some/any Conditions being evaluated.

I have to ask why you have 100 Triggers defined if you only need two of them?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Vreo on January 02, 2014, 06:37:46 pm
I was putting an exagerated example, but let me elaborate more my escenario:

I started with one PLEG and basic stuff months ago. PLEG is so great that now I have 80 conditions that come from like 40 triggers, 5 schedules and 10 properties, all this in one single instance of PLEG. I am going to split those into two or three instances, the way I am planning to do it is explained in this post:

http://forum.micasaverde.com/index.php/topic,18221.msg141083.html#msg141083 (http://forum.micasaverde.com/index.php/topic,18221.msg141083.html#msg141083).

The thing is that when I am done, I will have triggers in each pleg that are not used in that instance, but in the other, and viceversa. So... if the previous quote is true, then I don't have to worry, else, I have to take time to explicitly check wich ones are not used in each instance and delete them.

Thanks!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 02, 2014, 07:14:08 pm
You will want to delete them!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Vreo on January 02, 2014, 07:40:12 pm
Thansk Richard, I will.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Jeff Lacy on January 02, 2014, 08:39:52 pm
Rex,
     First, just a big Thank You! for taking the time to put the documentation together. As someone new to HA I had been anxious to try PLEG plug ins but felt that I needed some additional understanding of what it could and would do and more so, how to "think like PLEG".  I believe I speak for many who, though they may not bother to mention it, nonetheless feel this was a welcome endeavor.

Richard,
     Again, as someone new to the world of HA and to the forums here on MicasaVerde (MiOS) I want to thank you as well, it doesn't take a long time member to see how much time and effort you spend on the various plug ins and applications as well as being so involved in the forums with helping to answer the many questions uses have, etc.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: spudjr on January 02, 2014, 09:33:47 pm
Thanks for the great write up. Makes some of the fog disappear  :)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on January 02, 2014, 09:49:59 pm
Rex,
Just finished reading the PDF. This is great, just finished using it to do some more automation and I planning on implementing the example you have for the Simple Heater Timer. Right now, I have schedules defined using scenes and I was going to  try to figure out how to enable/disable the scenes using PLEG and a virtual switch. Now I don't need to as the that will do exactly what I want.

Thanks for your work on the documentation and Richard's work on the PLEG PlugIn automation is becoming easier (at least for me).
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: bucko on January 03, 2014, 09:26:49 pm
@REXBECKETT

Nice work there! I thank you for all your work making this pdf. This is a big help and a great reference tool.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garrettwp on January 05, 2014, 08:16:50 am
Rex,

Just wanted to say great work on the documentation. Hopefully this will help people starting out with pleg and those who did not know some things were possible with pleg.

- Garrett
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Theduck38 on January 05, 2014, 12:43:49 pm
I am adding my voice to the multitude saying "great work" !!! This tutorial is very well made and the examples very clear. So thank you very much for this document.

... and once again, thank you Richard for creating such a great plugin !
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 05, 2014, 06:45:04 pm
Quote
... and once again, thank you Richard for creating such a great plugin !
You really must admire a guy who creates a plugin that is so powerful that it takes twenty pages to describe how it works!  8)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: poordom on January 09, 2014, 12:41:56 pm
Good afternoon All,

I am new to this site, my name is Dom, I am in the market to revamp my Home Automation package.

I have been using an Ocelot and other related peripherals.

I am looking at the HomeSeer Zee, and the Vera Lite.

What I which to have in my new purchase,  1) the usual  ( If and Then ) condition base operation, 2 ) regular schedulling, 3 ) External hardware triggers, ie. lights sensor and temperature sensors.

It goes without saying the the GUI is always a WOW factor that is required in any Home Automation set-up, and last but not least, dependable, easy to set-up, update, upgrade and maintain.

I would like to use the X-10 protocol for the time being, and eventually gradutate to Z-Wave.

Are these objectives attainable through VERA.

Your asistance would be greatly appreciated.

Dom
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: twostep on January 15, 2014, 06:20:26 am
Hi Rex,

it's a great relief finding some well constructed documentation rather than having to trawl numerous forum messages. The one area that I don't get yet is the use of the self trigger timer. Any chance you can expand the last example in the pdf by writing an explanation of what each of the instructions are doing?

twostep
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 15, 2014, 06:45:30 am
Hi @twostep,

Thanks for the feedback. I'll try to do this in the next release. Meanwhile:

Conditions
Target       ItsNight ? 14 : (Home ? 20 : 16)

This sets the value of Target to 14 at night or, during the day, 20 when Home is on and 16 when Home is off.


TimerEnd    !Timer5M

TimerEnd will get a timestamp when Timer5M completes (stops).


SendSP    (Target != LastTarget) or (TimerEnd and (TimerEnd; Now < 1:00) and (SetPoint != Target))

Becomes true if Target has changed since last run, or Timer5M has just ended and SetPoint is still not equal to Target. In other words, it either shows that something changed Target or that, after five minutes, the thermostat didn't change to our last requested Target. It indicates that we need to send another SetCurrentSetpoint request.


LastTarget   Target

LastTarget gets updated to the current value of Target for comparison on next run.

Actions
SendSP      TRV SetCurrentSetpoint   NewCurrentSetpoint={(Target)}
                  PLEG StartTimer  timerName=Timer5M

The first one sends a SetCurrentSetpoint request to TRV using the value of Target as NewCurrentSetpoint. The second one starts the Self-Trigger timer Time5M.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: twostep on January 15, 2014, 03:53:14 pm
Thanks Rex,

This is really useful.

Title: PLEG Basics - An Introduction to the Program Logic Event Generator V5.6
Post by: RexBeckett on January 24, 2014, 04:35:08 am
There's an updated version of PLEG Basics that includes the new features introduced in PLEG V5.6. See the first post to download the pdf.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: svaleb on January 24, 2014, 09:07:54 am
Thanks Rex.
I am looking forward to be able to use PLEG better.
And thanks to Richard for the great work.
Regards
         CE
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on January 26, 2014, 01:03:52 pm
Hi Rex,

assume I have a motion sensor that turns a lamp on when there is motion and light level is below 35%. And after 3 minutes turns it off. This works well with my pleg:
(CurrentLevel < 35) and Motion

but now, where do I start if I want this lamp to turn off AFTER the last motion?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 26, 2014, 02:22:21 pm
Hi Rex,

assume I have a motion sensor that turns a lamp on when there is motion and light level is below 35%. And after 3 minutes turns it off. This works well with my pleg:
(CurrentLevel < 35) and Motion

but now, where do I start if I want this lamp to turn off AFTER the last motion?
One possibility is a Condition like this:

AutoOff     LightOn and !Motion and (!Motion; Now > 3:00)

This will become true three minutes after the last motion trip cleared - if the light is on.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on January 26, 2014, 02:32:54 pm
Thanks. And what would "AutoOff" and "LightOn" be? Triggers?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on January 26, 2014, 04:10:01 pm
Thanks. And what would "AutoOff" and "LightOn" be? Triggers?

AutoOff would be a Condition.

LightOn would be a Trigger.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on January 27, 2014, 10:51:12 am
Rex, Brian,

sorry, my bad. I really do not know where to start...

I want: the light to only turn on when light level is below 35% and motion is detected. (this wors great with below).
Then additionally I would want to "reset" the 3 minutes timer with every new motion detection during that "running" 3 minutes.

this is it currently

Lamp Trappenhuis Light & Beweging

Device ID: 1832014-01-27 16:49:03.549 PLC Version: 5.6

Triggers

Name   Description   State   Last True   Last False
Motion    Sensor 2e Verdieping Beweging armed is tripped   false   2014-01-27 08:52:30.438   2014-01-27 08:53:22.117

Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
CurrentLevel   Sensor 2e Verdieping Licht   CurrentLevel   21   2014-01-27 16:44:48.910   2014-01-27 15:44:30.245

Conditions

Name   Expression   State   Last True   Last False
c1   (CurrentLevel < 35) and Motion   false   2014-01-27 08:52:30.440   2014-01-27 08:53:22.119
Actions

Actions for Condition: c1

Immediate

Device   Action   Arguments
Lamp Trappenhuis 2e Verdieping   SetTarget    newTargetValue=1
Delay 03:00

Device   Action   Arguments
Lamp Trappenhuis 2e Verdieping   SetTarget    newTargetValue=0

What do I need to change add and where?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 27, 2014, 11:45:40 am
Once you start an ACTION ... it will always complete ...  including delayed actions.

There is no way to extend this. When done in a Scene, if Vera Restarts during the actions, the delayed actions are not exectuted. In PLEG/PLTS even if Vera Reboots, the delayed actions will get executed.


An input schedule:
TImeout    A Self Restartable Timer for 3 minutes

You need you break your logic into two conditions.
TriggeredCondition       Your Logic Here
DelayedTriggerCondition     TriggeredCondition and (TiggeredCondition;!Timeout)


Actions:
TriggeredCondition    Start the Timeout Timer + any thing else you want to do every trigger
DelayedTriggerCondition    Any Actions after the timeout expires.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on January 27, 2014, 02:37:32 pm
Richard i really appreciate your reply and info. But i still do not understand how to achieve what i want... question is still: what do i need to change/add and where?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 29, 2014, 08:45:52 am
There's an updated version of PLEG Basics that reflects the changes in PLEG V5.7. I have also added some explanation of the recent issues people have had with Start-only Schedules. See the first post to download the pdf.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: hamishb on January 29, 2014, 11:39:01 pm
OK I have installed PLEG and tried to add a trigger for when device #4 Study Sensor is triggered.

I tried to edit the "undefined" Name and Description but do not seem to be able to change this text.

Ideas?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: hamishb on January 29, 2014, 11:41:45 pm
OK I am on UI6 so maybe that's the problem.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: clippermiami on February 02, 2014, 06:05:35 pm
The Kwikset lock returns a value "sl_UserCode" that contains the string {UserID="1" UserName="Code 7"} without the braces of course. Normally one would describe a LITERAL in quotes i.e "LITERAL". In PLEG how does one describe a LITERAL that contains quotation marks i.e. how can I escape the interior quotation marks? Single Quotes around the LITERAL? I tried the old forwad slash to escape  the interior quote marks (i.e. /") but PLEG didn't like that at all.

Is it possible to test substrings? Use RegEx on the string and extract just the "Code 7" part etc?

Thanks

John
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 02, 2014, 06:33:11 pm
Quote
In PLEG how does one describe a LITERAL that contains quotation marks i.e. how can I escape the interior quotation marks? Single Quotes around the LITERAL?
Yes - you can use single or double quotes to delimit a string literal in PLEG.

Quote
Is it possible to test substrings? Use RegEx on the string and extract just the "Code 7" part etc?
I'm afraid not.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: clippermiami on February 02, 2014, 07:44:11 pm
Thanks, I'll give it another go.

John
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Vreo on February 03, 2014, 02:32:22 pm
The Kwikset lock returns a value "sl_UserCode" that contains the string {UserID="1" UserName="Code 7"} without the braces of course. Normally one would describe a LITERAL in quotes i.e "LITERAL". In PLEG how does one describe a LITERAL that contains quotation marks i.e. how can I escape the interior quotation marks? Single Quotes around the LITERAL? I tried the old forwad slash to escape  the interior quote marks (i.e. /") but PLEG didn't like that at all.

Is it possible to test substrings? Use RegEx on the string and extract just the "Code 7" part etc?

Thanks

John
Clippermiami, I use this to get the Users name:

Code: [Select]
local UserCode = luup.variable_get("urn:micasaverde-com:serviceId:DoorLock1","sl_UserCode",63) or "Unknown"
local User = string.gsub (UserCode, " ", "+" )
local User = string.gsub (User, "\"", "" )
local ID = string.sub (User, 8, 8 )
local Name = string.sub (User, 19 )
local DeviceN = luup.devices[63].description
Hope it works for you.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: SaucyPig on February 04, 2014, 01:16:53 pm
Thanks for what I guess is great work.
I say guess as I barely got past the second paragraph before my brain started dribbling from my ears.
Do you have a basic guide to help out with this basic guide, as it throws you in the deep end if you don't know a boolean value from a string expression.  Or should I just stick to switching on a light at a time through Vera if I cant get my head round even this?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 12, 2014, 01:09:00 pm
There's an updated version of PLEG Basics that reflects the changes in PLEG V5.9.

The main change is the new optional parameter intervalTime for PLEG's StartTimer action. To celebrate its arrival, I have added an example of how it could be used with a State Variable to implement a bathroom fan timer - not unlike the one in PLTS Basics.  ;D

See the first post to download the pdf.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: rtt3821 on February 12, 2014, 01:27:27 pm
I want to schedule 2 or 3 different schedules, i.e. weekend, vacation, daily. Do I have to install 3 PLEG apps to do this or do I use just one?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 12, 2014, 01:30:11 pm
Thanks for what I guess is great work.
I say guess as I barely got past the second paragraph before my brain started dribbling from my ears.
Do you have a basic guide to help out with this basic guide, as it throws you in the deep end if you don't know a boolean value from a string expression.  Or should I just stick to switching on a light at a time through Vera if I cant get my head round even this?
Sorry, @SaucyPig, I only just saw your post.

I'm afraid I don't have a guide to basic computing terms but you can easily find out what they mean with a quick Google. There are many different online dictionaries that cover all aspects of computer jargon.

The main thing about computer jargon is that it is only confusing until you find out what it means. Generally the concepts are quite straightforward. They have to be - computers are not smart, just quick.

I can only suggest following Robert the Bruce's maxim...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 12, 2014, 01:35:04 pm
I want to schedule 2 or 3 different schedules, i.e. weekend, vacation, daily. Do I have to install 3 PLEG apps to do this or do I use just one?
You can do it in a single PLEG. One PLEG can handle many different Schedules and Conditions. You might want to consider partitioning into separate PLEGs if you reach forty Condition statements.

Many of us partition PLEG logic according to what is being controlled. e.g. A PLEG for heating, another for lighting, etc.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: flyveleder on February 12, 2014, 04:20:00 pm
I have been going through the manual, trying to find out how to run luup-code on PLEG actions; I didn't succeed.

Can you point me in the right direction ?

Thanks.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 12, 2014, 04:24:43 pm
I have been going through the manual, trying to find out how to run luup-code on PLEG actions; I didn't succeed.

Can you point me in the right direction ?

Thanks.
I'm not sure what you mean. Can you explain what you want to achieve?
 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Freddan101 on February 12, 2014, 05:44:20 pm
I want to schedule 2 or 3 different schedules, i.e. weekend, vacation, daily. Do I have to install 3 PLEG apps to do this or do I use just one?
You can do it in a single PLEG. One PLEG can handle many different Schedules and Conditions. You might want to consider partitioning into separate PLEGs if you reach forty Condition statements.

Many of us partition PLEG logic according to what is being controlled. e.g. A PLEG for heating, another for lighting, etc.
I would like to partition my PLEG logic as much as possible but wonder if this will drain the Vera resources, having multiple PLEG devices instead of one or two?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 12, 2014, 05:54:10 pm
Quote
I would like to partition my PLEG logic as much as possible but wonder if this will drain the Vera resources, having multiple PLEG devices instead of one or two?
The biggest impact will be on your available memory. Each PLEG device requires around 2MB of memory (as do other plugins). If you have plenty of free memory then this may not be a problem for you. If you are running on a Vera Lite and you already have a number of plugins, it may be better to concentrate your logic into a small number of PLEGs.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Freddan101 on February 12, 2014, 05:55:21 pm
Quote
I would like to partition my PLEG logic as much as possible but wonder if this will drain the Vera resources, having multiple PLEG devices instead of one or two?
The biggest impact will be on your available memory. Each PLEG device requires around 2MB of memory (as do other plugins). If you have plenty of free memory then this may not be a problem for you. If you are running on a Vera Lite and you already have a number of plugins, it may be better to concentrate your logic into a small number of PLEGs.
I do have a Vera Lite so I will try to keep my number of PLEGs down. Thanks.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Theduck38 on February 13, 2014, 06:09:04 pm
I have been going through the manual, trying to find out how to run luup-code on PLEG actions; I didn't succeed.

Can you point me in the right direction ?

Thanks.
Hello,
As PLEG action, you can run a scene containing the luup code...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: flyveleder on February 13, 2014, 06:11:49 pm
Thanks duck, this is what I do now, I just thought you could avoid scenes with PLEG.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 13, 2014, 06:21:07 pm
One day I will add LUA to PLEG/PLTS actions.
I just wanted to see how far this idea could go without LUA code.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Theduck38 on February 14, 2014, 01:36:04 pm
One day I will add LUA to PLEG/PLTS actions.
I just wanted to see how far this idea could go without LUA code.
Hello Richard,
To me it has been very far ! But as users are never satisfied  ;D , I may ask you again to consider adding some mathematical functions (or a way to use a startup pre-defined lua function) in the PLEG ?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: C4Vette on February 20, 2014, 01:13:43 pm
second that

I tried to let a PLEG-action write to "VariableContainer" using Luup and that didn't succeed  ::)  Then I found this topic....
Any other possibility to write the outcome of {device([14]service[urn:upnp-org:serviceId:TemperatureSensor1].CurrentTemperature)} to a variable without using a scene?

What I want to accomplish is to store the previous temperature so it can be compared against the current temp and only notify when the current temp is lower then the previous.

Ed
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BulldogLowell on February 20, 2014, 01:54:39 pm
Yes,

When the INPUT is part of the PLEG as a device property, you can go to the advanced tab for the action in PLEG, select the Variable Container, then add.

Then select the Device then add and then the variable you want to populate and the name of the INPUT you retrieve in the html call inside the parenthesis and braces.  In this example, I have a Input (Device Property) of RearDim.

Screenshot attached.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 20, 2014, 06:11:48 pm
second that

I tried to let a PLEG-action write to "VariableContainer" using Luup and that didn't succeed  ::)  Then I found this topic....
Any other possibility to write the outcome of {device([14]service[urn:upnp-org:serviceId:TemperatureSensor1].CurrentTemperature)} to a variable without using a scene?

What I want to accomplish is to store the previous temperature so it can be compared against the current temp and only notify when the current temp is lower then the previous.

Ed
As @Bulldoglowell has said, you can write the value of a PLEG Device Property or Condition to a VirtualContainer variable with an Action:

Device Properties
Temperature     TemperatureSensor  CurrentTemperature

Conditions
SaveTemp          <some trigger expression>

Actions
SaveTemp          VContainer  SetVariable1  newVariable1={(Temperature)}


It is also possible to detect a lower temperature without using a VariableContainer:

Conditions
LowTemp     Temperature < LastTemp
LastTemp     Temperature
    - or -
LastTemp     <expression to trigger save> ? Temperature : LastTemp

Actions
LowTemp       <action for temperature is lower>




Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: C4Vette on February 21, 2014, 05:20:49 am
@RexBeckett
Thank you! The first example I have working now. Did this with a MaxLow and a MaxHigh so I have these figures visable on the Dashboard. Under Actions added a rule to send a push-notification so I know when my heater is not working properly.
The second example is so simple I don't get it....
Maybe if I tried using it but for now the second Condition is a mystery to me. The first condition is easy: LowTemp becomes true if 'Temperature' is lower then 'LastTemp'. But won't this fail the first time because there is no 'LastTemp? (Didn't try). For the second Condition: LastTemp will be tru if if (? 'Temperature' exists maybe?). But what is the use of this? For the example after "- or -" LastTemp becomes true if <a trigger happens> then Temperature (does what?) else LastTemp. I presume 'LastTemp' will become one or the other but isn't a Condition just true or false?
Looks very powerfull but is beyond my understanding.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 21, 2014, 05:55:24 am
Quote
But won't this fail the first time because there is no 'LastTemp?
The first time this runs, LastTemp will be 0 - but not for long...

Quote
LastTemp will be tru if if (? 'Temperature' exists maybe?). But what is the use of this?
Think of it this way: Each time Temperature changes, LastTemp will be set to the new value. But this happens after the Condition LowTemp has been evaluated to see if the new Temperature is lower than the previous one. LastTemp just keeps the last value of Temperature.

Quote
For the example after "- or -" LastTemp becomes true if <a trigger happens> then Temperature (does what?) else LastTemp. I presume 'LastTemp' will become one or the other but isn't a Condition just true or false?
Conditions can have a value other than just true or false. This Condition uses the Conditional expression to assign one of two values to itself. If <expression to trigger save> becomes true, LastTemp gets the first value which is the current value of Temperature. If not, it gets the second value which is its own value so no change. If <expression to trigger save> is always true, this does exactly the same as:

LastTemp     Temperature

The only reason to use the Conditional version is if you wanted to control the circumstances under which you updated the saved value of Temperature.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: C4Vette on February 21, 2014, 07:55:35 am
Cool, I understand it now and have learned something new today! Thanks again RexBeckett.
As I thought already: PLEG is really powerful. And now I do make use of the conditional version to control when the value is saved to accomplish only an extremest value.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on February 22, 2014, 05:04:31 pm
I must be doing something wrong, but can't find anything about it in the forum/s and/or instructions.  I've installed PLEG and Program Logic Core (v5.93).   I now see a PLEG device in MiOS.

When I go to the Inputs tab on the PLEG device, I get "opening pleg_inputs..." and the moving status bar... and it never goes anywhere from there. 

I'm committed to trying to learn this over the weekend, but can't seem to get very far.  I'm guessing I may be missing a key first step?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 22, 2014, 05:11:59 pm
@tomgru, that issue is usually fixed by refreshing the browser page. I note from elsewhere, though, that you are a committed IE user so no guarantees. The plugin author uses Chrome...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on February 22, 2014, 05:18:02 pm
@tomgru, that issue is usually fixed by refreshing the browser page. I note from elsewhere, though, that you are a committed IE user so no guarantees. The plugin author uses Chrome...

"committed' may be accurate in more than one way :-).  I tried reloading... didn't work.  But start/stopping browser did. 

thanks!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on February 23, 2014, 08:44:51 pm
ok... I've ready the entire getting starting guide, and i'm still struggling.  I have a simple question first.. then a greater need for some guidance.
question one:  if I want to create multiple PLEG events, how do I create another device?  Or do I?  Do you just create all of the event/s code in the one device for multiple things you may want to do? 

that aside... here's what i'm trying to do.  I want to use a motion sensor to turn on a few lights at a certain dim level, but only once (if activated), and only if it's during a certain range of hours in the morning.  Scenario... wife gets up in morning... walks down stairs (trips motion sensor), and lights come up in kitchen and family room. 

Since we get up at the same time M-F, give or take, I only want this to run during those times.  Not on weekends where we attempt to sleep in.  And I only want it to be run once, or not at all if someone has already gotten up and turned the lights on.

I'm SURE PLEG can do this, but i'm a bit lost. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BulldogLowell on February 23, 2014, 09:08:49 pm
Create  a schedule for your actions, call it say "IsMorning"

Triggers:

LightOn (You need this because you don't want to trigger an event if the light(s) are on already)
IsMorning (Your schedule that goes MTWTF and from say 05:00 to 07:30)
IsMotion (IsMotion may be one of several motion events like MotionKitchen, MotionStairs or any or all of them)

Condition:

LightWasOn = (LightOn;IsMorning)  [this tests to see of the light was on at any time since IsMorning started)
TurnOnLights = !LightWasOn AND IsMorning AND !LightOn and IsMotion [this says turn on the light if the lights were not on this morning and it is during IsMorning and the light is not on already and there is motion]

Action:
TurnOnLights  Go ahead and Set the lights you want to go on and their respective Dim levels

note that you won't create an action for LightWasOn, we just created a condition to be used in the next condition
Title: PLEG Basics - Another Motion-triggered Light Example
Post by: RexBeckett 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:


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
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer 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 ?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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))

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett 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?
 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard 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
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 27, 2014, 07:55:55 am
Do you have a Motion on TIME of about 20 seconds ?

I think you should be starting the timer in the AutoOn Action.

Currently you require a Second motion to start the timer.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 27, 2014, 08:40:24 am
RTS is correct. My mods have messed-up the timer start logic. Just add an Action to AutoOn to start Timer. I should know better than to suggest untested changes...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard on February 28, 2014, 03:33:10 am
I have added the action as you suggested. I will see how it works later today. I have had some issues with getting a license, but hopefully I can test it anyway.

I assume I should not remove the start Timer action from the KeepOn condition.

regards
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 28, 2014, 03:43:23 am
Correct ... the start timer should be in both actions.
In the keep on action ... it extends the timer.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on March 01, 2014, 02:41:17 pm
Create  a schedule for your actions, call it say "IsMorning"

Triggers:

LightOn (You need this because you don't want to trigger an event if the light(s) are on already)
IsMorning (Your schedule that goes MTWTF and from say 05:00 to 07:30)
IsMotion (IsMotion may be one of several motion events like MotionKitchen, MotionStairs or any or all of them)

Thanks... just getting to try this today, and still confused. 

1.  when creating the schedule "IsMorning", I do this within PLEG, correct?
2.  Then for the triggers... in PLEG, I have to select a device before I can create a trigger.  So, for LightOn, what device would I select?  the light I want in the scene?  If it's more than one light, do I create a trigger for each light? 
3.  Similar... what device do I select when creating a trigger for IsMorning?

sorry.. i'm almost there.. appreciate help!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on March 01, 2014, 05:08:14 pm
Quote
1.  when creating the schedule "IsMorning", I do this within PLEG, correct?
Exactly. You do this on PLEG's Schedules tab.

Quote
Then for the triggers... in PLEG, I have to select a device before I can create a trigger.  So, for LightOn, what device would I select?  the light I want in the scene?
Correct. The reason for having this Trigger is to avoid turning on the light if it is already on. It isn't that it would break anything but it is generally good practice to avoid unnecessary commands.

Quote
If it's more than one light, do I create a trigger for each light?
That is slightly more difficult. If you are going to control each light separately, you would want a Trigger for each one. If you plan to turn them on or off as a group, you could use the state of a single light to represent them all. The question to ask yourself is: If one light is already on, do I want to turn the others on or not?

Quote
3.  Similar... what device do I select when creating a trigger for IsMorning?
IsMorning will be a Schedule so you don't need to create a Trigger for it.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on March 01, 2014, 07:37:17 pm
Thanks... OK, I think I have this setup, but it's still not working.  Attached is a screen shot for the Status page.  I set the time for 30 minutes before/after the actual time to test. 

see any glaring screw-ups?

Also, when I created the two triggers, it added  "1" to the end of each?  why? 

Lastly, when trying to type in the condition expression in the dialog box, nothing would type at first.... meaning i'd type but nothing would input into the box.  I'd have to click around a bit to get it to work.  thoughts?

Happy to pay/register if that's what's going on here.  Was going to anyway... but just trying to get this one to work first. 

Thanks.

PS. I'm confused about arm/bypass, although I tried it with each.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on March 01, 2014, 07:51:22 pm
Quote
I set the time for 30 minutes before/after the actual time to test. 
When you create a new Schedule, it will not get synchronized to the current time until the start-time occurs. You can force it to be true by clicking the Do It Now button.

Quote
Also, when I created the two triggers, it added  "1" to the end of each?  why? 

PLEG thinks that you already created Triggers with those names. If you did so but then deleted them, you need to refresh your browser page before trying to reuse the names.

Quote
Lastly, when trying to type in the condition expression in the dialog box, nothing would type at first.... meaning i'd type but nothing would input into the box.  I'd have to click around a bit to get it to work.  thoughts?
Sometimes the first click terminates the edit of the field you were in - like the Condition name. A second click in the expression field should then allow you to enter your expression.

Quote
PS. I'm confused about arm/bypass, although I tried it with each.
If PLEG is not Armed, the Actions will not be executed. Conditions will be evaluated either way and the Status report will show the current state.
 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on March 01, 2014, 08:11:49 pm
Thanks Rex... I think i'm starting to get this, at least in my head.  But it still doesn't work.

I actually deleted the device, then reinstalled from my apps tab. (clicked on create another on the PLEG link in the installed apps)

Recreated all the triggers/conditions/schedules/actions per the original instructions from BullDog. 

Clicked the "do it now" button to sync time.  And still no joy. 

Weirdly now, when I try to click on report or status, nothing happens.  Guessing I screwed something up even more when I deleted the device?  Should I have done something with PLC as well?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on March 02, 2014, 03:40:11 am
Quote
Weirdly now, when I try to click on report or status, nothing happens.  Guessing I screwed something up even more when I deleted the device?
That situation can often be fixed by refreshing the browser page but in your case...

Quote
Should I have done something with PLC as well?
There was a recent issue with the order of installation. I thought it was fixed now but, by deleting your only PLEG device, you may have triggered a re-installation of the code. Try a manual re-installation of PLC:

Code: [Select]
http://<veraip>:3480/data_request?id=update_plugin&Plugin=3086
Quote
And still no joy.
To help, we really need a Status report and a description of what you did, what you expected and what actually happened.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on March 02, 2014, 02:22:07 pm
OK... I just decided to start from scratch.  Uninstalled PLEG and PLC, then reinstalled.  (many reloads inbetween).

Then recreated the routine per Bulldog's advice.  Set the day/time range for something that would work right away.   (clicked do it now)

Turned off the Overhead Sink light, so that when the motion is tripped in front hallway, the sink light (as well as two lamps) will turn on.

Went into the hallway and danced jig in front of sensor to trip.  No joy.  Tried a few times, after reloading, etc...   (it is set to arm)

Interested, when I looked at the status report each time, it does NOT seem to be updating with the subsequent tests (if that tells you anything). So the attached report is really from the first test, although I tripped the motion sensor several additional times for the next 10 minutes.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on March 02, 2014, 02:58:21 pm
A couple of things:

What on-time is your motion sensor set for? It appears to have been tripped for about twelve minutes. Usually when you are using a separate timer or logic plugin to control the lights, you would set the on-time to minimum.

You may need to change your Condition LightWasOn to include AND LightOn. Right now it will stay true even when the light is off provided ItsMorning occurred after the last time the light was turned on.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on March 02, 2014, 03:49:42 pm
A couple of things:

What on-time is your motion sensor set for? It appears to have been tripped for about twelve minutes. Usually when you are using a separate timer or logic plugin to control the lights, you would set the on-time to minimum.

Sorry... I have no idea what this means.  On the trigger tab, for the motion sensor, the only settings I have are:
Event type, set to:  A sensor (door/window/motion) is trigger
Drop down:  Device is tripped

You may need to change your Condition LightWasOn to include AND LightOn. Right now it will stay true even when the light is off provided ItsMorning occurred after the last time the light was turned on.
would the expression look like this:
(LightOn;IsMorning) and LightOn

?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on March 02, 2014, 05:58:25 pm
Quote
Sorry... I have no idea what this means.
When a motion sensor trips, it stays tripped for a certain time before resetting ready for the next trip. This is known as the on-time. It may set with a physical adjustment (knob) or through a configuration parameter on the devices Device Options tab. I would expect this to be mentioned in the sensor's instruction sheet. We may be able to assist if you tell us the make & model.

Quote
would the expression look like this:
(LightOn;IsMorning) and LightOn
Possibly. I'm not entirely sure what you wanted the expression to do but it means: The light is on and it last became morning after it was turned on. Note: it will remain true even when it is no longer morning as long as the light stayed on...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: haavard on March 03, 2014, 03:28:18 am
@RexBeckett

RTS is correct. My mods have messed-up the timer start logic. Just add an Action to AutoOn to start Timer. I should know better than to suggest untested changes...

Just a status update.
The logic is now working very good. In the scenarios that I have used it in it has worked perfectly.
One thing I am verry happy about is response performance.
I now use one pleg for the bathroom lights, and the response is better than it was with the SmartSwitch plugin.
The on time is in most cases as good as instant. I see the motion detector light turns red and before it goes out the light turns on.

Thank you for your help RexBeckett and RichardTSchaefer!
Title: PLEG Basics - Updated for PLEG 6.2
Post by: RexBeckett on March 05, 2014, 06:29:33 am
There's an updated version of PLEG Basics that includes the new features introduced in PLEG V6.0/6.2. See the first post to download the pdf.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MLabuda on March 29, 2014, 01:00:47 pm
Hi Rex,

Can't thank you enough for doing this.  It's very helpful and is much appreciated.  And of course thanks Richard for creating PLEG in the first place.

Mark
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: gtallan on April 01, 2014, 10:39:57 am
I've been experimenting with tweaking your motion-controlled light example from earlier in the thread and some of the thing I was trying didn't work - possibly they didn't make sense.

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.   ;)

This is so true, and getting it just right is so hard. I haven't succeeded yet, but I'm getting closer using PLEG than I did with SmartSwitch!

What I am trying is to set a state, let's say "TVOn" based on someone setting a particular scene from the leviton scene controller (as opposed to casually passing through the room using the regular light switch). Then alter the timer retrigger time based on that variable, extending the motion detector timeout to 2 hours instead of 15 minutes. The thinking was something like:

Condition:
TVTimerDuration = (TVOn ? 02:00:00 : 15:00)

Action:
PLEG StartTimer timerName=xxx intervalTime={(TVTimerDuration)}

well obviously this didn't work - the condition state is always "null". I guess my main question is simply whether the condition state can only be an integer value, and not hold strings (or times, if they are effectively a separate variable type)?

Graham
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 01, 2014, 11:03:20 am
You might also look at my comments on another thread:
   http://forum.micasaverde.com/index.php/topic,24312.msg167968.html#msg167968
And the couple of responses after it.

This is what I use for "SmartSwitch" behavior. 

You could also add a few more tweaks for your example.
1)   Add a TVONAction ... that sets the timer to 2:00:00
2)   Separate the motion and the MotionOn into two conditons.
      This will keep the lights off if someone gets up to go to the bathroom.
      MotionOn  will turn on the lights if the lights are NOT currently on and the timer is OFF.
      Motion extends the timer.
      You could even make it a little more sophisticated with low lights (say at 11) when someone moves and the tv is on ...
     

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: guest141575 on April 07, 2014, 09:49:32 am
In PLEG Basics, page 21

For action Alarm$Alert action says: Alarm eq "Tripped" and (Alarm$Tripped; !Timer30S)

I believe it should be Alarm eq "Tripped" and !Timer30S and (Alarm$Tripped; !Timer30S) so that the expression will be evaluated when the timer comes to an end.  ;D
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on April 07, 2014, 10:03:32 am
In PLEG Basics, page 21

For action Alarm$Alert action says: Alarm eq "Tripped" and (Alarm$Tripped; !Timer30S)

I believe it should be Alarm eq "Tripped" and !Timer30S and (Alarm$Tripped; !Timer30S) so that the expression will be evaluated when the timer comes to an end.  ;D

Strictly speaking, your version of the expression is more correct. However, if the !Timer30S timestamp is later than that of Alarm$Tripped the timer must have ended...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: guest141575 on April 07, 2014, 10:12:01 am
In PLEG Basics, page 21

For action Alarm$Alert action says: Alarm eq "Tripped" and (Alarm$Tripped; !Timer30S)

I believe it should be Alarm eq "Tripped" and !Timer30S and (Alarm$Tripped; !Timer30S) so that the expression will be evaluated when the timer comes to an end.  ;D

Strictly speaking, your version of the expression is more correct. However, if the !Timer30S timestamp is later than that of Alarm$Tripped the timer must have ended...

However, it didn't work when I set it up according to the example. Nothing happened after the timer ran out of time (The expression did not evaluate as true when I looked at the status page). It works now though after my modification. I am a newbie so I can't tell why. :D
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 07, 2014, 11:49:27 am
Probably because the Alarm was not tripped when the timer expired.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: guest141575 on April 08, 2014, 01:25:32 am
Probably because the Alarm was not tripped when the timer expired.
No that's not the case. I start a new thread (http://forum.micasaverde.com/index.php/topic,24486) in case you guys like to have a look into it. Thanks. ส็็็็็็็็็็็็็็็็็็็(ಠ益ಠส็็็็็็็็็็็็็็็็็็็
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dferrey on April 11, 2014, 12:25:13 am
Here is my simple goal.  Use the ping sensors to trip a virtual switch to indicate when either someone is home or not.  Seems simple enough :)

I created my ping sensors, they behave as expected.
I created a virtual switch
I've attached my status.
I'm pretty sure I had a one phone thing working and tried to add a second which would never work.  I went back to one phone and now it's not working correctly :(
Note, I use the inverted option.  I've been testing by switching between inverted and normal.

Thoughts?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on April 11, 2014, 03:29:43 am
Quote
Seems simple enough :)

It does seem simple but phone-pinging is not an exact science. There are many threads where members discuss their finely-tuned ping setups that work most of the time... You may find it beneficial to look for posts where they are using the same type of phone that you have.

Your status shows that your phone is not tripped so, presumably as inverted, you are home. The house is therefore not empty. Seems OK. I would be worried by the fact that you apparently went out at 22:03:20 and came home at 22:04:02, though. Is that what happened or is it a typical ping drop-out?

Quote
I created my ping sensors, they behave as expected.

You don't have a hope of getting a reliable PLEG logic unless your ping sensors work 100% of the time or you know their anomalies so you can program around them. I would start by tuning the ping sensor for minimum drop-outs. You may then need to add some debouncing to the conditions to ignore brief drop-outs. Something like:

HouseEmpty    !PhonePresent and (!PhonePresent; Now > 5:00)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dferrey on April 11, 2014, 11:56:14 am
Quote
Seems simple enough :)

It does seem simple but phone-pinging is not an exact science. There are many threads where members discuss their finely-tuned ping setups that work most of the time... You may find it beneficial to look for posts where they are using the same type of phone that you have.

Your status shows that your phone is not tripped so, presumably as inverted, you are home. The house is therefore not empty. Seems OK. I would be worried by the fact that you apparently went out at 22:03:20 and came home at 22:04:02, though. Is that what happened or is it a typical ping drop-out?

Quote
I created my ping sensors, they behave as expected.

You don't have a hope of getting a reliable PLEG logic unless your ping sensors work 100% of the time or you know their anomalies so you can program around them. I would start by tuning the ping sensor for minimum drop-outs. You may then need to add some debouncing to the conditions to ignore brief drop-outs. Something like:

HouseEmpty    !PhonePresent and (!PhonePresent; Now > 5:00)
Thanks for you comments.  This morning it's behaving exactly as I would expect.  When I switch my sensor from Inverted (home) to Normal (away), the Virtual Switch changes from Off (Home Not Empty)) to On (Home Empty).

Not sure why it's working all of a sudden again.  I'm now going to add the second phone.  I will change the logic to

HouseIsNotEmpty = DaveIsHome OR DonnaIsHome
HouseIsEmpty = Not DaveIsHome AND Not DonnaIsHome

Is that correct?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BulldogLowell on April 11, 2014, 12:29:46 pm
Not sure why it's working all of a sudden again.  I'm now going to add the second phone.  I will change the logic to

HouseIsNotEmpty = DaveIsHome OR DonnaIsHome
HouseIsEmpty = Not DaveIsHome AND Not DonnaIsHome

Is that correct?

or just:

HouseIsNotEmpty = DaveIsHome OR DonnaIsHome
HouseIsEmpty = Not HouseIsNotEmpty

I personally struggle with negating negatives so I'd use an even simpler lexicon so that I would still understand it in a few months...

HouseOccupied = DaveIsHome OR DonnaIsHome
HouseEmpty = NOT HouseOccupied
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dferrey on April 11, 2014, 12:38:47 pm
Thanks, I forgot that concept - I guess I need to work with PLEG more :)
I'll give that a try.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Mothan on April 13, 2014, 06:15:11 am
Hi dferrey,
What phones are you using, I know a android phone is pingable all the time, (to much) and a iPhone is not pingable all the time.
When you don't use your iPhone, it will be pinged as away.



Verzonden vanaf mijn iPad met behulp van Tapatalk
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: NewfD90 on April 13, 2014, 03:36:22 pm
Hi dferrey,
What phones are you using, I know a android phone is pingable all the time, (to much) and a iPhone is not pingable all the time.
When you don't use your iPhone, it will be pinged as away.

And if you're using an iPhone, stop pinging and set up a geofence with iViri.  Rock solid and low battery consumption.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on April 17, 2014, 08:50:22 pm
Trying to create a simple PLEG that turns on some lights at night when I turn off the alarm (e.g. get home).  this is what I have setup (attached)... but what it's doing is running when night occurs (via day and night plugin), when I'm already home.  So I think the input of "alarm DISARMED" is just checking to make sure that is true, and then runs when it is also night.

I've looked at the other alarm settings - but can't figure out what might work. 

Thoughts?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BulldogLowell on April 17, 2014, 09:21:52 pm
you could add a sequence expression and test to see that IsNight happened first:

LightsOnAlarmOff = IsNight AND AlarmOff AND (IsNight;AlarmOff)

this way, when IS night becomes true and AlarmOff was already true, LightsOnAlarmOff won't become true.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on April 18, 2014, 12:11:03 pm
you could add a sequence expression and test to see that IsNight happened first:

LightsOnAlarmOff = IsNight AND AlarmOff AND (IsNight;AlarmOff)

this way, when IS night becomes true and AlarmOff was already true, LightsOnAlarmOff won't become true.

Thanks... tried that quickly this morning, but it didn't seem to work.  the good news is that it didn't turn the lights on when it became 'night'... but the bad news is that it didn't turn on anything when I disarmed the alarm. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 18, 2014, 12:46:37 pm
Post  a PDF version of the status report .
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on April 18, 2014, 01:35:25 pm
Post  a PDF version of the status report .

Thanks for looking at it.  Attached.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 18, 2014, 07:03:07 pm
Everything looks right.
Make sure the PLEG is armed.

To test
1) make sure day or night device indicates day.
Toggle to make it day.
2) Turn the alarm on and off.
     It should not turn on the lights.
3) Generate a status report. Call it day.
4) Now make sure day or night indicates dark.
5) Turn the alarm on and off.
     The lights should come on.
6) Generate a status report. Call it night.

If you still have problems post the day and night reports.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tomgru on April 23, 2014, 01:51:27 pm
thanks for the help.  Seems to be working now!!!!!! 
Title: Question about user guide.
Post by: 93732 on April 23, 2014, 04:08:49 pm
Hi Rex,

I had a question about your PLEG basics guide, particularly regarding this statement on page 12 of the PDF:

Note that as Now only fires once per minute, it is not suitable for precise timing. The expression:
Event; Now > 1:00 could become true at any time between *1:01 and 2:00* after Event becomes true.

Shouldn't the are between the asterisks say "0:01 and 1:00"?

Hypothetically, lets say PLEG does a check at time 0:00 and again at time 1:00.  If an event occurs at 0:00 and assuming PLEG is not able to detect a "simultaneous event," then the PLEG should detect that the event has occurred at time 1:00.  I don't see a situation where it would take 2 minutes to detect an event. Is my logic or understanding of PLEG incorrect here?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 23, 2014, 05:53:00 pm
The document is correct.
The constraint will only be true if NOW has a time stamp > than 1:00

But because NOW is only evaluated once per minute, and it runs asynchronous to other actions it will be true between 1:00.001 and 1.59.999 after the first event.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on April 23, 2014, 05:54:40 pm
Hi @93732,

The sequence expression (Event; Now > 1:00) will be true when the timestamp for Now is more than one minute greater than the timestamp for Event. Now occurs one per minute - on the minute. The two extremes are:

Event happens exactly on the minute. One minute later, the timestamp for Now is exactly one minute greater than that for Event so the expression remains false. After two minutes, the expression will be true.

Event happens one second before the minute. One second later, the timestamp for Now is one second greater than that for Event so the expression remains false. After another minute, the timestamp for Now is 1:01 greater than that for Event so the expression will be true.

Does that help?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 93732 on April 23, 2014, 08:04:50 pm
Hi @RexBeckett and @RichardTShaefer,

Yes, that makes sense.  I didn't realize that the statement "Event; Now" means that the Event has to occur before the NOW before either timestamp is compared.

Is there a way with PLEG to check an Event sooner than 1 minute?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: S-F on April 23, 2014, 10:10:15 pm

Is there a way with PLEG to check an Event sooner than 1 minute?

Yeah! Just don't use NOW!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 24, 2014, 01:52:32 am
See Rex's discussions using self started triggers  ... Then you have 1 second resolution.

The strategy:
   1) Create a Timer, Start Type is Self  (Re) Trigger, Stop type is interval with the time you want it to stop. Call the Timer something like: XXX
   2) In the actions for the triggering condition ... start the timer called XXX
   3) Have a condition to catch when the timer expires:
        Timeout       (XXX; !XXX)
        This is true when the Timer transitions from TRUE to FALSE.
   4) Add your actions to the condition named: Timeout.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Fred S on April 24, 2014, 03:01:57 pm
I?ve been going round and round with this and I need to ask the experts. Essentially I want to turn on my front lights but only if two conditions are met 1 my door sensor is triggered and my alarm is disarmed.  My two conditions I have listed are DoorOpen and AlarmDisarmed. I think the issue is that PLEG isn?t taking into account my alarm status and firing off the action regardless. What am I missing?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 24, 2014, 03:55:51 pm
First you need to make sure you have your AlarmOff input working as expected ...
How is determined in your system ? Do you have an attached alarm system ? Is this a Virtual Switch ? ....

The condition you have described is quite simple .. and can be extracted literally from your description ....

YourCondition     DoorOpen and AlarmDisarmed

Please attach a status report so we can see what is happening.
Title: Would Self (Re) Trigger work for my situation?
Post by: 93732 on April 24, 2014, 04:02:36 pm
Hi @RichardTSchaefer and @RexBeckett,

Would the below situation work with a Self (Re) Trigger? If so, could you make me an example?

I have a plugin that sends a "heartbeat" signal to indicate that it has not crashed.  It updates a variable LastUpdate with the current time every 30 seconds.  I want to have an action fire if the variable LastUpdate hasn't been updated after 31 seconds (one second after the expected update).  I have PLEG monitoring the variable LastUpdate using the condition:  Lastupdate;NOW > 31 and it works.  However, I do not want to potentially wait 2 minutes for action to fire.



Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on April 24, 2014, 06:51:23 pm
I think it would be unwise to expect it to be accurate to the second. There are many small delays possible in Vera. I would use a safety factor of at least five seconds. Something along the lines of:

Schedules
WatchDog     OnType: SelfReTrigger  OffType: Interval 35 seconds

Device Properties
LastUpdate   VariableContainer VariableX

Conditions 
Tick     Repeat=Yes  LastUpdate
Alarm  Repeat=No   !WatchDog and (Tick; !WatchDog)

Actions
Tick     PLEG StartTimer timerName=WatchDog
Alarm  As required...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Fred S on April 24, 2014, 07:34:44 pm
Richard,  The AlarmOff input is working but only when I use it as a trigger when the alarm arms and disarms. I know this variable works because i use it in other PLEG programs. I have the Honeywell Ademco Vista Alarm Panels via AD2USB connected to the Vera. The variable AlarmOff equates to "Ademco Vista Partition 1 is DISARMED".  I copied the syntex but it still not working. Essentially when the alarm is disarmed, I want to porch lights to turn on and off depending on whether the door is open or closed however if the alarm is active I want my porch lights to remain on. What is happening is that the door open / closed script is overriding the alarm status/light script. Does that make sense?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 24, 2014, 11:06:07 pm
Quote
Does that make sense?
Partially ... I would really like to see your Status report .... I can probably see exactly what you are doing ...
When you say:
Quote
door open / closed script is overriding the alarm status/light script
Does that mean there are some scenes involved as well ? Or are these other PLEG conditions ?
If they are scenes ... I will likely need to know the details of the scenes as well.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 93732 on April 25, 2014, 12:58:55 am
@RexBeckett, thanks for the logic!!! I had one question,



Actions
Tick     PLEG StartTimer timerName=WatchDog


When I setup this action, I click "Advanced --> PLEG --> Add", it then asks me for timerName but also intervalTime.  Should I leave intervalTime blank?

 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on April 25, 2014, 03:52:09 am
Quote
When I setup this action, I click "Advanced --> PLEG --> Add", it then asks me for timerName but also intervalTime.  Should I leave intervalTime blank?

Yes. Leave it blank. In this application there is no reason to vary the interval time from the 35 seconds in the Schedule definition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: clippermiami on April 25, 2014, 09:33:59 am
I'm trying to sort out a way to do time comparisons in PLEG using data stored in the Variable Container.

I have a PLEG set to control a number of things in the Family Room. Using a Aeon Labs Multi-Sensor I have it configured to prevent the lights from coming on when the ambient light is above a threshold. Similarly I prevent the ceiling fan from coming on if the ambient temperature is below a threshold. These values are stored in a Variable Container and read by the PLEG. This allows me to adjust these values without modifying the PLEG and restarting Vera.

i'd like to come up with a way to do the same thing for a time-of-day window. I currently have a PLEG Schedule item setup to disable the motion sensor controls and timers beginning in the early evening and terminating about midnight. This prevents the lights from going out when people would normally be in the room waching TV, etc. I'd like to store the start and end times in the Variable Container again to make adjustments easily and avoid modifying the PLEG values and restarting Vera.

I've fiddled with some simplistic solutions such as

        Enable_Start_Time :: Variable3
        Enable_End_Time   :: Variable4

        Enable_Schedule_Active :: Enable_Start_Time;NOW;Enable_End_Time

But this doesn't work, probably for a lot of reasons not the least of which is problems with string arithmetic, punctuation marks, etc.. There is also undoubtedly going to be a problem crossing midnight using a "simple" solution. But one never knows, sometimes a simplistic solution does work :)

Any suggestions?



Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Fred S on April 25, 2014, 11:07:18 am
@RichardTSchaefer I'm not sure how to generate the report you are asking for. Is it the one from the Program Logic Event Generator control page?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 25, 2014, 12:32:23 pm
On the Vera Dashboard ...
1) Click the PLEG device.
2) Click the Wrench icon.
3) Then click on the Status button.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Fred S on April 25, 2014, 03:44:22 pm
Sorry Richard, I'm not seeing a status button.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 25, 2014, 05:10:20 pm
Well then you are on an old version ...  This was added in Version 4.4 we are are 6.7
The old versions did not need a license ... the new versions do ... So you may want to stay where you are at.

See:
http://forum.micasaverde.com/index.php/topic,17624.0.html

For a description of the changes/improvements to PLEG.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Fred S on April 27, 2014, 08:10:15 pm
Thanks Richard. The new version of PLEG fixed the issue. :)
Title: Re: PLEG Basics - Setting AC units off if doors left open
Post by: brubalcava on June 18, 2014, 11:37:32 am
Hi,  I'm new and a bit overwhelmed in using PLEG...  I need to set up my Vera so that if someone leaves the deck doors open for over 3 minutes (time could change) AND any of the AC's were on to begin with THEN it shuts off the ACs...

IF they close the doors (say within 30 minutes in case they just wanted to keep the doors open) THEN the ACs go back to what they were BEFORE they triggered the shut down. 

What the normal scenes don't accomplish is that it will turn on the ACs after doors were opened, or it will turn on the ACs after doors are closed without taking into consideration that maybe the AC's weren't on to begin with (so it ends up turning them on when they didn't need to be.   OR that if they open the doors and just want to keep them open for a long time then the ac's should just stay off and they can manually turn them on when they come back in...

I have to believe someone out there has already done this and I don't have to re-invent the wheel?...   Can you guys help me?  I'd love to talk to someone about this..
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 12, 2014, 04:34:39 pm
Hi, I've read the PDF and lot's of forum threads. I have avery simple wish and probalby I am not seeing things clearly anymore.

I want:
To only start a scene (via PLEG actions) when a virtual switch is "ON" and only (somewhere - random) between 22:00 and 22:30 in the evening. But I do not know what to choose in the PLEG.

In "inputs" I choose a "schedule"

But what do I do for "schedule"?? Start Type "unknown" or "interval" Do I need a stop time?

Random on delay? random off delay?

And then... when that scene has started... Nothing else should happen... it should stay that way "forever". At least unitll the "next scene" (another) will take place.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 14, 2014, 02:04:26 pm
Create an input schedule On Mon-sun at 20:00 random on time of 29 minutes off Mon-Sun at 21:31

Call the schedule TimeWindow

Then have an input triggered call Enabled bound to your virtual switch being on.

Then the condition call DoCoolStuff as:


DoCoolStuff     TimeWindow AND Enabled

And of course add all the commands you want to the action called DoCoolStuff.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 15, 2014, 07:47:59 am
Hi Richard,

thanks. See attached my output for the schedule. Is that correct?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 15, 2014, 04:34:15 pm
Richard. Update... the pleg was not triggered at 22.34... so I assume this is not working as wanted. What did I do wrong? I find the "random" in PLEG not very intuitive, are you planning change in the interface? Or again: am I missing something?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tyfoon on July 16, 2014, 03:18:50 am
@sanderl (for some reason presuming you are also Dutch) : best to post a status report in Pdf format (can be generated in via the buttons in the first screen).

This is super useful for debugging.

Verstuurd vanaf mijn Nexus 5 met Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 16, 2014, 09:16:59 am
Attached.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tyfoon on July 17, 2014, 04:03:08 am
@sanderl

The light in your case never turns on. The time window as such will not do any action by itself,  it's only used to evaluate true or false.

i would expect a lights on action when vacation AND timewindow  is TRUE and a lights off action when  this is same condition is FALSE

PS if you want to make the house look like you are on holiday,  check out vacation ghost (search the forum)

Verstuurd vanaf mijn Nexus 5 met Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 17, 2014, 02:17:09 pm
So what did i do wrong and what to change?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tyfoon on July 17, 2014, 03:45:37 pm
@sanderl : not sure what you exactly expect  but as I write in my previous note you need to make sure you have an on action.  So change your current action to a on action that turns the light on,  and add another condition (opposite of the one that triggers on,  so with either Not or! )  that assures the lights go off. 

I'M on a mobile so not easy to give you the EXACT super specific string you need to enter

Pls. Just try and play around,  that is the best way to learn.

Verstuurd vanaf mijn Nexus 5 met Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 17, 2014, 03:58:37 pm
Very simple: I do want a "random" input schedule.  One that is triggering "on" somewhere between 22 and 22.30 and action is carried out. Please see my previous screen shot and text. I can't be more clear.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 17, 2014, 09:39:10 pm
You have a random on time of 29 seconds.

You need to use:   29:00  for a random on time of 29 minutes.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Sender on July 20, 2014, 01:53:33 am
Yes it works! So simple: 29 alone is 29 seconds. 00:29:00 is minutes. Thanks Richard.

Tip: use a "random" tick box in the interface with a start and end time.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tyfoon on July 21, 2014, 04:36:14 am
I want to delay the alarm being set (start detecting) for 60 seconds so I can leave the house or go to sleep.

I have:
Set the trigger (iMSsleep) to check if virtual switch is on

Condition:
sleepalarmon = iMSsleep>60

I would think this would make sleepalarmon TRUE after IMSsleep has been turned on AFTER 60 seconds have passed.

I have already broken up conditions to see where it goes wrong but can't get it working. I have checked with repeat on and off but sleepalarmon does not switch to true.

I have attached report (ignore all the other stuff).

Any suggestions?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 21, 2014, 09:47:59 am
Create a timer similar to Timer30s  call it Timer60s

Then you would have two conditions:

Start60STimer                   iMSsleep
Start60STimerExpired      Timer60S; !Timer60S
    or maybe:
Start60STimerExpired      iMSsleep AND (Timer60S; !Timer60S)

Action for Start60STimer would be to trigger Timer60s
Action for Start60STimerExpired would be actions as desired ... maybe turning off iMSsleep.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: wsyaeger on July 22, 2014, 06:49:04 am
Is this plugin capable of sending a notification if an IP camera connected to a veralite goes offline? If so, could you please assist in some of the setup. Thank you!

Sent from my SAMSUNG-SGH-I747 using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 22, 2014, 07:24:26 am
I do not know of a strategy to detect when the camera goes offline.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: wsyaeger on July 22, 2014, 11:01:00 am
Thank you for your response. Are you are off any method that would send an alert if any device (not limited to a camera) becomes disconnected from Vera?

Sent from my SAMSUNG-SGH-I747 using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garrettwp on July 22, 2014, 12:29:48 pm
No, there is no such mechanism built in. People use the ping sensor for devices on a network.

- Garrett

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: wsyaeger on July 23, 2014, 02:34:51 pm
Thank you for that! Once I can resolve the false alerts, the ping sensor plugin seems to be the solution I was looking for.

Sent from my SAMSUNG-SGH-I747 using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: joelc73 on July 23, 2014, 08:46:44 pm
Guys,  I'm trying to set up the bathroom fan scene in the 'getting started guide' but I can't get it to work.  I'm attaching the status/log in hopes that someone can help.

Thanks in advance!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 24, 2014, 08:09:53 am
Please do not double post.

If this is an example from Rex's documentation ... and it does not work ... it's probably because you do not have INSTANT status reporting Z-wave devices.

To test  ...
1) Start up you Vera Dashboard.
2) Ask someone to turn on a light.   Check your watch.
3) Notice when Vera detects the change ... Check your watch.

If its not within a couple seconds ... then you do not have INSTANT status reporting devices.
In this case you can not create automation scripts that react to your manual activation of the devices.

Title: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: joelc73 on July 25, 2014, 07:09:47 pm
Please do not double post.

If this is an example from Rex's documentation ... and it does not work ... it's probably because you do not have INSTANT status reporting Z-wave devices.

To test  ...
1) Start up you Vera Dashboard.
2) Ask someone to turn on a light.   Check your watch.
3) Notice when Vera detects the change ... Check your watch.

If its not within a couple seconds ... then you do not have INSTANT status reporting devices.
In this case you can not create automation scripts that react to your manual activation of the devices.

I just tried and it does show up instantly on my Dashboard -- so I don't think it's the device.  Could it have something to do with the code itself?

These are Jasco switches. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garrettwp on July 26, 2014, 04:31:29 pm
These so not support instant status! You will bet random results as the status will not always update instantly.

- Garrett

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: mrhex on August 01, 2014, 07:06:44 pm
I am trying to experiment and learn to use PLEG, so I setup the simple alarm as posted in the PLEG BASICS page 19, with the exceptions. I use virtual switches to test it.

However i get a error message:

Alarm system[51] : Alarm eq ?Tripped? and (Alarm$Tripped; !Timer30S): Invalid Value token: ?TRIPPED?

What could possibly be the problem? to me the syntax appears to be fine. And the state variable "Alarm" has the "Idle" value.
I attached status of that PLEG as a attachment, what do you think?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 01, 2014, 07:35:17 pm
You syntax looks OK to me, @mrhex. I don't see why you are getting an error flagged. Try using single quotes for the string compare to see if that helps. E.G. Alarm eq 'Tripped' and (Alarm$Tripped; !Timer30S)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: mrhex on August 01, 2014, 07:43:42 pm
You syntax looks OK to me, @mrhex. I don't see why you are getting an error flagged. Try using single quotes for the string compare to see if that helps. E.G. Alarm eq 'Tripped' and (Alarm$Tripped; !Timer30S)

That solved it! Thanks a bunch!
I use beta fw 1.5.672 to get the fibaro sensors working and Pleg 6.9
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: johnes on August 12, 2014, 06:05:07 pm
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.

Once this is locked on, how do you get it to start detecting motion (either to turn it off etc).  Or would this require a manual off? 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 12, 2014, 06:52:17 pm
Quote
Once this is locked on, how do you get it to start detecting motion (either to turn it off etc).  Or would this require a manual off?

Yes. If you lock it on, you have to turn it off to resume automatic operation.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 16, 2014, 07:28:05 pm
Hi all,

I have a PLEG set up to turn off our living room lights when both of our electric blankets are turned off in the bedroom, as this means we're in bed.  (Later on when the house is kitted out with more devices this can be done properly, but I only have a few devices to work with at the moment).

I've been noticing the lights turning off occasionally while we're in watching TV, and just realised last night that this could be because our electric blankets are scheduled to turn on at 7:30pm, and as the living room lights turn on at "Night" (5:30pm ish), there's a couple of hours there where the scenes overlap.  Though I understand that something has to trigger to cause an evaluation, so I'm not sure what that is right now, but next time it happens I'll check the logs to find out for sure (http://192.168.1.xx/cgi-bin/cmh/log.sh?Device=LuaUPnP)   

So basically what I want to do (unless there's a better way) is to tell PLEG to only turn off the lights if both blankets are turned off and the time is later than 7:30pm.     I understand I can use something like "Now > 7:30", but it seems the use of NOW causes evaluations every minute which I'd rather avoid if there's a better way.    I could have a virtual switch that trips when 7:30 comes around, and then check with the status of the switch, but that means adding another device.   Basically I'm just curious of the most efficient way to handle this so that I learn things the correct way going forward ;)

Thanks everyone!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 16, 2014, 08:23:34 pm
I would use a Sequence expression so that your lights-off Condition only fires when the blankets turn off after the living room lights are turned on. Something like this:

DoLightsOff  LivRoomLights and !Blankets and (LivRoomLights; !Blankets)

This will fire when the Living room lights are on, the blankets are off and the blankets turned off after the lights turned on.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 16, 2014, 10:14:44 pm
I would use a Sequence expression so that your lights-off Condition only fires when the blankets turn off after the living room lights are turned on. Something like this:

DoLightsOff  LivRoomLights and !Blankets and (LivRoomLights; !Blankets)

This will fire when the Living room lights are on, the blankets are off and the blankets turned off after the lights turned on.

Interesting, that looks to be just what I need.  I haven't played with sequence expressions yet, and I'm just about to head out to a wedding (I'd much rather be sat working this out to be honest :D), so that's a job for tomorrow.

Thanks a lot for your help by the way Rex, you do a great job here.  Karma up :)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 17, 2014, 12:46:46 am
Ok, back for an hour or so before the reception ;)

How does the attached look?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 17, 2014, 02:25:36 am
Ok, back for an hour or so before the reception ;)

How does the attached look?

That looks pretty good but you should add a Stop to your TwoAM Schedule otherwise once it turns true it will stay there. Just set it to Interval and 1:00 (one minute).
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 17, 2014, 02:31:19 am
Ok, back for an hour or so before the reception ;)

How does the attached look?

That looks pretty good but you should add a Stop to your TwoAM Schedule otherwise once it turns true it will stay there. Just set it to Interval and 1:00 (one minute).

Sweet, I'll do that.   So any schedule should have some sort of stop added (that makes sense :D).  I just wasn't sure if, because it's set to run daily, it'd reset at some point.  But then I suppose it wouldn't know how or when to reset ;)

Excellent, thanks again for the help.  I'll be back with more questions no doubt, but I'm slowly learning the power of PLEG piece by piece :).   I'll be buying a license soon even though I don't really need to (Richard's earned it I think).
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 18, 2014, 06:20:53 am
Right, I'm back ;)

I have another scene that turns on the living room lights at Night and when a Video starts playing.    I also added something to still turn on the lights if Night ticks over and a video is currently playing (rather than having to wait for a new one to start).  This works, but it's not ideal as the XBMC_State plugin doesn't actually have a variable for currently playing, so I had to use NOT STOPPED (but this encompasses a bunch of other states that I don't really want included.  I could explicitly filter them all out, but that's messy).

So, after more reading I thought I could use the # tag to get the timestamp of when Night hits, and the timestamp of when a video last started.   What I'd like to do is say something like, if Night hits, but a video started playing within the last hour, then go ahead and turn on the lights (as that means someone is most likely present).

I've been testing it but can't quite get the syntax.  I initially just did #VideoStart < #Night, which technically works, but is no good as it'll grab the timestamp of whenever a video was last started, no matter when.

So I'm currently at the following:

Night AND (#VideoStart == #Night - 300)  (5 minutes for testing).

This doesn't appear to be the correct syntax (not sure if it doesn't want seconds, or it's not possible to subtract seconds from a timestamp.  Perhaps it's not a number?)

Anyway, any help appreciated as always!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 18, 2014, 06:29:53 am
You should be able to do this with a simple Sequence Expression:

     Night AND (VideoStart; Night < 1:00:00)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 18, 2014, 06:31:18 am
You should be able to do this with a simple Sequence Expression:

     Night AND (VideoStart; Night < 1:00:00)

Dammit, I'm always overcomplicating things!

Thanks Rex ;)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 18, 2014, 01:57:47 pm
Your syntax working with time stamps is correct but it's meaningless.

Nothing evaluates the condition at the exact second that the condition expression would be true.

Conditions only are evaluated when inputs change ... Or you use the special NOW keyword which is just a one minute interval timer.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: simonk83 on August 18, 2014, 07:06:32 pm
Your syntax working with time stamps is correct but it's meaningless.

Nothing evaluates the condition at the exact second that the condition expression would be true.

Conditions only are evaluated when inputs change ... Or you use the special NOW keyword which is just a one minute interval timer.

Hi Richard,

I think a lot of my issues come from dealing with VBA and SQL all day for work, so I tend to think in those terms :)    I think, at the time, I was assuming that the first condition (Night) would trigger and cause the timestamps calculation to be evaluated.    I need to get out of that frame of mind, but I'll make plenty more mistakes in the meantime I'm sure.

Do you have a working example of using the # operator?  I tend to find it easier if I can see how it's supposed to flow and dissect it from there.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 19, 2014, 11:19:07 am
I'm having an issue with my fan logic (mostly pulled from PLEG basics) not working and I can figure out the issue after a month.   Instead of the Light On, I use the Door Closed for the shower/toilet stall to turn on the fan.

MBA_Fan$Off
MBA_FanOn and !MBA_Timer and ((MBA_Fan eq '5Min' and MBA_Door_Open and (MBA_Fan$5Min; !MBA_Timer)) or (MBA_Fan eq '10Min' and (MBA_Fan$10Min; !MBA_Timer)) or (MBA_Fan eq '20Min' and (MBA_Fan$20Min; !MBA_Timer)))

MBA_Fan$5Min
!MBA_FanOn and !MBA_Door_Open and (!MBA_FanOn;!MBA_Door_Open)

MBA_Fan$10Min   
MBA_Fan$5Min and !MBA_Timer and (MBA_Fan$5Min; !MBA_Timer)

MBA_Fan$20Min
(MBA_FanOn eq '5Min' and !MBA_Timer and !MBA_Door_Open and (MBA_Fan$10Min; !MBA_Timer)) or (MBA_FanOn and (MBA_Fan eq 'Off') and (MBA_Fan$Off; MBA_FanOn))

MBA_Timer   Self ReTrigger         None   Interval   05:00
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 19, 2014, 12:54:14 pm
Quote
I'm having an issue with my fan logic (mostly pulled from PLEG basics) not working and I can figure out the issue after a month. 

Did you mean that you cannot figure out the issue? What are the symptoms? How did you want t to work?


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 19, 2014, 01:33:15 pm
Sorry, it cannot figure it out.  I've been trying a to simplify my 'current code' as I'm having troubles with the getting the 10Min state to fire...and really don't understand how the sample code increments the timer.

End Goal (based on door closed and open)::
* Turn On Fan when Shower/Commode Door Closed.  If door closed for less than 5 mints, Run fan for 2 mins after door opens.
* If Door is closed for more than 5 mins, run fan for 10 mins after door opens.
* If Door is closed for more than 10 mins, run fan for 20 mins after door opens
* Manually turning the fan on will turn it off after 20 mins.

Current Code (based on door closed only):
* Turn On Fan when Shower/Commode Door Closed. Run fan for 5 minutes
* If Door is closed for more than 5 mins, extend Fan timer to 10 mins.
* If Door is closed for more than 10 mins, extend Fan timer to 20 mins.
* Manually turning the fan on will turn it off after 20 mins.


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 19, 2014, 02:02:20 pm
It sounds as though you really want to start the timer when the door is opened not when it is closed. So start the fan when the door is closed and start your timer when it is opened. You can decide how long to run it for based on how long the door was closed. Something like this (not tested):

Conditions
Do_MBA_Fan_On     !MBA_Door_Open and !MBA_Fan_On and (!MBA_Fan_On; !MBA_Door_Open)
Do_MBA_Fan_2m     MBA_Door_Open and (!MBA_Door_Open; MBA_Door_Open  < 5:00)
Do_MBA_Fan_10m   MBA_Door_Open and (!MBA_Door_Open; MBA_Door_Open  >= 5:00 < 10:00)
Do_MBA_Fan_20m   (MBA_Door_Open and (!MBA_Door_Open; MBA_Door_Open  >= 10:00)) or (MBA_Fan_On and (MBA_Door_Open; MBA_Fan_On))
Do_MBA_Fan_Off     MBA_Fan_On and !MBA_Timer and (MBA_Fan_On; !MBA_Timer)

The Actions for Do_MBA_Fan_Xm should start MBA_Timer for the appropriate time (X).
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 19, 2014, 02:15:52 pm
Would this replace the state based logic or append to it?  It sounds like your method replaces and is simpler logic.

I thought I had to use state logic with increment timers. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 19, 2014, 03:54:10 pm
Quote
Would this replace the state based logic or append to it?  It sounds like your method replaces and is simpler logic.

It would replace it.

Quote
I thought I had to use state logic with increment timers.

There are not too many have-tos in the PLEG world; There is usually more than one way to skin a cat. PLEG's State Variables are very useful for some applications but I don't see your scenario as state-based - it's just one timer with a select-able interval.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 19, 2014, 10:15:47 pm
Thanks Rex, that logic worked well.  Will let you know how it tests out.

PS - The only change needed was I couldn't use the >= and resorted to a >...otherwise I got an error.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 20, 2014, 03:28:47 am
Thanks Rex, that logic worked well.  Will let you know how it tests out.

PS - The only change needed was I couldn't use the >= and resorted to a >...otherwise I got an error.

Strange. A >= (greater than or equal to) comparison should be fine. Be aware that if you have just used > you have some tiny holes in your logic. If the door was closed for exactly five minutes, the fan timer would not be started.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 20, 2014, 11:13:58 pm
Understood, I tried re-adding and got the same error.  Maybe PLEG doesn't only supports > or < when doing multiple time sequences as it works everywhere else.  Not a huge deal for now.

I do have one other question that has alluded me if you have some time.  I have my lights turn on primarily by motion as shown in the condition below:

UBR_Night_On:      UBR_Motion and Night

It will turn a light on, picture frame, tv, etc...more than just a light. I've figure out to pick up a manual light awitch off using this to fire the Off condition via motion (typical) or manually (rare)

UBR_Night_Off:  !UBR_Motion or (UBR_Light_Off and UBR_Motion)

The problem is when you manually turn the light on again, I can't figure out a logic that doesn't duplicate UBR_Night_On condition (having it fire twice or looping).  I thought the following would work but does NOT:

UBR_Night_On:      (UBR_Motion and Night) or (!UBR_Light_Off and UBR_Motion)

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on August 21, 2014, 02:40:19 am
Quote
The problem is when you manually turn the light on again, I can't figure out a logic that doesn't duplicate UBR_Night_On condition (having it fire twice or looping).

I don't understand the problem but there's a good chance you can fix it by including a Sequence Expression to constrain the order of the events. E.g. (UBR_LightOff; UBR_Motion) in the on Condition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AgileHumor on August 21, 2014, 02:26:37 pm
Thanks Rex, my motion goes to !motion after 20 minutes in the UBR office.   So while I can chain my devices to turn of with Motion OR Light_Off...I couldn't figure out a way to turn the lights and associated devices in the scene,  back on if motion was still true (without leaving the room for 20 minutes).

I finally got this to work by adding the sequence as you suggested :)
(UBR_Motion and UBR_Light_Off and Day and not (UBR_Motion;!UBR_Light_Off)) or (UBR_Motion and !UBR_Light_Off and Day and (UBR_Motion;!UBR_Light_Off))

Thanks much!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: thewizardofoz on September 03, 2014, 10:53:50 am
Guys,
I am having some trouble with PLEG.   I travel for work, but not always.  I have a home office.   I want setup PLEG to set my thermostat to a temperature depending on if I am at home or not.  I want to use the Ademco plug-in to determine if I am at home or not.   I have it set up to where it will lower the A/C if I am home, but the condition stays true.  I want to be able to set the alarm if I leave for lunch with my wife and not have the temperature go back, since I will be home shortly.

If at 08:05 the alarm is not set, then set A/C to 73.   If at 08:05 the alarm is set, then set A/C to 73 or it can do nothing since my Honeywell schedule is set to change A/C to 77 at 08:00

My times might be wrong in the screen shot due to testing.

What am I doing wrong?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: thewizardofoz on September 03, 2014, 12:17:30 pm
Nevermind   I got it.   I wasn't waiting for the Stop Time
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 13, 2014, 10:07:38 pm
I am still a beginner and that document really helped me understand the examples better and some of the other people's ways they are using PLEG.

I am using PLEG now to control my heating schedules and lighting along with a few other things.

I have a condition in PLEG named C_PorchLightOn:

IsNight AND PorchLightOn AND HomeAwayVSwitch AND 22:00:00

I want the condition to be true when IsNight, PorchLightOn and HomeAwayVSwitch are true and it is 10PM.

Is this the correct format or should I be evaluating it against NOW  (NOW >  22:00:00)

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 14, 2014, 06:38:55 pm
If you want the light to come on we a specific time create a timer called TenPM and have it trigger at 10 pm on the days you want.

Also have the timer turn off again in a few minutes.
Then put AND TenPM into your condition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 14, 2014, 08:26:35 pm
Thanks Richard
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on October 19, 2014, 12:59:32 pm
@RexBeckett,

On page 13 of 22 of PLEG Basics for Multiple Trigger Expressions, you state:

SoundSiren MotionDetector @ 3 < 5:00
SoundSiren will become true if MotionDetector becomes true three times in a five minute period.


Assuming SoundSiren becomes true, when does SoundSiren subsequently become false?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 19, 2014, 09:35:45 pm
I am using PLEG to control the heat in my house but is seems that it isn't working.

Triggers

Name   Description   State   Last True   Last False
Away   Home Away Switch is turned on   false   2014-10-11 20:26:06.378   2014-10-11 20:28:15.178

Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On   Last Off
WDMHOFF   Weekly   07:30:00   1,2,3,4,5   None   None         None   false   2014-10-17 07:30:00.103   0
WDMHON   Weekly   06:00:00   1,2,3,4,5   None   None         None   false   2014-10-17 06:00:00.100   0
WDNHOFF   Weekly   21:30:00   1,2,3,4,5   None   None         None   false   2014-10-17 21:30:00.102   0
WDNHON   Weekly   16:30:00   1,2,3,4,5   None   None         None   false   2014-10-17 16:30:00.103   0
WEHOFF   Weekly   21:00:00   6,7   None   None         None   false   2014-10-19 21:00:00.109   0
WEHON   Weekly   07:00:00   6,7   None   None         None   false   2014-10-19 11:46:18.077   0

Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
Return   GCal3 Sensor   gc_TrippedEvent      2014-10-11 20:30:00.805   2014-10-11 20:28:15.101

Conditions

Name   Repeat   Expression   State   Last True   Last False
C_WDMHON   No   WDMHON AND (Away == 0)   true   2014-10-13 06:00:00.114   0
C_WDNHON   No   WDNHON AND (Away == 0)   true   2014-10-13 16:30:00.108   0
C_WEHON   No   WEHON AND (Away == 0)   true   2014-10-12 07:00:00.118   0
C_WDMHOFF   No   WDMHOFF AND (Away == 0)   true   2014-10-13 07:30:00.124   0
C_WDNHOFF   No   WDNHOFF AND (Away == 0)   true   2014-10-13 21:30:00.113   0
C_WEHOFF   No   WEHOFF AND (Away == 0)   true   2014-10-11 21:00:00.137   0
C_Away   No   Away   false   2014-10-11 20:26:06.401   2014-10-11 20:28:15.198
C_Return   No   Return      2014-10-11 20:30:00.817   2014-10-11 20:28:15.129

Actions

Actions for Condition: C_Away

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=50
Actions for Condition: C_Return

Device Actions:

Immediate

Device   Action   Arguments
Home Away Switch   SetTarget   newTargetValue=0
Actions for Condition: C_WDMHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=62
Actions for Condition: C_WDMHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=66
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Actions for Condition: C_WDNHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=64
Actions for Condition: C_WDNHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=66
Actions for Condition: C_WEHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=64
Actions for Condition: C_WEHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=68

I have virtual switch called Away so that when I go away the heat gets set to 50 degrees.

Do I need to have an off time for my Schedules? When I look at the Status, all of my schedules are true.

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on October 20, 2014, 08:08:11 am
@RexBeckett,

On page 13 of 22 of PLEG Basics for Multiple Trigger Expressions, you state:

SoundSiren MotionDetector @ 3 < 5:00
SoundSiren will become true if MotionDetector becomes true three times in a five minute period.


Assuming SoundSiren becomes true, when does SoundSiren subsequently become false?

SoundSiren will become false when MotionDetector becomes true and has not done so two more times in the last five minutes.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on October 20, 2014, 08:16:55 am
Quote
Do I need to have an off time for my Schedules? When I look at the Status, all of my schedules are true.

If a Schedule does not have an Off time, it will not return to false. You can use Schedules this way but you would need to set the Repeats flag on for any Condition that uses them otherwise it will not trigger its Action when the On time occurs (because it was already true so is not seen to have changed).

It is usually easier to set an Off time for all Schedules. Either combine your ON and OFF Schedules into one or give the existing single-event ones an OffType of Interval for a few seconds.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 20, 2014, 09:11:58 am
Hi RexBeckett,

Thanks for the response. I have added a 10 second off time interval for all of the schedules. Hopefully when I come home from work tonight the house is warm.

Originally, I wanted to do a single schedule with on/off times but I wasn't sure how to get the thermostat to turn back down when the schedule was off so I did it this way.

Other than less schedules, is there any advantage to having schedules with on/off times as opposed to having a schedule for each?

Regards,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on October 21, 2014, 05:35:36 am
Quote
Originally, I wanted to do a single schedule with on/off times but I wasn't sure how to get the thermostat to turn back down when the schedule was off so I did it this way.

You can just use the negated term in your off Conditions:

WEH   Weekly   07:00:00   6,7   None   Weekly   21:00:00   6,7   None

C_WEHON   No   WEH AND (Away == 0)
C_WEHOFF   No   !WEH AND (Away == 0)

Quote
Other than less schedules, is there any advantage to having schedules with on/off times as opposed to having a schedule for each?

There can be an advantage depending on how you want the logic to work when you turn Away on and off. In the example above, if Away is turned off during the valid heating period, the heating will turn on. If you use individual Schedules with short on intervals, this will not happen.
 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on October 21, 2014, 06:08:35 am
Thanks Rex.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 21, 2014, 12:59:54 pm
RexBeckett,

Thanks I will try that. I do want the heat to be set for 50 degrees when the Away virtual switch is On.

Regards,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 22, 2014, 08:41:44 am
Hi RexBeckett,

I made the suggested changes last night and so far everything works. Thanks for the help.

Regards,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 25, 2014, 09:00:25 am
Hi RexBeckett,

All of the weekday heating schedules are working correctly but this morning when I got up, the heat did not trigger even though the schedule (WEH) and condition (C_WEHON) are both true.

Triggers

Name   Description   State   Last True   Last False
Away   Home Away Switch is turned on   false   2014-10-11 20:26:06.378   2014-10-11 20:28:15.178
Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On   Last Off
WDMH   Weekly   06:00:00   1,2,3,4,5   None   Weekly   07:30:00   1,2,3,4,5   None   false   2014-10-24 06:00:00.100   2014-10-24 07:30:00.102
WDNH   Weekly   16:30:00   1,2,3,4,5   None   Weekly   21:30:00   1,2,3,4,5   None   false   2014-10-24 16:30:00.101   2014-10-24 21:30:00.103
WEH   Weekly   07:00:00   6,7   None   Weekly   21:00:00   6,7   None   true   2014-10-25 07:00:00.100   0
Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
Return   GCal3 Sensor   gc_TrippedEvent      2014-10-11 20:30:00.805   2014-10-11 20:28:15.101
Conditions

Name   Repeat   Expression   State   Last True   Last False
C_WDMHON   No   WDMH AND (Away ==0)   false   2014-10-24 06:00:00.104   2014-10-24 07:30:00.105
C_WDNHON   No   WDNH AND (Away ==0)   false   2014-10-24 16:30:00.108   2014-10-24 21:30:00.107
C_WEHON   No   WEH AND (Away ==0)   true   2014-10-12 07:00:00.118   0
C_WDMHOFF   No   !WDMH AND (Away ==0)   true   2014-10-24 07:30:00.111   2014-10-24 06:00:00.114
C_WDNHOFF   No   !WDNH AND (Away ==0)   true   2014-10-24 21:30:00.113   2014-10-24 16:30:00.118
C_WEHOFF   No   !WEH AND (Away ==0)   false   2014-10-11 21:00:00.137   2014-10-25 07:00:00.115
C_Away   No   Away   false   2014-10-11 20:26:06.401   2014-10-11 20:28:15.198
C_Return   No   Return      2014-10-11 20:30:00.817   2014-10-11 20:28:15.129
Actions

Actions for Condition: C_Away

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=50
Actions for Condition: C_Return

Device Actions:

Immediate

Device   Action   Arguments
Home Away Switch   SetTarget   newTargetValue=0
Actions for Condition: C_WDMHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=62
Actions for Condition: C_WDMHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=66
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Actions for Condition: C_WDNHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=64
Actions for Condition: C_WDNHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=66
Actions for Condition: C_WEHOFF

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=64
Actions for Condition: C_WEHON

Device Actions:

Immediate

Device   Action   Arguments
Trane Thermostat   SetModeTarget   NewModeTarget=HeatOn
Trane Thermostat   SetCurrentSetpoint   NewCurrentSetpoint=68

Do you see any reason for this not working? What should be the next step to trouble shoot this issue?

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 25, 2014, 04:11:18 pm
It will work tomorrow magically!

Actually it's just an initialization problem.
The problem is the condition was already true when the schedule ran this morning at 7:00

It will go off tonight at 21:00 so when it triggers tomorrow at 7:00 it should work.

You could have also set the repeats checkbox.
Then it would have run the actions even though the condition was already true.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 25, 2014, 06:55:20 pm
Hi RichardTSchaefer,

Thanks for the explanation.

Regards,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on October 27, 2014, 10:43:12 am
Hi RichardTSchaefer,

As predicted, magically it worked. :)

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: East on November 10, 2014, 06:18:35 pm
I need some help programming this:

Relevant setup:
Philips Hue light
Vera with UI5
e-thermostaat plug-in
Philips Hue Plug-in
PLEG plug-in
Sleepcycle App on iphone

Trying to attempt:
Sleepcycle monitors my sleep and wakes me based on my sleeping fase within a given timeframe. It does that by fading in my philips hue lights and then wakes me with some sounds. I want to use  the Philips Hue lights as trigger for PLEG and combined with a preset timeframe for the weekday's, I want it to set my thermostat (e-thermostaat) to a preset to heat up my apartment.

I'm testing this now, and it seems only to work when the philips hue light is turned on using Vera, the trigger is not activated when the philips hue light is turned on using the direct interface although the light status is updated in the Vera interface.

Is it possible to have the trigger set on "Hue_On lightlevel >0". Only option available now is "device is turned on" - see attached image. And wil this solve this problem?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on November 11, 2014, 03:22:17 am
Quote
Is it possible to have the trigger set on "Hue_On lightlevel >0". Only option available now is "device is turned on" - see attached image. And wil this solve this problem?

You could set a Device Property to the lamp's LoadLevelStatus and then compare that to some level in your Condition. I don't know whether this will solve the problem but it is worth a try.

Device Properties
HueLevel     Bedroom Hue, LoadLevelStatus

Conditions
HueOn        HueLevel > 0
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: East on November 12, 2014, 10:07:55 am
Quote
Is it possible to have the trigger set on "Hue_On lightlevel >0". Only option available now is "device is turned on" - see attached image. And wil this solve this problem?

You could set a Device Property to the lamp's LoadLevelStatus and then compare that to some level in your Condition. I don't know whether this will solve the problem but it is worth a try.

Device Properties
HueLevel     Bedroom Hue, LoadLevelStatus

Conditions
HueOn        HueLevel > 0

Thank you so much. It's working! :)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: skogen75 on November 27, 2014, 12:28:29 pm
Can someone give me a quick reminder on absolute time in a sequence expression?  I read that in a sequence expression, times HH:MM:SS on the left side will be absolute time on the current day, but HH:MM:SS on the right side will be relative time.  What is the time relative to?  I would like to use a sequence expression to turn lights on as follows:

DayHasArrived;!DayHasArrived;06:15:00

Where 06:15:00 is the absolute time on the current day.  My expression does not work, is it due the the 'relative time' on the right of the expression, it should work if the time on right was absolute on the current day, correct?

Thanks.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: skogen75 on November 27, 2014, 01:50:21 pm
okay so I think I have an idea why this doesn't work.  The expression is only evaluated on a DayHasArrived or !DayHasArrived time stamp and not at 06:15:00. 

That is, a sequence expression is not evaluated at a specified absolute time but only when a time stamp from a trigger changes; is this correct?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on November 27, 2014, 05:37:20 pm
Can someone give me a quick reminder on absolute time in a sequence expression?  I read that in a sequence expression, times HH:MM:SS on the left side will be absolute time on the current day, but HH:MM:SS on the right side will be relative time.  What is the time relative to?  I would like to use a sequence expression to turn lights on as follows:

DayHasArrived;!DayHasArrived;06:15:00

Where 06:15:00 is the absolute time on the current day.  My expression does not work, is it due the the 'relative time' on the right of the expression, it should work if the time on right was absolute on the current day, correct?

Thanks.

When used as you have shown, the time would be an absolute value (relative to 00:00 the same day). The time is relative when it is used with a comparison operator (> <).

What do you want to achieve with this expression?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: skogen75 on November 27, 2014, 07:31:29 pm
I would like the lights to come on at 06:15:00 if 06:15:00 is before sunrise. 

What I would really like to know is the following:

In an expression such as DayHasArrived;!DayHasArrived;06:15:00

The expression is only evaluated when the time stamp of DayHasArrived turns 'true' and when it turns 'false' and not when 06:15:00 occurs. Is this a correct statement?

Anyway, I think that if I set a schedule for 06:15:00 everyday and modify my expression to:

DayHasArrived;!DayHasArrived;sSixFifteenAM

Where, sSixFifteenAM is a schedule that triggers everyday at 06:15:00 and turns off 5 minutes later.

This will fire at 06:15:00 every morning, if 06:15:00 is before sunrise.   

Thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on November 28, 2014, 12:00:22 am
Quote
Anyway, I think that if I set a schedule for 06:15:00 everyday and modify my expression to:

DayHasArrived;!DayHasArrived;sSixFifteenAM

Where, sSixFifteenAM is a schedule that triggers everyday at 06:15:00 and turns off 5 minutes later.

This will fire at 06:15:00 every morning, if 06:15:00 is before sunrise.   

Yes - that should work.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 28, 2014, 07:27:45 am
Quote
DayHasArrived;!DayHasArrived;sSixFifteenAM

That is pretty obscure logic. Because  DayHasArrived and !DayHasArrived are compliments of each other:

!DayHasArrived     =        DayHasArrived;!DayHasArrived

So the logic could just be:
             !DayHasArrived and  sSixFifteenAM

Which is a lot easier to read and understand.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: skogen75 on November 28, 2014, 09:48:37 am
Quote
DayHasArrived;!DayHasArrived;sSixFifteenAM

That is pretty obscure logic. Because  DayHasArrived and !DayHasArrived are compliments of each other:

!DayHasArrived     =        DayHasArrived;!DayHasArrived

So the logic could just be:
             !DayHasArrived and  sSixFifteenAM

Which is a lot easier to read and understand.

True, very true.  I may switch it to that. 

Sequence expressions are cool, though and this exercise has helped me understand them a bit better.

Richard-Can you verify that the sequence expressions are only evaluated on a trigger/schedule time-stamp change and not when an absolute time in a sequence expressions has been reached, such as in the original sequence:

DayHasArrived;!DayHasArrived;06:15:00 (PLEG will only check the expression when DayHasArrived or !DayHasArrived change their time-stamp and will not be evaluated at 06:15:00, correct? )
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 28, 2014, 09:55:57 am
Your analysis is right ...
There is nothing that cause the condition to be evaluated at 6:15.
Conditions ONLY get evaluated when INPUTS or  cascaded conditions (Conditions who were updated by an input) change.

The only exception is NOW ... it is equivalent to a 1 minute interval timer.
 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on December 04, 2014, 01:27:55 pm
So I am back at the well to drink some more knowledge. Since the days are now shorter when I get up in the morning I would like the living room light to turn on after the bedroom light has been turned off but only when it is still considered night. I have been playing with this for the last few weeks and I am not sure what I am doing wrong. I have an idea but not sure how to correct. What is happening now, is the LR light will turn on in the morning if I sleep in and the bedroom light was not turned on. I think what I need is the trigger needs to see the change from the bedroom light from on to off and not just see that it is off (which is how I think I have it set now).

Triggers

Name   Description
Antonio_Away   Ping Sensor is Tripped
Antonio_Home   Ping Sensor is not Tripped
HomeAwayVSwitch   Home Away Switch is turned on
IsDay   Day or Night indicates Day time.
IsNight   Day or Night indicates Night time.
LightisOff   Living Room Dimmer is turned off
LightisOn   Living Room Dimmer is turned on
LRDoorIsOpen   Dining Room French Door Sensor armed is tripped
MBRLightOff   Master Bedroom Dimmer is turned off
PorchLightOn   Front Porch Lights is turned on

Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay
MBRLightOff1   Weekly   06:45:00   1,2,3,4,5,6,7   None   Weekly   07:30:00   1,2,3,4,5,6,7   None
MBRtimes   Weekly   21:00:00   1,2,3,4,5,6,7   None   Weekly   03:00:00   1,2,3,4,5,6,7   None
TenPM   Weekly   22:00:00   1,2,3,4,5,6,7   None   Interval   00:30:00      None
WorkDayMBRLightOn   Weekly   06:20:00   1,2,3,4,5   None   Interval   01:00:00      None

Device Properties

Name   Device Name   Device Variable
AntonioPingStat   Ping Sensor   Tripped
Away   Home Away Switch   Status
GCalendar   GCal3 Sensor   Tripped
LRDimmerStat   Living Room Dimmer   Status

Conditions

Name   Repeat   Expression
TurnOnMBRLight   No   MBRtimes AND LightisOff AND (MBRtimes; LightisOff)
Arm_House   No   Antonio_Away
OutsideLightsOn   No   (IsNight == 1) AND (LightisOff == 1) AND (LightisOff;IsNight)
Disarm_House   No   Antonio_Home
BYPASS   No   HomeAwayVSwitch
ARM   No   NOT HomeAwayVSwitch
MorningAlarm   No   IsNight AND WorkDayMBRLightOn AND (GCalendar ==0) AND (IsNight; WorkDayMBRLightOn)
CameraPosition3   No   LRDoorIsOpen
C_PorchLightOn   No   IsNight AND PorchLightOn AND HomeAwayVSwitch AND TenPM
C_LRLightOn   No   IsNight AND (MBRLightOff == 1) AND MBRLightOff1 AND (IsNight;MBRLightOff;MBRLightOff1)

Actions

Actions for Condition: Arm_House

Device Actions:

Immediate

Device   Action   Arguments
VistaCam PT Motion Sensor   SetArmed   newArmedValue=1
Actions for Condition: C_LRLightOn

Device Actions:

Immediate

Device   Action   Arguments
Living Room Dimmer   SetLoadLevelTarget   newLoadlevelTarget=100
Actions for Condition: Disarm_House

Device Actions:

Immediate

Device   Action   Arguments
VistaCam PT Motion Sensor   SetArmed   newArmedValue=0
Actions for Condition: MorningAlarm

Device Actions:

Immediate

Device   Action   Arguments
Master Bedroom Dimmer   SetLoadLevelTarget   newLoadlevelTarget=90
Actions for Condition: OutsideLightsOn

Device Actions:

Immediate

Device   Action   Arguments
Front Porch Lights   SetTarget   newTargetValue=1
Actions for Condition: TurnOnMBRLight

Device Actions:

Immediate

Device   Action   Arguments
Master Bedroom Dimmer   SetLoadLevelTarget   newLoadlevelTarget=90

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on December 04, 2014, 03:21:18 pm
A couple of things (#1 and #2 ease readability)
1)   When you have a trigger XXX
       You can replace your use of
               (XXX == "1")   
       with just
                XXX
2)    I would also recommend that you replace
                 (XXX == "0")
        with   
                  (NOT XXX) 
        or:
                 NOT XXX
        or:
                 !XXX

3) Change to:

C_LRLightOn      IsNight AND MBRLightOff AND MBRLightOff1 AND (IsNight;MBRLightOff)
4) In the future Please post your logic as an attachment (i.e. the status report as PDF)
      Then one can have your logic in one window and your description in another ... its easier than scrolling back and forth.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on December 04, 2014, 07:49:18 pm
Richard,

Thanks for the suggestions to clean up my PLEG statements. I will try the change to my condition to see how that works.

Would you mind explaining why the way I made the condition didn't work and why your suggestion will so I can understand for future reference.

And thanks for the tips to posting my logic. I will do that the next time.

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on December 04, 2014, 09:16:22 pm
A Sequence expression  (using a semicolon) is true when ALL of the listed inputs or conditions are in the specified order.

In your case:
    (IsNight;MBRLightOff;MBRLightOff1)

The order of the events for this to be true would be:
      IsNight   then MBRLightOff    then MRRLightOf1
And the last token is only true at 7:30

That did not sound like what you wanted ... so I just dropped it.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on December 05, 2014, 09:16:27 am
Hi Richard,

Thank you for the response. I made the suggested changes last night but I think I screwed something up as my MBR Light didn't come on this morning (It is my second alarm as I am not a morning person) but I will review what I did there later tonight when I get home.

I was thinking about the part that you suggested to remove from my condition, and I actually do want something in there to limit the times when the Living Room lights are turned on. As an example, if I get up in the middle of the night for what every reason and I turn on the bedroom light and then turn it back off, I don't want the living room light to turn on.

How do I look for a change in state when the light has to be on during the times indicated and then turned off to trigger the LR Lights to come on only during that time interval (Between 6:45-7:30)?

Would switching the order to IsNight then MBRLightOff1 then MBRLightOff. I assume it would look at the conditions so if it is Night and it is between 6:45 and 7:30 and then the MBR Light was off were all true it would work? If so, I am still hung up on if the MBR light was never turned on, then the Living room light would still go on.

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on December 09, 2014, 02:48:08 pm
Hi Richard,

I was making changes again to try to fix my MorningAlarm. You suggested removing "==0" with either NOT or !. I changed my original condition from:

IsNight AND WorkDayMBRLightOn AND (GCalendar ==0) AND (IsNight; WorkDayMBRLightOn) to:

IsNight AND WorkDayMBRLightOn AND (NOT GCalendar) AND (IsNight; WorkDayMBRLightOn)

I also tried replacing the (NOT GCalendar) with !GCalendar.

This is when the morning alarm stopped working. When I changed it back to the original (GCalendar==0), it started working again.

All of the other statements that I changed per your suggestions work fine. What would cause this one instance to not work correctly?

I was also working to get my original questions resolved. After changing the condition to:

IsNight AND MBRLightOff AND MBRLightOff1 AND (IsNight; MBRLightOff1; MBRLightOff) it seems to be working correctly.

The only difference is that in the new statement, the order of the sequenced expressions have changed to what I asked in my last post. I guess that the order in this instance is what was making it work incorrectly before.

Regards,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on December 09, 2014, 03:36:34 pm
When GCalendar is not 0 what value does it show ?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on December 23, 2014, 01:50:58 pm
I am trying to get past my newb status with PLEG and things are starting to come together, however I don't completely understand the use of accessing PLEG's inputs and conditions after reading the guide. I want to use XXXX.seq as a time in a Vera Alerts notification. Is XXXX.seq only available on the luup tab or can it be available in the action editor under the advanced tab of Vera Alerts?

Device   Action   Arguments
VeraAlerts   SendAlert   Message={tone:2} Girlfriend is leaving at {(MLEAVING.seq)} after being home since {(MRETURN.seq)} {timestamp} {picture(65)} {picture(102)} Recipients=ME HouseModeMask=

I receive the text as stated along with the pictures. Do I need to set this in a condition to be made available or should I just paste in the luup tab with a luup call action Vera Alerts? I assume I'll need to add some date/time magic to make those values readable as well.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on December 23, 2014, 02:04:02 pm
The format XXXX.seq is only for use by Lua code in PLEG Actions. You can include the value of a Condition or Input in a normal Action by using the notation: {(expression)}. If it is the timestamp you want, use the # operator: #Name is the timestamp of the last change of Condition Name to true, #!Name is the timestamp of the last change to false.

If you want to convert the timestamp to human-understandable form, you will need to do this with Lua in the action.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on December 24, 2014, 10:22:06 am
The format XXXX.seq is only for use by Lua code in PLEG Actions. You can include the value of a Condition or Input in a normal Action by using the notation: {(expression)}. If it is the timestamp you want, use the # operator: #Name is the timestamp of the last change of Condition Name to true, #!Name is the timestamp of the last change to false.

If you want to convert the timestamp to human-understandable form, you will need to do this with Lua in the action.


Thank you sir! I was missing that part as I kept reading the actions section of the guide when I should have referred to the operators listed in the beginning.

Girlfriend arrived home on {DateTime(#MReturn,%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime(#MLeaving,%A %B %d, %Y at %H:%M:%S)} {timestamp}
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 02, 2015, 06:34:13 am
I am learning this great plugin and now I can see all kinds of possibilities that I couldn't do before.

I have a small problem with my first script that I am hoping someone can help with...

I would like to turn on my PC monitors, if they are off and if there is movement in the room.

I have a Condition of switchMonitorsOn, and expression of Movement and (not MonitorsOn).  By looking at the status I can see both Movement (a trigger) and MonitorsOn (a Device property of a switch) are working and have recently triggered.  But for some reason the expression never evaluates to True.  What am I missing??
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2015, 08:18:48 am
Quote
I have a Condition of switchMonitorsOn, and expression of Movement and (not MonitorsOn).  By looking at the status I can see both Movement (a trigger) and MonitorsOn (a Device property of a switch) are working and have recently triggered.  But for some reason the expression never evaluates to True.  What am I missing??

If you post a Status report from PLEG (preferably as a PDF), we can probably tell you why it is not working.

You will not regret the time you spend learning how to apply PLEG.  :)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 02, 2015, 08:50:19 am
Thanks!  I couldnt attach my status report (the forum upload folder is full) so have pasted below.  I used your guide Rex (very helpful!), but must have made some error.

Basically what I wanted to do was to turn on the lights if it is after dark and there is movement.  That bit works!

I also want to turn on monitors if there is movement.  That part doesn't work.

I also want to turn off the monitors and lights after 10 mins if there is no movement. 

------
Triggers

Name   Description   State   Last True   Last False
isNight   Day or Night indicates Night time.   false   2015-01-01 15:58:34.103   2015-01-02 08:08:59.103
movement   Fibaro motion sensor armed is tripped   false   2015-01-02 13:37:24.249   2015-01-02 13:37:55.278
Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On   Last Off
Timer   Self ReTrigger         None   Interval   00:10:00      None   false   2015-01-02 11:39:26.009   2015-01-02 11:49:26.100
Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
MonitorsOn   PC Monitors   Status   1   2015-01-02 11:16:51.131   2015-01-02 00:26:16.781
Conditions

Name   Repeat   Expression   State   Last True   Last False
Lightson   No   movement and isNight   false   2015-01-02 00:25:53.684   2015-01-02 00:26:43.243
Comments:   Switch lights on
switchMonitorsOn   No   movement and (not MonitorsOn)   false   0   0
Comments:   switch on monitor, sound etc
AutoOff   No   (MonitorsOn or LightsOn)and !Timer and ((MonitorsOn or LightsOn); !Timer)   null   2014-12-23 13:20:13.835   2015-01-02 11:59:11.927
Comments:   Turn off everything in the office if no movement in last 10 mins
Actions

Actions for Condition: AutoOff

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=0
PC Monitors   SetTarget   newTargetValue=0
Actions for Condition: Lightson

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=80
Actions for Condition: switchMonitorsOn

Device Actions:

Immediate

Device   Action   Arguments
PC Monitors   SetTarget   newTargetValue=1
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 02, 2015, 09:02:50 am
Try changing from:

   (not MonitorsOn)

to:

   (MonintorsOn == 0)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 02, 2015, 09:07:38 am
Try changing from:

   (not MonitorsOn)

to:

   (MonintorsOn == 0)

Wow.  That works!  Thanks. 

So I know for next time, what's the difference between not On and On==0
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 02, 2015, 10:41:14 am
Unfortunately my Auto off Timer also doesn't work. 

It is supposed to turn off the monitor and lights if there is no movement for 10 minutes.

LOG:

Name   Description   State   Last True   Last False
isNight   Day or Night indicates Night time.   false   2015-01-01 15:58:34.103   2015-01-02 08:08:59.103
lowlight   Light Sensor brightness reach 100   true   2015-01-02 15:36:31.292   0
movement   Fibaro motion sensor armed is tripped   false   2015-01-02 15:38:01.432   2015-01-02 15:38:32.532
Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On   Last Off
Timer   Self ReTrigger         None   Interval   00:10:00      None   false   2015-01-02 11:39:26.009   2015-01-02 11:49:26.100
Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
MonitorsOn   PC Monitors   Status   1   2015-01-02 14:06:48.408   2015-01-02 14:06:44.109
Conditions

Name   Repeat   Expression   State   Last True   Last False
Lightson   No   movement and isNight   false   2015-01-02 00:25:53.684   2015-01-02 00:26:43.243
Comments:   Switch lights on
switchMonitorsOn   No   movement and (MonitorsOn == 0)   false   2015-01-02 14:06:48.072   2015-01-02 14:06:48.411
Comments:   switch on monitor, sound etc
AutoOff   No   MonitorsOn and !Timer and (MonitorsOn; !Timer)   null   2014-12-23 13:20:13.835   2015-01-02 11:59:11.927
Comments:   Turn off everything in the office if no movement in last 10 mins
Actions

Actions for Condition: AutoOff

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=0
PC Monitors   SetTarget   newTargetValue=0
Actions for Condition: Lightson

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=80
Actions for Condition: switchMonitorsOn

Device Actions:

Immediate

Device   Action   Arguments
PC Monitors   SetTarget   newTargetValue=1
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2015, 11:26:40 am
Quote
Unfortunately my Auto off Timer also doesn't work.  It is supposed to turn off the monitor and lights if there is no movement for 10 minutes.

You don't appear to be starting the timer. You will need a Condition and Action to start the timer and, presumably, restart it if motion is detected.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 02, 2015, 12:34:47 pm
How do I do that?  I have tried various things to start the timer but I don't know what to do to make it work.

I am following the Timer light example on page 18 of the Getting Started guide, which shows the timer being created, but doesn't include any other action to start it or reset it - or am I missing something?   Is there another example with a timer I could follow?

Thanks for the help.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on January 02, 2015, 05:59:47 pm
The format XXXX.seq is only for use by Lua code in PLEG Actions. You can include the value of a Condition or Input in a normal Action by using the notation: {(expression)}. If it is the timestamp you want, use the # operator: #Name is the timestamp of the last change of Condition Name to true, #!Name is the timestamp of the last change to false.

If you want to convert the timestamp to human-understandable form, you will need to do this with Lua in the action.


Rex, it turns out I spoke too soon on my successes with #Name and the timestamps. I am trying to use 2 different timestamps in a Vera Alerts message but no matter which 2 #Name I insert both values return with the same timestamp.

Girlfriend arrived home on {DateTime(#MReturn,%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime(#MLeaving,%A %B %d, %Y at %H:%M:%S)} {timestamp}

Both MReturn and MLeaving will have #MReturn timestamp in my notification, and the reverse of this will have the #MLeaving as the timestamp for both items.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2015, 07:21:01 pm
How do I do that?  I have tried various things to start the timer but I don't know what to do to make it work.

I am following the Timer light example on page 18 of the Getting Started guide, which shows the timer being created, but doesn't include any other action to start it or reset it - or am I missing something?   Is there another example with a timer I could follow?

Thanks for the help.

The example on page 18 of PLEG Basics shows the Action KeepOn starting the timer. This is also mentioned on pages 4 and 14.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 02, 2015, 07:25:38 pm
Quote
Rex, it turns out I spoke too soon on my successes with #Name and the timestamps. I am trying to use 2 different timestamps in a Vera Alerts message but no matter which 2 #Name I insert both values return with the same timestamp.

Girlfriend arrived home on {DateTime(#MReturn,%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime(#MLeaving,%A %B %d, %Y at %H:%M:%S)} {timestamp}

Both MReturn and MLeaving will have #MReturn timestamp in my notification, and the reverse of this will have the #MLeaving as the timestamp for both items.

Sorry, I cannot help you with Vera Alerts syntax. I'm sure RTS will comment, though.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on January 03, 2015, 03:41:00 am
Quote
Rex, it turns out I spoke too soon on my successes with #Name and the timestamps. I am trying to use 2 different timestamps in a Vera Alerts message but no matter which 2 #Name I insert both values return with the same timestamp.

Girlfriend arrived home on {DateTime(#MReturn,%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime(#MLeaving,%A %B %d, %Y at %H:%M:%S)} {timestamp}

Both MReturn and MLeaving will have #MReturn timestamp in my notification, and the reverse of this will have the #MLeaving as the timestamp for both items.

Sorry, I cannot help you with Vera Alerts syntax. I'm sure RTS will comment, though.


Rex, thanks for your reply. I actually didn't consider that Vera Alerts could be the issue, as I just assumed that calling the #Name in any action in PLEG would provide the associated timestamp. I'll test with something other than Vera Alerts and see if I get the same result.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 03, 2015, 08:04:58 am
The Expansion in Actions (not LUA) is

 {(Expression)}

So you would use:

{(#MReturn)}
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 03, 2015, 10:02:26 am
The example on page 18 of PLEG Basics shows the Action KeepOn starting the timer. This is also mentioned on pages 4 and 14.
Thanks.  I missed that line.  Sorry about that.  The guide is really helpful and clear, especially with the examples.  PLEG is so powerful.  Once I get more confident I will try more things.  For now I am setting up my heating using the guide on page 19. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 03, 2015, 10:32:15 am
I am trying to understand and use the Simple Heater Timer Example. 

In the Conditions, AutoOff says:  Home and Not HeaterOn and (WeekdayAM or WeekdayPM or WeekendAM or WeekendPM)

Wouldn't this work the same if the Not HeaterOn was left out?

I have a heating controller that needs to be resent the ON commands every 30 minutes so I was thinking to add a 30 minute self retrigger Timer and make the condition say:

AutoOn:   Home and !Timer30M and (WeekdayAM or WeekdayPM or WeekendAM or WeekendPM)

In the Actions I would add
AutoOn   Turn Heater ON
               PLEG StartTimer timerName=Timer30M

Would that work?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on January 03, 2015, 11:38:38 am
The Expansion in Actions (not LUA) is

 {(Expression)}

So you would use:

{(#MReturn)}


Richard, thank you sir for your comment. I'll try this:

Girlfriend arrived home on {DateTime({(#MReturn)},%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime({(#MLeaving)},%A %B %d, %Y at %H:%M:%S)} {timestamp}
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 03, 2015, 12:21:22 pm
Quote
I am trying to understand and use the Simple Heater Timer Example. 

In the Conditions, AutoOff says:  Home and Not HeaterOn and (WeekdayAM or WeekdayPM or WeekendAM or WeekendPM)

Wouldn't this work the same if the Not HeaterOn was left out?

Yes that's an error in my example. Leave out the and Not HeaterOn term.

Quote
I have a heating controller that needs to be resent the ON commands every 30 minutes so I was thinking to add a 30 minute self retrigger Timer...

I guess you have a Horstmann HRT4-ZW or Secure SRT321 then. You could use a SelfTrigger timer but there is a simpler way too. Here's how I do it (http://forum.micasaverde.com/index.php/topic,28809.msg206151.html#msg206151).

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 03, 2015, 03:46:20 pm
I guess you have a Horstmann HRT4-ZW or Secure SRT321 then. You could use a SelfTrigger timer but there is a simpler way too. Here's how I do it (http://forum.micasaverde.com/index.php/topic,28809.msg206151.html#msg206151).

Great.  Thanks Rex!  Yes I have a Secure 2 channel heating controller.  I will try that delay tonight.  First though I can't actually get my existing timer to work properly.

I was using "Thermostat Mode Change" set to Heat as a Trigger, but that didn't seem to actually pick up the change if I set the Heat to on using the controls in the Vera UI.  So instead I changed it to use a device property (CentralHeating ModeStatus) of HeatOn.  That seems to work, but I can't do the autoOff becuase when I evaluate (HeatingOn eq "HeatOn");Away I always get a NULL value, even though both the parts of the comparison evaluate fine.

I've attached my log file below to see if you (or anyone can help).  I added some test conditions to see what is going on but can't see why (HeatingOn eq "HeatOn");Away is always Null.  Shouldn't it be True or False.


PLC Version:7.29Program Logic Event Generator[16]
2015-01-03 20:50:57.342

Registration

Installed: Thu Sep 25 2014. You have 1 license, which allows a total of 4 PLEG and/or PLTS plugins.
Your license key is: *******************
Triggers

Name   Description   State   Last True   Last False
isNight   Day or Night indicates Night time.   true   2015-01-03 19:41:21.105   2015-01-03 16:01:26.104
lowlight   Light Sensor brightness reach 100   true   2015-01-03 19:51:48.859   0
movement   Fibaro motion sensor armed is tripped   false   2015-01-03 20:29:47.809   2015-01-03 20:30:18.019
Schedules

Name   On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On   Last Off
SaturdayAM   Weekly   07:00:00   6   None   Weekly   08:00:00   6   None   false   0   0
SundayAM   Weekly   08:00:00   7   None   Weekly   11:00:00   7   None   false   0   0
Timer   Self ReTrigger         None   Interval   00:20:00      None   true   2015-01-03 20:29:47.885   2015-01-03 20:01:50.100
WeekdayAM   Weekly   05:20:00   1,2,3,4,5   None   Weekly   06:30:00   1,2,3,4,5   None   false   0   0
WeekdayPM   Weekly   18:00:00   1,2,3,4,5   None   Weekly   21:00:00   1,2,3,4,5   None   false   0   0
WeekendPM   Weekly   17:00:00   6,7   None   Weekly   21:00:00   6,7   None   true   2015-01-03 17:00:00.100   0
Device Properties

Name   Device Name   Device Variable   Value   Last Change   Previous Change
HeatingOn   Central Heating   ModeStatus   Off   2015-01-03 20:21:32.688   2015-01-03 19:54:52.101
Home   Home or Away   Status   0   2015-01-03 20:18:08.503   2015-01-03 20:17:19.947
MonitorsOn   PC Monitors   Status   1   2015-01-03 20:01:57.528   2015-01-03 20:01:50.358
Conditions

Name   Repeat   Expression   State   Last True   Last False
Lightson   No   movement and isNight   false   2015-01-03 20:29:47.811   2015-01-03 20:30:18.021
switchMonitorsOn   No   movement   false   2015-01-03 20:29:47.815   2015-01-03 20:30:18.021
Comments:   switch on PC monitors if senses movement
Away   No   Home == 0   true   2015-01-03 20:18:08.521   0
Comments:   If HomeAndAway virtual switch is off then I am away so dont trigger the central heating schedules
AutoOff   No   MonitorsOn and !Timer and (MonitorsOn; !Timer)   false   2015-01-03 20:01:50.105   2015-01-03 20:01:50.364
Comments:   Turn off monitors and lights if they are on and there is no movement for x mins since they were turned on
HeatingAutoOn   No   Home and (WeekdayAM or WeekdayPM or SaturdayAM or SundayAM or WeekendPM)   true   2015-01-03 17:00:00.111   2015-01-03 15:00:27.308
Comments:   Set Heating and HW to come on if Home and within one of the time windows. Keep it on by resending the command every 30 mins (avoids the sensor auto-off failsafe)
HeatingAutoOff   No   Not HeatingAutoOn or ((HeatingOn eq "HeatOn") and Away and ((HeatingOn eq "HeatOn"); Away))   null   2015-01-03 14:54:48.308   2015-01-03 19:54:52.112
Comments:   Set Heating and HW to Off if it is On and I then set Away
c1   No   HeatingOn eq "HeatOn"   false   2015-01-03 20:06:53.251   2015-01-03 20:21:32.700
c3   No   (HeatingOn eq "HeatOn");Away   null   0   2015-01-03 20:06:53.254
c4   No   Not HeatingAutoOn   false   0   0
Actions

Actions for Condition: AutoOff

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=0
PC Monitors   SetTarget   newTargetValue=0
Actions for Condition: HeatingAutoOff

Device Actions:

Immediate

Device   Action   Arguments
Central Heating   SetModeTarget   NewModeTarget=Off
Hot Water   SetModeTarget   NewModeTarget=Off
Actions for Condition: HeatingAutoOn

Device Actions:

Immediate

Device   Action   Arguments
Central Heating   SetModeTarget   NewModeTarget=HeatOn
Hot Water   SetModeTarget   NewModeTarget=HeatOn
Actions for Condition: Lightson

Device Actions:

Immediate

Device   Action   Arguments
Dimmer Light switch   SetLoadLevelTarget   newLoadlevelTarget=80
Actions for Condition: switchMonitorsOn

Device Actions:

Immediate

Device   Action   Arguments
Program Logic Event Generator   StartTimer   timerName=Timer intervalTime=
PC Monitors   SetTarget   newTargetValue=1
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on January 03, 2015, 04:00:47 pm
((HeatingOn eq "HeatOn"); Away) is not a valid Sequence expression. The terms in a Sequence expression cannot be expressions. One solution is to place the expression in a previous Condition:

Conditions
HeatIsOn           (HeatingOn eq "HeatOn")
HeatingAutoOff  Not HeatingAutoOn or (HeatIsOn and Away and (HeatIsOn; Away))
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on January 04, 2015, 11:37:54 am
((HeatingOn eq "HeatOn"); Away) is not a valid Sequence expression. The terms in a Sequence expression cannot be expressions. One solution is to place the expression in a previous Condition:

Conditions
HeatIsOn           (HeatingOn eq "HeatOn")
HeatingAutoOff  Not HeatingAutoOn or (HeatIsOn and Away and (HeatIsOn; Away))

Thanks!  That worked perfectly.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on January 04, 2015, 04:43:32 pm
The Expansion in Actions (not LUA) is

 {(Expression)}

So you would use:

{(#MReturn)}


Richard, thank you sir for your comment. I'll try this:

Girlfriend arrived home on {DateTime({(#MReturn)},%A %B %d, %Y at %H:%M:%S)} after being gone since {DateTime({(#MLeaving)},%A %B %d, %Y at %H:%M:%S)} {timestamp}

Richard, this is a big improvement as I actually get the condition timestamp! I assume my DateTime format must have an issue though as I get a 4 digit number appended to the beginning of my message:

Girlfriend arrived home on .3515,Sunday January 04, 2015 at 15:03:23.........
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 04, 2015, 07:18:30 pm
That's a problem because the timestamps are floats (with MS precision) ... i think this is the fractional part ... I will fix.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: YzRacer on January 05, 2015, 08:13:02 am
That's a problem because the timestamps are floats (with MS precision) ... i think this is the fractional part ... I will fix.


Richard, thanks for the input. I suspect the same, because when I was testing I did see that was the last fraction of the actual timestamp. It's not really a bother.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: jp9219 on January 09, 2015, 10:51:42 am
I'm having a lot of trouble figuring out what I'm trying to do with PLEG on UI7.  I started playing with Vera yesterday and jumped right in (IT background so most of it is pretty self explanatory to me).  However, I'm trying to work in schedules with PLEG and I just don't seem to be getting it.

What I'm trying to accomplish:
  Alert that will fire when my garage door is opened between 12am and 6:30am.  I'm testing it with my thermostat since that is easier than opening my garage door over and over. :)

What I'm setting up in PLEG:

Trigger:
 t1 = _Therm_Main_Floor heat setpoint goes over 73 degrees

Schedule
s1 =   Weekly   23:55:00   1,2,3,4,5,6,7   None   Weekly   00:59:00   1,2,3,4,5,6,7   None

Condition:
c1 = t1 and s1

Action:
VeraAlerts to email me alert message

t1 will trigger when the garage door opens (thermostat goes above 73) and that works correctly.  However, it never evaluates s1 to be True.  I assumed it would activate at whatever time I set above but it doesn't seem to work that way.  What am I missing?

Thanks!!!  One note, I'm thinking about whether I should just downgrade to UI5.  I have a request in to turn off my auto-update flag but figured I should continue playing with UI7 while I have the chance.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 09, 2015, 11:14:06 am
Schedules  will not automatically change state until the ACTUAL time occurs.
If you want to simulate the schedule happening sooner ... then click the Do It Now. It will toggle the CURRENT state of the timer.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: jp9219 on January 09, 2015, 11:24:41 am
Thanks Richard.  I was putting the schedule out a few minutes from the current time to try and get it to take effect.  That wasn't changing the state though...do I have to do something to make it start tracking so that it will change state?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 09, 2015, 11:29:47 am
You have to restart LUA for the definitions to take effect  (... this is available at the bottom of the Advanced Tab)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: jp9219 on January 09, 2015, 01:06:10 pm
Thank you so much Richard.  I didn't see anything before about restarting but that worked.  Plus, I am on the latest Firmware now so I think that had something to do with helping it out.  I really want to try and stay on UI7 and this should allow it for now.

One question, do you know why the icons don't show up anymore for the apps after I reloaded my backup after the firmware update?  Anyway to get them back easily?
Title: New Version of PLEG Basics for V7.35
Post by: RexBeckett on January 29, 2015, 11:54:30 am
I have uploaded a new version of PLEG Basics. The updates include:


The PDF can be downloaded using the link in the first post (http://forum.micasaverde.com/index.php/topic,21603.0.html).
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on February 08, 2015, 10:22:14 am
I think I have a small error in my HeatBoost function, designed to turn on my heating for 45 mins.

It starts OK, but when the 45 minute timer ends, the HeatingOff condition doesn't evaluate. 

My heatingOff Condition is:  (Not HeatingAutoOn) or (HeatIsOn and Away and (HeatIsOn; Away)) or (HeatIsOn; !I45M)   

I think it might be because it is already true, so having the 45 minute timer end doesn't trigger it to be true again and do the actions of turning off the heat.

I tried setting it to repeats but that also didn't work, because that stops the Boost function operating at all.

Thanks for any advice.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on February 08, 2015, 10:38:55 am
I think I have a small error in my HeatBoost function, designed to turn on my heating for 45 mins.

It starts OK, but when the 45 minute timer ends, the HeatingOff condition doesn't evaluate. 

My heatingOff Condition is:  (Not HeatingAutoOn) or (HeatIsOn and Away and (HeatIsOn; Away)) or (HeatIsOn; !I45M)   

I think it might be because it is already true, so having the 45 minute timer end doesn't trigger it to be true again and do the actions of turning off the heat.

I tried setting it to repeats but that also didn't work, because that stops the Boost function operating at all.

Thanks for any advice.

You do need to set Repeats on for this Condition. When you are using the boost, it is presumably because the heating is off so Not HeatingAutoOn is going to be true already. I think a small adjust ment to the parentheses is also required and I would include a term for the timer.

HeatingAutoOff    (Not HeatingAutoOn) or (HeatIsOn and ((Away and (HeatIsOn; Away)) or (!I45M and (HeatIsOn; !I45M)))
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 08, 2015, 10:46:01 am
From your report ...
     HeatingAutoOff became true (15:14:07.117)  as a result of I45M being turned OFF (15:14:07.101)

You might check to see if Vera is restarting while executing your actions.

Maybe set the log (using the Log cmd) to into it's own file (save/reload).
From the log file you should be able to see if this is restarting while running.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 08, 2015, 11:01:12 am
Actually I would probably change the logic as follows:

  (Not HeatingAutoOn) or (HeatIsOn and Away and (HeatIsOn; Away)) or (HeatBoost and (HeatBoost; !I45M))

You need to reset the HeatBoost switch ... even if the heat is already off.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dominoman on February 08, 2015, 05:50:02 pm
Actually I would probably change the logic as follows:

  (Not HeatingAutoOn) or (HeatIsOn and Away and (HeatIsOn; Away)) or (HeatBoost and (HeatBoost; !I45M))

You need to reset the HeatBoost switch ... even if the heat is already off.

Brilliant.  That works perfectly.  Thanks!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on April 25, 2015, 10:27:52 pm
Basic PLEG question.
I am testing this out and I really like it so far, even thought I have not been able to make it work.

I am trying a very simple task to start and will try to grow from there
- What I'm trying to accomplish: Stair lights turn on when I unlock the door at night


- How I have configured this:
Code: [Select]
[u][b]Triggers:[/b][/u]
[i]tFrontDoorUnlocked[/i] Baldwin Door Lock is opened
[i]tItsNight[/i] Day or Night indicates Night time.

[u][b]Conditions:[/b][/u]
[i]cDoorOpenAtNight[/i]    tFrontDoorUnlocked AND tItsNight

Actions:
[i]cDoorOpenAtNight[/i]   Immediate  SetTarget  newTargetValue = 1

when i test the action by pressing the Do It Now button it works fine but when I unlock my front door nothing happens.

What am I doing wrong?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 26, 2015, 01:45:53 am
Is the PLEG armed ?
Did you check the status report to see what times the various Inputs where set to true ?

Please post your Status report as a PDF file ... there are plenty of FREE PDF printers ... see Cute PDF if you do not currently have a PDF printer.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on April 27, 2015, 02:18:42 pm
Is the PLEG armed ?
Did you check the status report to see what times the various Inputs where set to true ?

Please post your Status report as a PDF file ... there are plenty of FREE PDF printers ... see Cute PDF if you do not currently have a PDF printer.

Thanks for your help. I did check to ensure PLEG is armed (it hadn't occurred to me so thanks for the heads up)
I have attached the PDF file. Please let me know what I did wrong

thanks again
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 27, 2015, 06:27:03 pm
@grrgold
You did not indicate you were getting an error about invalid Startup LUA.
I have a bug that requires you to explicitly set it to blank (delete the contents) when you create a new PLEG.
This was not checked or detected in a previous version of PLEG.
But you can see it in the status report ...

Also you might try a different trigger .. like a pin is entered  ... I do not know what kind of lock you have or what type of events are generated.
A pin code of * will accept any pin code.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on May 19, 2015, 12:25:23 am
@RichardTSchaefer

thanks for your help so far. I was able to re-install PLEG and no longer get the error, however I still can't get even the most basic event to run.

I am trying something simple just to learn. I want the Stair lights to turn on when i unlock the door.

I have attached the reports, let me know what I am doing wrong.

thanks
grrgold
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 19, 2015, 08:38:03 am
Looks correct ...
The status report shows you have NOT opened the door after you created/saved the condition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on May 19, 2015, 09:34:03 pm
OK, I am finally making some progress. I was able to get the light to turn on when a pin code is entered. Now i wanted to refine by having this only happen at night so I added a device property for my Day or Night plugin.
Now what happens is the light turns on any time the device property is set to Night even if the door pin code trigger is not set.

I have attached my reports... I really appreciate your patience helping me figure this out.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RexBeckett on May 20, 2015, 03:44:13 am
Quote
OK, I am finally making some progress. I was able to get the light to turn on when a pin code is entered. Now i wanted to refine by having this only happen at night so I added a device property for my Day or Night plugin.
Now what happens is the light turns on any time the device property is set to Night even if the door pin code trigger is not set.

You can create a Trigger for Day or Night rather than using a Device Property. This will make it easier to use time-sensitive Sequence expressions:

Triggers
tFrontDoorUnlock     PIN Code #* is entered on Baldwin Door Lock
tItsNight                    Day or Night indicates Night

Conditions
cFrontDoorOpensAtNight     tFrontDoorUnlock and tItsNight and (tItsNight; tFrontDoorUnlock)

The modified Condition will fire when the door is unlocked after it became night.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 20, 2015, 08:48:37 am
Another approach is to CLEAR the pin after it is detected.
i.e. Create a second condition (Should be after first condition):
ClearDoorCode             tFrontDoorUnlock

And add the following acction:

This can be done using the ADVANCED mode settings in the Action editor.
Select the:
    1) The PLEG Device
    2) The SetVariable Action
    3) Set ServiceId to:
               urn:micasaverde-com:serviceId:DoorLock1
    4) Set VariableName to:
             sl_UserCode
    5) Set Value to:     LEAVE IT BLANK
    6) Set the device to the Lock device number.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on May 20, 2015, 02:11:36 pm
Quote
OK, I am finally making some progress. I was able to get the light to turn on when a pin code is entered. Now i wanted to refine by having this only happen at night so I added a device property for my Day or Night plugin.
Now what happens is the light turns on any time the device property is set to Night even if the door pin code trigger is not set.

You can create a Trigger for Day or Night rather than using a Device Property. This will make it easier to use time-sensitive Sequence expressions:

Triggers
tFrontDoorUnlock     PIN Code #* is entered on Baldwin Door Lock
tItsNight                    Day or Night indicates Night

Conditions
cFrontDoorOpensAtNight     tFrontDoorUnlock and tItsNight and (tItsNight; tFrontDoorUnlock)

The modified Condition will fire when the door is unlocked after it became night.

i understand the logic behind what you say, can you please explain the syntax of the Condition? I am having a hard time seeing how this will prevent the light from turning on only when the tItsNight is triggered if tFrontDoorUnlock has happened
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 20, 2015, 06:12:08 pm
Quote
(tItsNight; tFrontDoorUnlock)

This is only TRUE if   tFrontDoorUnlock happens AFTER tIsNight
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 4Crawler on May 22, 2015, 01:08:27 am
I'm probably missing something basic  Simple question here, VeraLite running UI7 and the latest PLEG (licensed). 

I have my original PLEG instance I set up last year under UI5.  How do I create a second instance in UI7, associated with a different room for example?

Thanks.

P.S. I put together a little YouTube video of a little proof of concept idea I put together using PLEG:
https://youtu.be/oX36pEva--A
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 22, 2015, 10:57:07 am
To Create another PLEG

1) Go to Apps Panel
2) Select My Apps
3) Select PLEG Details
4) Create Another

Nice Little Video
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 4Crawler on May 22, 2015, 01:01:44 pm
Thanks Richard, I knew I must be missing something simple like that.

Are the namespaces between the separate instances separate then? 
If I had trigger t1 in instance 1 and trigger t1 in instance 2 are those the same or different?

Really fantastic plug-in, keep up the good work!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 22, 2015, 06:44:27 pm
The are different ...
Although PLEG allows you to EXPORT a condition ... that can be used as a device property input in another PLEG. There you can give it a new name or reuse the name!

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on May 23, 2015, 03:49:11 pm
Help with schedule.

I am slowly getting the hang of PLEG but would still like some help. I have a fountain that is controlled from a switch. I would like to put it on a schedule so that it runs for 5 minutes every hour.
Can you walk me through this?

thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 23, 2015, 08:04:10 pm
Create a schedule:

Call it FountainSchedule

Start Time:    Interval   1 Hour
Stop Time:    Inerval 5 Minutes

Create two conditions:
StartFountain           FountainSchedule
StopSchedule           !FountainSchedule


Add actions to these conditions to turn on/off your fountain.


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 4Crawler on May 24, 2015, 10:59:06 am
The are different ...
Although PLEG allows you to EXPORT a condition ... that can be used as a device property input in another PLEG. There you can give it a new name or reuse the name!

Thanks Richard.  This will help me clean up my system a bit.  I was trying to do a couple of motion controlled lights in the same instance and the names were getting overly messy.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dpancer on June 01, 2015, 10:20:45 am
I'm also just getting into pleg. I read through the entire PLEG Basic guide....Awesome job on it!!!

So just a few questions im hoping to get answered:

1. When I try using the interactive editor the cursor keeps jumping to the to beginning of the box. It makes using this impossible. I haven't seen any errors or bug-fix request regarding this so im not sure if its broken or im using it wrong.

2. In pleg basics, the first simple example of the motion triggered light:

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)


If the sequence expression (LightOn; Motion) was taken out of the condition statement would it still function the same way? Does the motion need to follow the last timestamp of LightOn to be functional?
Same thing for (LightOn; !Timer) for the AutoOff condition?

3. I"m still not completely grasping the NOW term; where its best used and why? Also because of its 1 min evaluation period, and the extra CPU processing needed, would there not be an alternative to this that would in fact be less "intense" on the CPU?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 4Crawler on June 01, 2015, 05:18:10 pm
Some other usage questions I ran into that I did not see addressed in the PLEG Basics document:

1. Under Devices->Advanced->Commands is a "Controlled Via" selection, normally set to Z-Wave.  But in the pull down list are other devices including the PLEG instances.  If I have a device controlled via a PLEG instance, do I need to change this setting or just leave it set to Z-Wave?

2. In PLEG->Conditions I can enter my inputs and logic in the main text field, but below are "Using:" selections.  If I already reference say a Schedule in the text field, do I also have to select Using->Schedule and select that same one?  Or is the intention there to just autofill in the name of the dependency for you, such as selecting a schedule under Using->Schedule will place that schedule name into the text field?  I've not tried the latter, and the former doesn't seem to do anything visible in UI7.  That is, if I have schedule s1 in the text field and then select Using->Schedule->s1, nothing seems to change.

Thanks in advance.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 01, 2015, 06:39:18 pm
Quote
Under Devices->Advanced->Commands is a "Controlled Via" selection, normally set to Z-Wave
Do not ever touch this setting unless you are a developer and know what you are doing ... or you really trust the person that told you to do this!



The Condition Editor needs more UI work ... but it allows you to create a condition without remembering the names of your inputs or condition names.
It also has the list of various operator types in case you can't remember.

You can Always just type text into this window ... or the table with the list of conditions. I think that is what most folks do.
Point the mouse somewhere in the expression ... The more clicks you do the wider the selection becomes.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: EOppie on June 01, 2015, 11:53:34 pm
Alright, I am missing something stupid I am sure.  PLEG is chugging along with everything quite well with the exception of my "kitchen can lights" which turn themselves off, despite motion occurring in the room.  I simply go turn them back on, but when cooking this gets to be a little tedious.

Any ideas?  Please let me know if I should post this in a different way :-)

Code: [Select]
Triggers

Name Description
AlarmArmed Security is armed AWAY
AlarmNight Ademco Vista Partition 1 is armed NIGHT-STAY
BathLightOn Front Bathroom Light is turned on
DrivewayLightsOn Driveway Lights is turned on
EricaAway Erica Phone is not Tripped
EricaHome Erica Phone is Tripped
EricAway Eric Phone is not Tripped
EricaWork GCal3 Sensor: Tripped
EricHome Eric Phone is Tripped
FamilyMotion Zone #2 - Family Room Motion is tripped
FrontBathMotion _4 in 1 sensor (motion) is tripped
FrontDoorClosed Zone #27 - Front Entry Door is not tripped
FrontDoorOpen Zone #27 - Front Entry Door is tripped
FrontNFC Front Door Entry NFC is turned on
FrontNFCOff Front Door Entry NFC is turned off
GarageClosed Garage Door Sensor is not tripped
GarageEntryClosed Zone #28 - Garage Entry Door is not tripped
GarageEntryNFC Garage Entry NFC is turned on
GarageEntryOpen Zone #28 - Garage Entry Door is tripped
GarageOpen Garage Door Sensor is tripped
IsDay Day or Night indicates Day time.
IsNight Day or Night indicates Night time.
IsRaining World Weather: Condition Group is 'Rain'
IsThunderstorm World Weather: Condition Group is 'Thunderstorm'
KitchenCansOn Kitchen Can Lights is turned on
KitchenMotion Kitchen Motion is tripped
KitchenNoMotion Kitchen Motion is not tripped
MasterLightsOn Floor and Dresser Lamp is turned on
PoleLightOff Pole Lamp is turned off
PoleLightOn Pole Lamp is turned on
PorchOff Porch Lights is turned off
PorchOn Porch Lights is turned on
PorchOutletOff Front Porch Outlet is turned off
PorchOutletOn Front Porch Outlet is turned on
RearEntryOpen Zone #28 - Garage Entry Door is tripped
TableLightOn Kitchen Table Light is turned on
Schedules

Name On Type On Time On Days Random On Delay Off After Type Off Time Off Days Random Off Delay
BathTimer Self ReTrigger None Interval 00:05:00 None
KitchenTimer Self ReTrigger None Interval 00:10:00 None
NightLightActive Weekly 23:30:00 1,2,3,4,5,6,7 None Weekly 06:00:00 1,2,3,4,5,6,7 None
Timer Self ReTrigger None Interval 00:10:00 None
Conditions

Name Repeat Expression
TurnOnPoleLight No (NOT PoleLightOn) AND (FrontNFC AND IsNight)
TurnOnTableLight No (NOT TableLightOn) AND (GarageEntryNFC AND IsNight)
AutoOnTableLight No TurnOnTableLight; TableLightOn < 2:00
Sunset No (IsNight) AND (PorchOff)
Sunrise No (IsDay)
_ArriveLights Yes PorchOn AND (EricHome OR EricaHome OR FrontDoorOpen) AND IsNight
AutoDim No (PorchOn) AND (_ArriveLights; NOW > 1:00)
OutletOn No (IsNight) AND (PorchOutletOFF)
OutletOff No (IsDay) AND (PorchOutletON)
FrontEntryOpen No (IsNight) AND (FrontDoorOpen) AND PoleLightOff
FrontEntryClose No (IsNight) AND (FrontEntryOpen; Now > 2:00) AND (FrontDoorClosed)
WakeupLight No (EricaWork AND EricaHome) AND IsNight
AutoWakeupLight No WakeupLight; MasterLightsOn < 15
AutoOnKitchenCans No !KitchenCansOn and IsNight and KitchenMotion and (!KitchenCansOn; KitchenMotion > 15)
AutoOffKitchenCans No !NightLightActive and KitchenCansOn and !KitchenTimer and (KitchenCansOn; !KitchenTimer) and (!KitchenCansOn; KitchenCansOn > 10)
AutoOffKitchenManualOn No (NOT AutoOnKitchenCans) AND (KitchenMotion; KitchenNoMotion) AND (KitchenNoMotion; NOW > 5:00)
AutoOnRainLights No (NOT IsNight) AND (IsRaining OR IsThunderstorm)
AutoOffRainLight No AutoOnRainLights AND (NOT IsRaining) AND (NOT IsThunderstorm) AND (AutoOnRainLights; NOW > 5:00)
KeepOnKitchenCans No (KitchenCansOn and KitchenMotion and (KitchenCansOn; KitchenMotion)) or AutoOnKitchenCans
CleanFloor No AlarmArmed AND (EricaAway or EricAway)
DockRoomba No !AlarmArmed OR (EricHome or EricaHome)
AutoOnGarageLight No (GarageEntryOpen AND (!GarageOpen OR IsNight)) OR (GarageOpen AND IsNight)
AutoOffGarageLight No (!AutoOnGarageLight) AND (AutoOnGarageLight; NOW > 10:00)
DrivewayLightsAutoOn No DrivewayLightsOn AND GarageOpen
DrivewayLightsAutoDim No (DrivewayLightsAutoOn AND !GarageOpen) AND (DrivewayLightsAutoOn; NOW > 2:00)
LivingRoomNightLightOn No NightLightActive and !PoleLightOn and FamilyMotion and (!PoleLightOn; FamilyMotion > 15)
LivingRoomNightLightOff No !LivingRoomNightLightOn and (LivingRoomNightLightOn; NOW > 2:00)
KitchenNightLightOn No AlarmNight and !KitchenCansOn and IsNight and KitchenMotion and (!KitchenCansOn; KitchenMotion > 15)
KitchenNightLightOff No !KitchenNightLightOn and (KitchenNightLightOn; NOW > 2:00)
AutoOnBathLight No !BathLightOn and IsNight and FrontBathMotion and (!BathLightOn; FrontBathMotion > 30)
KeepOnBathLight No (BathLightOn and FrontBathMotion and (BathLightOn; FrontBathMotion)) or AutoOnBathLight
AutoOffBathLight No BathLightOn and !BathTimer and (BathLightOn; !BathTimer) and (!BathLightOn; BathLightOn > 10)
Actions

Code: [Select]
Triggers

Name Description State Last True Last False
AlarmArmed Security is armed AWAY false 2015-06-01 19:36:22.349 2015-06-01 23:33:37.306
AlarmNight Ademco Vista Partition 1 is armed NIGHT-STAY false 0 2015-06-01 21:27:12.897
BathLightOn Front Bathroom Light is turned on false 2015-06-01 19:48:07.199 2015-06-01 19:53:06.609
DrivewayLightsOn Driveway Lights is turned on true 2015-06-01 19:30:53.709 2015-06-01 06:49:13.038
EricaAway Erica Phone is not Tripped false 2015-06-01 19:37:16.423 2015-06-01 21:26:40.211
EricaHome Erica Phone is Tripped true 2015-06-01 21:26:40.211 2015-06-01 19:37:16.424
EricAway Eric Phone is not Tripped false 2015-06-01 21:30:35.246 2015-06-01 21:30:55.215
EricaWork GCal3 Sensor: Tripped false 2015-05-23 04:30:06.107 2015-05-23 19:30:01.666
EricHome Eric Phone is Tripped true 2015-06-01 21:30:55.215 2015-06-01 21:30:35.246
FamilyMotion Zone #2 - Family Room Motion is tripped false 2015-06-01 23:33:19.936 2015-06-01 23:33:36.795
FrontBathMotion _4 in 1 sensor (motion) is tripped true 2015-06-01 19:32:48.927 2015-06-01 07:10:13.537
FrontDoorClosed Zone #27 - Front Entry Door is not tripped true 2015-06-01 21:37:48.495 2015-06-01 21:36:15.979
FrontDoorOpen Zone #27 - Front Entry Door is tripped false 2015-06-01 21:36:15.980 2015-06-01 21:37:48.495
FrontNFC Front Door Entry NFC is turned on false 2015-06-01 07:16:15.132 2015-06-01 07:17:15.104
FrontNFCOff Front Door Entry NFC is turned off true 2015-06-01 07:17:15.105 2015-06-01 07:16:15.132
GarageClosed Garage Door Sensor is not tripped true 2015-06-01 21:29:59.143 2015-06-01 21:26:05.029
GarageEntryClosed Zone #28 - Garage Entry Door is not tripped true 2015-06-01 21:37:49.105 2015-06-01 21:28:35.831
GarageEntryNFC Garage Entry NFC is turned on false 2015-06-01 21:27:11.584 2015-06-01 21:27:21.107
GarageEntryOpen Zone #28 - Garage Entry Door is tripped false 2015-06-01 21:28:35.831 2015-06-01 21:37:49.105
GarageOpen Garage Door Sensor is tripped false 2015-06-01 21:26:05.029 2015-06-01 21:29:59.144
IsDay Day or Night indicates Day time. false 2015-06-01 06:49:12.120 2015-06-01 19:48:06.160
IsNight Day or Night indicates Night time. true 2015-06-01 19:48:06.160 2015-06-01 06:49:12.120
IsRaining World Weather: Condition Group is 'Rain' true 2015-06-01 22:30:52.512 2015-06-01 19:30:52.914
IsThunderstorm World Weather: Condition Group is 'Thunderstorm' false 2015-06-01 19:30:52.914 2015-06-01 22:30:52.513
KitchenCansOn Kitchen Can Lights is turned on false 2015-06-01 23:21:38.873 2015-06-01 23:22:27.258
KitchenMotion Kitchen Motion is tripped false 2015-06-01 23:21:38.047 2015-06-01 23:25:57.208
KitchenNoMotion Kitchen Motion is not tripped true 2015-06-01 23:25:57.208 2015-06-01 23:21:38.048
MasterLightsOn Floor and Dresser Lamp is turned on true 2015-06-01 21:48:08.386 2015-06-01 01:19:00.081
PoleLightOff Pole Lamp is turned off false 2015-06-01 21:50:59.250 2015-06-01 22:58:56.454
PoleLightOn Pole Lamp is turned on true 2015-06-01 22:58:56.454 2015-06-01 21:50:59.250
PorchOff Porch Lights is turned off false 2015-06-01 06:49:12.778 2015-06-01 19:30:53.429
PorchOn Porch Lights is turned on true 2015-06-01 19:30:53.429 2015-06-01 06:49:12.778
PorchOutletOff Front Porch Outlet is turned off false 2015-06-01 06:49:13.297 2015-06-01 19:48:06.828
PorchOutletOn Front Porch Outlet is turned on true 2015-06-01 19:48:06.828 2015-06-01 06:49:13.297
RearEntryOpen Zone #28 - Garage Entry Door is tripped false 2015-06-01 21:28:35.832 2015-06-01 21:37:49.106
TableLightOn Kitchen Table Light is turned on false 2015-06-01 21:27:12.385 2015-06-01 21:29:11.504
Schedules

Name On Type On Time On Days Random On Delay Off After Type Off Time Off Days Random Off Delay State Last On Last Off
BathTimer Self ReTrigger None Interval 00:05:00 None false 2015-06-01 19:48:06.402 2015-06-01 19:53:06.154
KitchenTimer Self ReTrigger None Interval 00:10:00 None false 2015-06-01 23:21:38.497 2015-06-01 23:31:38.101
NightLightActive Weekly 23:30:00 1,2,3,4,5,6,7 None Weekly 06:00:00 1,2,3,4,5,6,7 None true 2015-06-01 23:30:00.143 2015-06-01 06:00:00.101
Timer Self ReTrigger None Interval 00:10:00 None false 2014-09-21 22:14:30.671 2014-09-21 22:24:30.102
Conditions

Name Repeat Expression State Last True Last False
TurnOnPoleLight No (NOT PoleLightOn) AND (FrontNFC AND IsNight) false 2015-05-31 21:48:29.965 2015-05-31 21:48:30.528
TurnOnTableLight No (NOT TableLightOn) AND (GarageEntryNFC AND IsNight) false 2015-06-01 21:27:11.600 2015-06-01 21:27:12.393
AutoOnTableLight No TurnOnTableLight; TableLightOn < 2:00 true 2015-06-01 21:27:12.394 2015-06-01 21:27:11.607
Sunset No (IsNight) AND (PorchOff) false 2015-05-31 19:47:36.136 2015-05-31 19:47:36.932
Sunrise No (IsDay) false 2015-06-01 06:49:12.139 2015-06-01 19:48:06.173
_ArriveLights Yes PorchOn AND (EricHome OR EricaHome OR FrontDoorOpen) AND IsNight true 2015-06-01 21:37:48.510 2015-06-01 19:48:06.176
AutoDim No (PorchOn) AND (_ArriveLights; NOW > 1:00) true 2015-06-01 21:38:52.124 2015-06-01 21:33:59.592
OutletOn No (IsNight) AND (PorchOutletOFF) false 2015-06-01 19:48:06.180 2015-06-01 19:48:06.847
OutletOff No (IsDay) AND (PorchOutletON) false 2015-06-01 06:49:12.156 2015-06-01 06:49:13.322
FrontEntryOpen No (IsNight) AND (FrontDoorOpen) AND PoleLightOff false 2015-05-29 22:58:36.183 2015-05-29 22:58:46.691
FrontEntryClose No (IsNight) AND (FrontEntryOpen; Now > 2:00) AND (FrontDoorClosed) true 2015-06-01 21:37:16.221 2015-06-01 21:36:00.494
WakeupLight No (EricaWork AND EricaHome) AND IsNight false 2015-05-23 04:30:06.182 2015-05-23 05:28:43.279
AutoWakeupLight No WakeupLight; MasterLightsOn < 15 false 2015-05-23 04:30:06.604 2015-05-23 19:03:52.696
AutoOnKitchenCans No !KitchenCansOn and IsNight and KitchenMotion and (!KitchenCansOn; KitchenMotion > 15) false 2015-06-01 23:21:38.147 2015-06-01 23:21:38.950
AutoOffKitchenCans No !NightLightActive and KitchenCansOn and !KitchenTimer and (KitchenCansOn; !KitchenTimer) and (!KitchenCansOn; KitchenCansOn > 10) false 2015-06-01 18:44:11.141 2015-06-01 18:44:11.538
AutoOffKitchenManualOn No (NOT AutoOnKitchenCans) AND (KitchenMotion; KitchenNoMotion) AND (KitchenNoMotion; NOW > 5:00) true 2015-06-01 23:31:52.153 2015-06-01 23:21:38.225
AutoOnRainLights No (NOT IsNight) AND (IsRaining OR IsThunderstorm) false 2015-06-01 19:30:52.959 2015-06-01 19:48:06.218
AutoOffRainLight No AutoOnRainLights AND (NOT IsRaining) AND (NOT IsThunderstorm) AND (AutoOnRainLights; NOW > 5:00) false 2014-11-25 10:53:46.108 2014-11-25 11:02:38.654
KeepOnKitchenCans No (KitchenCansOn and KitchenMotion and (KitchenCansOn; KitchenMotion)) or AutoOnKitchenCans false 2015-06-01 23:21:38.246 2015-06-01 23:21:38.969
CleanFloor No AlarmArmed AND (EricaAway or EricAway) false 2015-06-01 19:37:16.300 2015-06-01 21:26:55.301
DockRoomba No !AlarmArmed OR (EricHome or EricaHome) true 2015-06-01 21:26:40.297 2015-06-01 19:37:16.487
AutoOnGarageLight No (GarageEntryOpen AND (!GarageOpen OR IsNight)) OR (GarageOpen AND IsNight) false 2015-06-01 21:26:05.101 2015-06-01 21:29:59.208
AutoOffGarageLight No (!AutoOnGarageLight) AND (AutoOnGarageLight; NOW > 10:00) true 2015-06-01 21:36:52.174 2015-06-01 21:26:05.111
DrivewayLightsAutoOn No DrivewayLightsOn AND GarageOpen false 2015-06-01 21:26:05.112 2015-06-01 21:29:59.212
DrivewayLightsAutoDim No (DrivewayLightsAutoOn AND !GarageOpen) AND (DrivewayLightsAutoOn; NOW > 2:00) false 2015-02-22 06:29:40.289 2015-02-23 00:28:01.034
LivingRoomNightLightOn No NightLightActive and !PoleLightOn and FamilyMotion and (!PoleLightOn; FamilyMotion > 15) false 2015-06-01 05:59:59.430 2015-06-01 05:59:59.815
LivingRoomNightLightOff No !LivingRoomNightLightOn and (LivingRoomNightLightOn; NOW > 2:00) true 2015-06-01 06:02:50.180 2015-06-01 05:59:59.441
KitchenNightLightOn No AlarmNight and !KitchenCansOn and IsNight and KitchenMotion and (!KitchenCansOn; KitchenMotion > 15) false 2015-04-12 00:33:59.578 2015-04-12 00:34:00.095
KitchenNightLightOff No !KitchenNightLightOn and (KitchenNightLightOn; NOW > 2:00) true 2015-04-12 00:36:30.182 2015-04-12 00:33:59.585
AutoOnBathLight No !BathLightOn and IsNight and FrontBathMotion and (!BathLightOn; FrontBathMotion > 30) false 2015-06-01 19:48:06.256 2015-06-01 19:48:07.286
KeepOnBathLight No (BathLightOn and FrontBathMotion and (BathLightOn; FrontBathMotion)) or AutoOnBathLight false 2015-06-01 19:48:06.264 2015-06-01 19:48:07.289
AutoOffBathLight No BathLightOn and !BathTimer and (BathLightOn; !BathTimer) and (!BathLightOn; BathLightOn > 10) false 2015-06-01 19:53:06.290 2015-06-01 19:53:06.697
Actions

Code: [Select]
Actions for Condition: AutoOffKitchenCans

Device Actions:

Immediate

Device Action Arguments
Kitchen Can Lights SetLoadLevelTarget newLoadlevelTarget=0
Actions for Condition: AutoOffKitchenManualOn

Device Actions:

Immediate

Device Action Arguments
Kitchen Can Lights SetLoadLevelTarget newLoadlevelTarget=0

Actions for Condition: AutoOnKitchenCans

Device Actions:

Immediate

Device   Action   Arguments
Kitchen Can Lights   SetLoadLevelTarget   newLoadlevelTarget=70

Actions for Condition: KeepOnKitchenCans

Device Actions:

Immediate

Device   Action   Arguments
Lighting   StartTimer   timerName=KitchenTimer intervalTime=
Actions for Condition: KitchenNightLightOff

Device Actions:

Immediate

Device   Action   Arguments
Kitchen Can Lights   SetLoadLevelTarget   newLoadlevelTarget=0
Actions for Condition: KitchenNightLightOn

Device Actions:

Immediate

Device   Action   Arguments
Kitchen Can Lights   SetLoadLevelTarget   newLoadlevelTarget=10
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 4Crawler on June 02, 2015, 01:02:31 am
Quote
Under Devices->Advanced->Commands is a "Controlled Via" selection, normally set to Z-Wave
Do not ever touch this setting unless you are a developer and know what you are doing ... or you really trust the person that told you to do this!



The Condition Editor needs more UI work ... but it allows you to create a condition without remembering the names of your inputs or condition names.
It also has the list of various operator types in case you can't remember.

You can Always just type text into this window ... or the table with the list of conditions. I think that is what most folks do.
Point the mouse somewhere in the expression ... The more clicks you do the wider the selection becomes.

Thanks Richard, that's essentially what I thought, just wanted to be sure.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on June 06, 2015, 02:29:43 pm
Hi Richard. Some additional Help
I have a motion sensor (Fibaro) that I am using to controll my stair lights.
I want the stair lights to go on when motion is detected, but only if the lights aren't already on, and only at night.

the problem i am having is that the motion sensor retains its "tripped" state so when i turn off the lights, it immediately turns them back on again. How can I have this reset so that it only does it the first time it senses motion?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 06, 2015, 04:41:37 pm
You should use triggers where they are defined. Then you can use the sequence expression:

tStairLightsOn                When stair lights are on.
tNight                            When Day or night indicates Night

Then:
cDimStairLights          tUpStairsMotion and !tStairLightsOn and tNight and (!tStairLightsOn; tUpStairsMotion)


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on June 06, 2015, 09:24:29 pm
You should use triggers where they are defined. Then you can use the sequence expression:

tStairLightsOn                When stair lights are on.
tNight                            When Day or night indicates Night

Then:
cDimStairLights          tUpStairsMotion and !tStairLightsOn and tNight and (!tStairLightsOn; tUpStairsMotion)


Thank you for your help. I have already read through all your guides but as you can see I am still not clear on when to use a Trigger and when to use a Device Property. Could you please elaborate on how to choose the right input?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 07, 2015, 08:36:42 am
Triggers have  binary state ... they are only TRUE or FALSE.

Variables are used when the value can be more that TRUE or false ... i.e. the DIM level of a light, the Temperature of your house, ...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on June 07, 2015, 09:49:47 pm
Triggers have  binary state ... they are only TRUE or FALSE.

Variables are used when the value can be more that TRUE or false ... i.e. the DIM level of a light, the Temperature of your house, ...

that helps, thanks


Continuing with my Stair Lights project I want the lights to turn off if there is no motion detected for 30 minutes. I have given a stab at this below. This is a difficult one to test so can you tell me if my logic is correct and if I implemented it in a way that it will work?

Logic I used:
- Check the time the motion sensor was tripped
- compare the time to now
- if the time is > 30 minutes turn off light

I am attaching my reports, can you please tell me if i implemented this correctly?

thanks

Joe


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 07, 2015, 10:41:56 pm
There are other ways to do this ...

1)  Use Sequence Expression with NOW
       tStairLightsOn and (tStairLightsOn; NOW > 30:00)

2)  Use Sequence Expression with Self Started Trigger
       
      Create timer  tAutoOff    On  - Self Retrigger, Off interval of 30:00 minutes;
     
      Fiirst of two conditions:

      cLightTurnedOn -    tStairLightsOn
                            Action, using Advanced Tab, Select PLEG device, Action is StartTimer, Timer Name is tAutoOff

      Second of two conditions:
 
      cAutoOff              tStairLightsOn and (tStairLigjhsOn; !tAutoOff)

     

 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on June 08, 2015, 02:12:53 pm
There are other ways to do this ...

1)  Use Sequence Expression with NOW
       tStairLightsOn and (tStairLightsOn; NOW > 30:00)

2)  Use Sequence Expression with Self Started Trigger
       
      Create timer  tAutoOff    On  - Self Retrigger, Off interval of 30:00 minutes;
     
      Fiirst of two conditions:

      cLightTurnedOn -    tStairLightsOn
                            Action, using Advanced Tab, Select PLEG device, Action is StartTimer, Timer Name is tAutoOff

      Second of two conditions:
 
      cAutoOff              tStairLightsOn and (tStairLigjhsOn; !tAutoOff)

     

unless I am not understanding this correctly, wouldn't it turn off the lights 30 minutes after they were turned on? i want the motion sensor to be the trigger (30 minutes of inactivity). how would I change this?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 21, 2015, 06:01:02 pm
Alcon,

After looking over the PLEG Basics PDF it is a good resource, but..  one has to understands how, what and when to actually populate the PLEG device. I took the "Example - Simple Motion-Triggered Light" and attempted to develop the actual steps in order to accomplish the abbreviated example (below)

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
AutoOff    Turn Light off
AutoOn    Turn Light on
KeepOn    PLEG StartTimer timerName=Timer

Procedure:
Look in your Devices Tab and verify that you have a PLEG device available (would normally be in the "No Room" items area. If there is no PLEG device go to "Apps"=>"My apps" and verify that you have the PLEG plug-in installed. Locate the "Program Logic Event Generator" and select the "Details" Select "Create another" you should get a message that a device was created. Go back to the "Devices" tab and locate the newly created PLEG Device.
Select the PLEG Device. Change the "Device name" to something that makes sense to you. Select the Inputs tab (top green bar). You should be able to see a sub bar with "Triggers", "Schedules", "Device Properties" and "My Modes".

Triggers

1.   LightOn Trigger
a.   Select the "Triggers" Tabs, you will be presented with a drop down "Please select a device" Select the Light that you?re going to turn on, Change the "Name for this trigger:" from "t1" to "LightOn".
b.   Select the "Event type:" via the drop down selection and select "a device is turned on or off"
c.   Select the "Which mode" via the drop down selection and select "Whenever Device is turned on"
d.   Depress the Accept button "gray located upper right". Congratulation you've created your first PLEG trigger.

2.   Motion Trigger
a.   Select the "Device:" via the drop down selection and select "presented with a drop down Please select a device" Select the Motion Detection device that you're going to use to detect motion, Change the "Name for this trigger:" from "t1" to "Motion".
b.   Select the "Event type:" via the drop down selection and select "a device is turned on or off".
c.   Select the "Which mode" via the drop down selection and select "Whenever _Device_Name detects motion whether armed or disarmed".
d.   Depress the Accept button (gray located upper right).

3.   ItsNight Trigger
a.   Select the "Device:" via the drop down selection and select "presented with a drop down Please select a device" Select the Day or Night device that you're going to use to detect Day vs Night state, Change the "Name for this trigger:" from "t1" to "ItsNight".
b.   Select the "Event type:" via the drop down selection and select "day or night has arrived".
c.   Select the "Which mode" via the drop down selection and select "Device indicates Night time".
d.   Depress the Accept button (gray located upper right).

Schedules

1.   Timer Schedules
a.   Select the "Schedules" Tabs, you will be presented with a "Create" button, depress the Create button. Change the "Name" from "s1" to "Timer"?.
b.   Select the "Start type" via the drop down selection and select "Self Retrigger".
c.   Select the "Stop type" via the drop down selection and select "Interval".
d.   Select the "After" and input "00:05:00".
e.   Depress the Accept button (gray located under "Random Off Delay").

Conditions

1.   AutoOn Conditions
a.   Select the Conditions tab (top green bar). You should be able to see an "Add Row" button. Depress the "Add Row"
b.   Change the "Condition Name" from "c1" to "AutoOn".
c.   Select the "Edit" Button and either enter the text statement or use the radio buttons below to input with the blue edit area the following "!LightOn and ItsNight and Motion and (!LightOn; Motion > 30)". Depress "OK" to save. (Pay attention to the color coding of your condition text it should be blue(known Variable) , green(operator) and light blue (literal) if its red or pick check your statement to ensure that you correct).

2.   KeepOn Conditions
a.   Select the "Add Row" button. 
b.   Change the "Condition Name" from "c1" to "KeepOn".
c.   Select the "Edit" Button and either enter the text statement or use the radio buttons below to input with the blue edit area the following "(LightOn and Motion and (LightOn; Motion)) or AutoOn'" Depress "OK" to save.

3.   AutoOff Conditions
a.   Select the "Add Row" button.
b.   Change the "Condition Name" from "c1" to "AutoOff".
c.   Select the "Edit" Button and either enter the text statement or use the radio buttons below to input with the blue edit area the following "LightOn and !Timer and (LightOn; !Timer) and (!LightOn; LightOn > 10)". Depress "OK" to save.

Actions

1.   AutoOff Actions
a.   Select the Actions tab (top green bar). you will be presented with a drop down "Make a selection"
b.   Select "AutoOff" => "Edit" => "Immediate" => "Control"
c.   You will be presented with a drop down "Please select a device" Select the Light that you're going to turn off,
d.   Select "Add Device"
e.   You should see the Device you selected (left side) and Action of the Device (ensure that it is set to "ON" state) (Right side)
f.   Select the "Save" button

2.   AutoOn Actions
a.   Select "AutoOn" => "Edit" => "Immediate" => "Control"
b.   You will be presented with a drop down "Please select a device" Select the Light that you're going to turn off,
c.   Select "Add Device"
d.   You should see the Device you selected (left side) and Action of the Device (ensure that it is set to "OFF" state) (Right side)
e.   Select the "Save" button

3.   KeepOn Actions
a.   Select "KeepOn" => "Edit" => "Immediate" => "Advanced"
b.   You will be presented with a drop down "Please select a device" Select the PLEG device that you're creating,
c.   Select "Add Device"
d.   You should see the Device you selected (left side) and Device Action/Arguments of the Device (Right side)
e.   Under the "Device Action" You will be presented with a drop down "Please select an Action" Select "StartTimer".
f.   Under the "Arguments" sub selection "timerName" type "Timer"
g.   Select the "Save" button
h.   Depress the "Reload Luup" which should run with no error messages posted in the VERA status (Light blue bar at the top of screen)
i.   Depress the "Back" you should be back to the Devices tab.

Congrats you've completed your first Motion based PLEG, I hope this help those of us that are Newbie and/or not necessarily familiar with Luup structure/logic.  :D

** One observation is that folks have to wander through all the various threads to glean other peoples PLEG solutions, it would be nice if there was a library of the various PLEG solutions that one could go to, re-use and learn the various solutions that are out there. I think then for those of us who are not necessarily program savoy could use examples to help in the development of PLEG devices for their particular needs.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 22, 2015, 12:18:52 am
Quote
One observation is that folks have to wander through all the various threads to glean other peoples PLEG solutions, it would be nice if there was a library of the various PLEG solutions that one could go to, re-use and learn the various solutions that are out there. I think then for those of us who are not necessarily program savoy could use examples to help in the development of PLEG devices for their particular needs.
The intention for the  Examples Child board was for sharing user supplied solutions solving various problems.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 22, 2015, 10:14:26 am
Richard,
What I was implying is the same as what was done for "Conditional Scene Execution: Some Examples" it was a convenient place to get to working code examples. Whilst trolling through the child boards that was not always the case for a number of problems presented. Surely you must have/be using a number of solutions that would be useful for PLEG users at large? I for one would welcome any help especially developing condition statements. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 22, 2015, 10:28:32 pm
Question when I look at the following conditions statement both have greater than numeric values 30 and 10 respectably, how does PLEG know that the 30 is seconds and 10 is minutes? I know that within the Schedules one can input HH:MM:SS (00:10:00) for 10 minutes within the time inputs but not sure how the condition statement handles the values? Any help would be greatly appreciated. Mike

Conditions
AutoOn !LightOn and ItsNight and Motion and (!LightOn; Motion > 30)
AutoOff LightOn and !Timer and (LightOn; !Timer) and (!LightOn; LightOn > 10)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 23, 2015, 08:44:08 am
They are both seconds!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 23, 2015, 10:13:36 am
Richard,
Thanxs, so.. if one wanted to have the condition be minutes I'm assuming that the syntax would be 30:00 and 10:00?

Never mind... It helps for one to look at the PLEG Basics PDF, I see in the LightOn example a 1:00. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 24, 2015, 01:57:05 am
  10    is 10 seconds.
  10:00  is 10 minutes.
  10:00:00  is 10 hours.

   120 is 2 minutes:
   120:00   is 2 hours
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 24, 2015, 12:47:01 pm
Richard,

Thanxs for comeback, I did not realize that the second example of 120 seconds was valid but it makes sense. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 28, 2015, 01:17:16 pm
Richard, PLEG question. I would like to create a talking clock (TTS via Sonos) I thought I could create a schedule that would trigger on the hour (clock time) and/or half hour interval and have it say time (or what ever) via a Lua snip it. I had originally set up a scene with a hourly timer that works however it seems to trigger at different times depending on when the scene was saved or if VERA has had power interruptions. Do you have any idea's and or potential solutions, I did look the virtual clock plug-in which by the way should be relabeled as "virtual alarm clock" but it does not allow for more than one alarm. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 29, 2015, 01:23:22 pm
In PLEG  ... if you do an interval timer (every 15 minutes, 30 minutes, or Hourly) it will ruin AT the correct time. In PLEG if  24 Hours divided by the interval is an integer value it will always run as expected.

In Vera for scenes or PLEG for intervals that do not meet the above condition (i.e.  1:13) , the interval is always from the time that Vera is restarted.   

So use PLEG instead of a Scene.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 29, 2015, 02:21:01 pm
Can you provide an example? Looking at PLEG Basics, I see discussion re #Now and would think that the following should work, your thoughts

Speaktime (#Now> 15:00)

Now looking at the above sequence I believe that if the "Now" time is 15:05 then this would speak at 15:20 instead of 15:15 any help would be greatly appreciated. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 29, 2015, 05:03:55 pm
Create a PLEG Schedule named: Interval

It's on type is Interval 15:00 minutes
You do not need an off time.

A condition:

SayIt       Interval 
Turn repeats on.

For the action of SayIt ... using LUA

 local Time = os.date("%I:%M")
 luup.call_action(....      Time)

The above formats the time as HH:MM
For options on how to format the time for speaking see the following:
   http://www.lua.org/pil/22.1.html
See the Sonos plugin for the appropriate arguments to call the Sonos Say actiion,


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on June 29, 2015, 05:17:45 pm
Richard,
Many thanxs, I will work this later this evening..

Update: Had a chance to work with your recommendation and attached both my Report and Status for your review and suggestions.

Update II: Solutions works great, now have a working Talking Clock that chimes every 30 minutes. A request from my "significant other" to only have time reported from 8:00 am to 11:00 pm and be silent during the sleeping hours. I will post the update files once tested Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 30, 2015, 11:22:27 pm
Try the following in your LUA:
Code: [Select]
local tod = os.date("*t")
local msg
if (tod.min == 0) then
   msg = string.format("The time is %d o clock", tod.hour)
else
   msg = string.format("The time is %d past %d o clock", tod.min,  tod.hour)
end
luup.call_action(LS_SID, "Say", {Text = msg ,Volume=60}, AV_DEV)

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sasaba on July 01, 2015, 01:50:27 pm
I am so sorry if this question has been answered but can't come up with a search that gives me a narrow set of responses and there is so much out there on PLEG.

I have a condition that is evaluating the status of several other conditions by "OR" (C1 OR C2 OR C3) statements and has the "REPEAT" box checked so that several later conditions will know if one of these conditions has gone true (does not care which one only that a new one has gone true). This worked fine until I added a condition with "NOW" in it. There is now an automatic re-eval of all conditions every min. (my understanding is that is what should happen). My understanding was also that a condition would only re-eval if it includes a term that has changed since the last eval, but now my condition that has the "REPEAT" box checked is re-evaluating true every min. if one of its terms is true, even if it the term has not recently changed (i.e. since the last NOW 1 min. cycle). Does checking the "REPEAT" box over ride the rule that a condition will only be evaluated if it includes a term that has changed?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on July 01, 2015, 02:07:54 pm
Try the following in your LUA:
Code: [Select]
local tod = os.date("*t")
local msg
if (tod.min == 0) then
   msg = string.format("The time is %d o clock", tod.hour)
else
   msg = string.format("The time is %d past %d o clock", tod.min,  tod.hour)
end
luup.call_action(LS_SID, "Say", {Text = msg ,Volume=60}, AV_DEV)

Richard,
Thanxs for the come back, wouldn't I have to add the first 3 lines following above your suggest LUA;

Code: [Select]
url = require("socket.url")
local AV_DEV = 233
local LS_SID = "urn:micasaverde-com:serviceId:Sonos1"

local tod = os.date("*t")
local msg
if (tod.min == 0) then
   msg = string.format("The time is %d o clock", tod.hour)
else
   msg = string.format("The time is %d past %d o clock", tod.min,  tod.hour)
end
luup.call_action(LS_SID, "Say", {Text = msg ,Volume=60}, AV_DEV)

as it identifies the AV_DEV device? Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 01, 2015, 10:45:32 pm
The time stamp of NOW changes so every condition that contains it is reevaluated.

The LUA code was just a fragment.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on July 01, 2015, 11:14:43 pm
OK Richard, I'm being dense this evening ;) I'm not sure of what your last message meaning is trying to imply for the LUA challenged..(me)  Am I missing and/or should I be changing something in my last LUA example? Mike

Update: My Bad, I did not realize you were responding to @sasaba
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sasaba on July 01, 2015, 11:51:35 pm
Thee to stamp of NOW changes so every condition that contains it is reevaluated.

The LUA code was just a fragment.


I am assuming the comment about the time? stamp changing applies to my previous post and the other to the post after mine. The condition that I am concerned about gettting re-evaluated when no term has changed does not include a "NOW" element only other conditions before and after this condition.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 01, 2015, 11:58:51 pm
Every condition is evaluated when NOW fires every minute. But only conditions that reference NOW or a condition that references NOW, can have their actions run.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sasaba on July 02, 2015, 12:29:39 am
Every condition is evaluated when NOW fires every minute. But only conditions that reference NOW or a condition that references NOW, can have their actions run.

OK, I understand that but in my case I have a condition with "REPEAT" checked that does not include "NOW" and does not fire any actions but if it re-evaluates true with cause a condition down stream to be true and fire an action. In my case the first condition will end up being true and fire that later condition but when NOW re-evaluates the first condition re-evaluates true even though none of its terms have changed and fires the future condition again. Before I had NOW in any of the other conditions if anything else happened (triggers, schedules, parameter changes) that resulted in conditions being re-evaluated that 1st condition that I am concerned about would not re-evaluate true again and fire the down stream condition unless a term in the condition itself changed. I don't know if I am making myself clear. I have neglected so far to try and include the PLEG as it is fairly complex (at least for me) but can do that if you would like.

By the way, tank you very much for developing this tool as as far as I am concerned it is the main tool that makes Vera worth putting up with the other ongoing problems that it has had. And I appreciate all the time you seem to put in supporting PLEG.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sasaba on July 02, 2015, 01:48:01 am
Just realized that the downstream condition did have a NOW in it which makes it re-evaluate even though the 1st condition status did not change, however it re-evaluates to a new value not because any term changed but because the time stamp on the 1st condition changed even though none of its terms or its value change. Below are some snippets which I hope show what I am talking about

Code: [Select]
Condition Name       Repeat    Condition Expression
cLauries_Alone         no          cLauries_Home AND cSteves_Gone AND cGuests_Gone AND cOthers_Gone

cSomeones_Home    yes         cSteves_Home OR cLauries_Home OR cGuests_Here OR cOthers_Here

cDisarm_Stay          No           pAlarm_Mode eq "Stay" AND ((cSomeones_Home AND (pAlarm_Mode;cSomeones_Home)) OR (tDisarm_Arm_Button AND (tDisarm_Arm_Button;Now<1:00)))

cArm_Stay              No           pAlarm_Mode ne "Stay" AND ((cLauries_Alone AND (pAlarm_Mode;cLauries_Alone)) OR (!tDisarm_Arm_Button AND (!tDisarm_Arm_Button;Now<1:00)))


Action Condition         Action
cSomeones_Home       No action

cDisarm_Stay              pAlarm_Mode changed to Disarm

cArm_Stay                  pAlarm_Mode changed to Stay


So what happens is that when cLauries_Alone evaluates to true the cArm_Stay is true and alarm mode is changed to stay but then 1 min. later cDisarm_Stay is re-evaluated and because the cSomeones_Home time stamp is now changed (even though no terms change but it remains true) after the pAlarm_Mode time stamp it re-evaluates true and alarm mode is set back to disarm. Before the NOW expressions were put in (in order to allow manual change of arm mode using minimote scene controller) the time stamp on cSomeones_Home condition would not change unless a term changed (cSteves_Home, cLauries_Home etc).

So 1st question, am I understanding this right and 2nd question is this what is supposed to happen? It seems like the cSomeones_Home time stamp should not change just because of the NOW's in other conditions but only if there was a NOW in that condition?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 02, 2015, 11:17:24 pm
You should use triggers where they are defined. Then you can use the sequence expression:

tStairLightsOn                When stair lights are on.
tNight                            When Day or night indicates Night

Then:
cDimStairLights          tUpStairsMotion and !tStairLightsOn and tNight and (!tStairLightsOn; tUpStairsMotion)


Thank you for your help. I have already read through all your guides but as you can see I am still not clear on when to use a Trigger and when to use a Device Property. Could you please elaborate on how to choose the right input?

Hi Richard

the above was working pefectly but lately I have noticed that if I manually turn on the light from the bottom of the stairs, when I walk upstairs I trip the motion sensor and the lights will dim down to the dimmed state. I though the last argument (in parenthesis) would prevent that from happening, but it is not, what do I need to change?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 03, 2015, 12:10:01 am
Do you have an instant on Switches for tStairLightOn ?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 03, 2015, 01:19:10 am
Do you have an instant on Switches for tStairLightOn ?

Not sure I understand the question
This is a 3 way dinner switch
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 03, 2015, 09:49:37 am
If the switch does NOT support instant status, then Vera does NOT know that you changed the switch manually until a much later time (Can be 5 to 10 minutes later).
This makes automation based on the you MANUALLY changing things difficult/impossible.

In your case you MANUALLY turned the switch on ... But Vera did not get notified right away ... But when you tripped the motion
sensor the following was true:

     tUpStairsMotion and !tStairLightsOn and tNight and (!tStairLightsOn; tUpStairsMotion)

This is true because VERA did NOT get the messages that the Stair light was on yet!

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 03, 2015, 12:12:40 pm
If the switch does NOT support instant status, then Vera does NOT know that you changed the switch manually until a much later time (Can be 5 to 10 minutes later).
This makes automation based on the you MANUALLY changing things difficult/impossible.

In your case you MANUALLY turned the switch on ... But Vera did not get notified right away ... But when you tripped the motion
sensor the following was true:

     tUpStairsMotion and !tStairLightsOn and tNight and (!tStairLightsOn; tUpStairsMotion)

This is true because VERA did NOT get the messages that the Stair light was on yet!

Thanks for the explanation.
the switch I have is a GE 12724 Dimmer Switch
http://www.amazon.com/gp/product/B006LQFHN2?psc=1&redirect=true&ref_=oh_aui_detailpage_o08_s00

how can i know if it supports instant status? or should I just assume it doesn't based on the behavior?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 03, 2015, 01:38:52 pm
You might PM ZWaver he s quite knowledgeable about Zwave devices.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 03, 2015, 01:47:55 pm
You might PM ZWaver he s quite knowledgeable about Zwave devices.

Thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RHINESEL on July 03, 2015, 10:19:26 pm
I believe only the Leviton Vizia RF and Cooper switches support instant status.  Hence them being more expensive too.

If memory serves me right there is a work around to make other switches "act" like instant status but I'm not sure what the process is.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on July 04, 2015, 11:22:37 am
Question,
I was trying to establish a schedule the would turn on at 7:58 am and stop at 11:02 pm every day. looking at my status for this morning (last on indicates 5:16) suggests that the start/stop values are timer duration values rather than actual times. If I try to use absolute, I'm able to enter start/stop times but am presented with having to choose a month and dated value,  I would have thought I could enter a "*" wildcard as what is available for the year drop down, am I missing something? guidance would be appreciated, thanxs in advance. Mike

Schedules
Name         On Type   On Time   On Days   Random On Delay   Off After Type   Off Time   Off Days   Random Off Delay   State   Last On                            Last Off
sClockOn     Interval    07:58:00               None                     Interval            23:02:00                None                     true     2015-07-04 05:16:00.100    0
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 04, 2015, 12:00:46 pm
You might PM ZWaver he s quite knowledgeable about Zwave devices.

Thanks

So after reading through a few threads I believe my switches do not support instant status.
I have a way to accommodate around this but I'm having a hard time programming it:

- I have a PLEG schedule that turns off all lights at 10pm
- I would like the motion sensor to turn on the stair lights full brightness if it is before 10pm
- I would like the motion sensor to turn on the stair lights to 20% brightness if it is after 10pm

I tried setting a variable using the device variable plugin that changes the dim level from 100 to 20 when the lights off schedule runs. then changes it back the following morning. I was not very successful at making it work.
guidance greatly appreciated

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RHINESEL on July 04, 2015, 01:07:45 pm
I'm very much an amateur (only made one simple PLEG) so take this for what it's worth... not much.

I see a condition to turn lights to dim after night.

I see a condition to turn the lights to 100 before night.

I see a condition to turn the lights off at 2200 (10 pm).

I see nothing in your logic about full or dim before or after 2200.  You're using day/night.  I also don't understand using properties for pDayOrNight.  Why not use a schedule?  It seems to me like your times are all messed up.

Also, there is nothing about a motion sensor turning the lights on to 100.  I assume you're using front door unlock for this?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on July 04, 2015, 01:21:49 pm
After investigating a little more I've noticed that absolute time can also be establish as part of the Conditions as listed below

Code: [Select]
cSayIt    sInterval60 and (07:58:00;sinterval60;23:02:00)
Where sInterval60 is hourly counter and will become true if the time is between 07:58 am to 11:02 pm and then should be false afterwards.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 18, 2015, 01:59:42 pm
how do i control the Device Variable Plugin using PLEG?
I can add it to an action but cannot set any of the variables
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on July 31, 2015, 02:07:12 pm
how do i control the Device Variable Plugin using PLEG?
I can add it to an action but cannot set any of the variables

Never mind the above, I just saw that the setting PLEG as the target of an action allows me to set a variable.
Can someone walk me through this? I tried to do it but can't seem to get it right

1- I wan to set a variable "DimLevel" to = 100 when it is night (I already have a condition that turns on the outside lights at this time, I just want to ad it to this)

2- I want to set the variable "DimLevel" to = 20 when the lights turn off at 10PM (I already have a condition that is turning off the lights every night)

2- I want to use the variable "DimLevel" as the value for my Light Dimmer when my motion sensor Is tripped. (I already have a condition that does this to a pre-set dim value)

help is much appreciated
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 01, 2015, 08:41:37 am
It sounds like you are using the Advanced option on the action editor.

Change from Advanced to Control
Then you can set the Light Level to the appropriate level just like you would do on the Vera Dashboard.
You can go back to Advanced if you want to see what actions are actually getting fired.

There are different actions for turning on a light and setting it's dim level.  But if you set the level ... Vera will automatically turn on the light.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on August 02, 2015, 12:53:46 am
It sounds like you are using the Advanced option on the action editor.

Change from Advanced to Control
Then you can set the Light Level to the appropriate level just like you would do on the Vera Dashboard.
You can go back to Advanced if you want to see what actions are actually getting fired.

There are different actions for turning on a light and setting it's dim level.  But if you set the level ... Vera will automatically turn on the light.

What in trying to do is have two different dim settings for the same action depending on the status of a 3rd device.
If I set the dim level using the control option, the dim will be a static value instead of variable.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 02, 2015, 10:23:36 am
When you have problems post your PLEG status report so we can see exactly what you are doing.

You need to use the advanced TAB, On UI7 also need "Customize Arguments".
The reason for the latter is that normally a DIM command takes a number, but you want to put an expression there that will evaluate to a number later.

Then the value of the dim will be something like:

   {(DimLevel)}
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on August 09, 2015, 03:13:05 pm
When you have problems post your PLEG status report so we can see exactly what you are doing.

You need to use the advanced TAB, On UI7 also need "Customize Arguments".
The reason for the latter is that normally a DIM command takes a number, but you want to put an expression there that will evaluate to a number later.

Then the value of the dim will be something like:

   {(DimLevel)}

Thank you Richard
 I am attaching a status report. What am I doing wrong?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 09, 2015, 09:03:03 pm
How about a clue as to what is not working properly!

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on August 10, 2015, 03:22:22 pm
How about a clue as to what is not working properly!

Sorry, I thought I had included a description of the problem

I am trying to set the StairLights Dimmer to a variable level. The variable level is set as a result of other actions (ie- When the cLightsOffAt10PM Condition should set the Dim Level to 20. The cResetDimmers Condition should set the Dim Level to 100)

I currently, I am trying to use a Device Variable plug in to handle this variable. If i enter a Variable Name under the Custom Arguments, the system does nothing. If i enter a fixed value instead, it works properly, so I know it is the variable that is causing it to fail.

 I don't know if (or how to) use the PLEG device variable to do it instead.

I am re-attaching the report.

thanks for your help

Joe
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: mntlvr on August 14, 2015, 01:43:16 pm
I need to add either a "wait", "delay", "pause" in the LUA section of PLG to wait for the action on the device to happen first then the LUA event to take place.
Is this possible?
I need for
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "0", 124)"
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "0", 128)"
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "0", 139)"
to happen xx sec after the device is turned on
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "1", 124)"
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "1", 128)"
"luup.variable_set("urn:micasaverde-com:serviceId:SecuritySensor1", "Armed", "1", 139)"
and xx sec after devices are turned Off
Can you help?
This is on a vera3 running 1.5.622
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 14, 2015, 05:59:25 pm
Why are you even using LUA for this ?
You can do what you want with delayed actions.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on August 16, 2015, 06:13:23 pm
Hi Richard

Still having a hard time figuring out how to use a variable as a set point for my lights.
I have various conditions that turn on my stair light (opening the door, tripping the motion sensor, etc.)
I would like the light to turn on to a diferent brightness depending on the state of my system. I am trying to use a PLEG variable "{(DimLevel)}" to define this. However it doesn't seem to work propertly.
what am I doing wrong?

I have attached the reports.
thanks
grrgold

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tellfic on August 19, 2015, 11:01:01 am



   AutoOff Actions

e.   You should see the Device you selected (left side) and Action of the Device (ensure that it is set to "ON" state) (Right side)


   AutoOn Actions

d.   You should see the Device you selected (left side) and Action of the Device (ensure that it is set to "OFF" state) (Right side)



Hi

I am new to PLEG and it's a great solution to VERA's scene creation. Excellent Job.

I have managed to setup a few PLEG's using the examples from the PLEG basics and most worked amazingly well.

Unfortunately I am struggling with the Simple-Motion-Triggered Light the Off condition trigger is not working so the lights do not switch off!! I have tried all sorts deleting and re-entering information including Reload luup and starting

I have attached the reports.

cAutoOn Switching the light on works fine.

cKeepOn again works fine
 
cAutoOff The lights won't switch off the condition is not being triggered

What am I missing?

Regards

Atkins

PS: I have noticed that MNB's example for the actions. AutoOff actions the lights switch is set to ON and vice versa for AutoOn which is OFF. Is that correct.
I tried that and didn't work as the lights would not switch on aftre the motion sensor trigerred.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 19, 2015, 05:45:06 pm
You should post the "Status" report ... there is a lot we can tell by seeing the current state of inputs and conditions as well as when they last transitioned.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tellfic on August 19, 2015, 06:06:54 pm
Thanks for responding

I have attached status reports at various stages , hope that gives more information

Atkins
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: minimoibientot on August 20, 2015, 10:34:49 am
Hi

a question :
I have an "expression"; in "conditions : Go"; which is empty
because it is launched by a scene (PLEG1 / RunAction / ConditionName: Go)

by cons, I get: state = null
and the "condition Go" is never true nor false
and therefore never launched.

it is not possible to do that?

Thank you
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: East on August 24, 2015, 03:44:37 pm
I've went trough the tutorial posted in the first post, but I can't managed to get this work.

I'm using the Harmony Hub with the Harmony plugin. I want to use PLEG to activate a scene based on sunset and CurrentActivityID of the Harmony Hub.

For inputs I've define:
- Schedules: named it "Dark" based on sunset and sunrise
- Device properties: Named it "CurrentID" monitoring device variable CurrentActivityID

Conditions (both on repeat):
- Name "HTon" - condition: CurrentID eq 15075848 or CurrentID eq 15076217 or CurrentID eq 15075914 or CurrentID eq 15075629
- Name "HTonSunset" - condition: Dark and HTon

Actions:
HTonSunset starts immediately set target on several lights.

The trigger only seems to work when the CurrentActivityID was set to one of the values above before sunset. Can someone please tell me what I'm doing wrong?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 24, 2015, 06:56:07 pm
PLEASE POST YOUR PLEG STATUS REPORT!

There are plenty of Free PDF printers that allow you to save the content of a browser window to a PDF file!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: East on August 25, 2015, 03:26:17 am
Hereby the status report.

I found out that the condition for HTon is working properly. When I change the activity to one noted in the expression, the state becomes True.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 25, 2015, 12:00:25 pm
You need to Evaluate Hton before you use it in  HTonSunset.

In the Condition editor ... use the "+" or "-" buttons near the condition name to change the order.
Title: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: legend99 on August 28, 2015, 03:35:26 pm
I am having a hard time with a PLEG.

The gist of it is this:

 - The front door opens
 - Runs a lua script that turns on for motion for camera
 - 30 seconds after motion starts it sends lua script to turn off motion for cam

What is happening is that I can not get the motion off to be true. It happened once and could not happen again. Any thoughts.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 28, 2015, 03:52:37 pm
Does the motion sensor show tripped on the Vera dashboard ?

You should always post your status report when you have problems.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: legend99 on August 28, 2015, 05:00:51 pm
Sorry Richard. Attached is first file next post has the second file. Yes the vera panel recognizes that the door is open. This is part of a much larger PLEG, but this is the only part that I can not get to work. I have tried deleting it and redoing it and continue to have the same problem of not executing the motion off after 30 seconds. Changed it to 90 seconds same thing. On another PLEG I have a thermostat that switches off after 2hours of on time and the pleg works flawlessly.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: legend99 on August 28, 2015, 05:05:42 pm
Second File
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: vituz on August 31, 2015, 12:55:18 pm
Hi!

I have copy/pasted exactly the alarm setting described at page 27 of the basic instructions manual, as it described what I really wanted to do.

However I get an error (please see screenshot).

Can you please advise?

Many thanks!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 31, 2015, 02:53:36 pm
It's telling you there is no definition for "Tripped"
Perhaps you mean "DoorTripped"
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: vituz on August 31, 2015, 04:13:31 pm
Hey thanks for the reply!

I found the error, and it's a stupid one... basically I used  ? instead of ". Once I corrected that it worked... I still have to test... however I was wondering whether I need to use the virtual switch... ideally it should be enough to tell the system that the alarm is armed when in Away mode... but I'm really new to this so I'm really not sure...

Thanks for the support. This looks like a great community. (also I just bought a license for PLEG)  ;D

Cheers,
Vituz
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on September 24, 2015, 11:17:37 pm
I am having a problem with one of my motion sensors. I have 2 motion sensors, each set to control one light switch.
The Stairs Motion Sensor controls the stair lights
The Entry Motion Sensor controls the enry lights

they are each set to turn on the lights upon detecting motion, and turn off after motion is no longer being detected.

They both respond properly to motion (turning on when motion is sensed) but only the Entry Sensor will turn off the lights when motion is no longer sensed, the Upstairs Motioin Sensor will turn on, but won't turn off

I have checked the settings on both and I can't find any difference... any ideas?

Just as additional info, the Entry sensor is an Aeon multi sensor, the Upstairs sensor is a Fibaro multi sensor. not sure if that makes a diference.

 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: birchey on October 06, 2015, 03:47:52 pm
Looking at the trigger for UpstairsNoMotion you have this set to no longer picking up movement not sure why you have both states as triggers when one will do.

As the trigger for motion is working on tUpstairsMotion try the following in the condition for  cNoMotionStairs

tStairLightsOn and !tUpstairsMotion

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on October 06, 2015, 04:53:13 pm
Looking at the trigger for UpstairsNoMotion you have this set to no longer picking up movement not sure why you have both states as triggers when one will do.

As the trigger for motion is working on tUpstairsMotion try the following in the condition for  cNoMotionStairs

tStairLightsOn and !tUpstairsMotion

I will give that a try and see how it works out... thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: duhlin on November 23, 2015, 07:41:12 am
Trying to set pleg to switch homemode, to set away with double click on switch and home with a pir.
The problem is that i just got one to work at time, so if it working to set mode away it wont trigger so it change back to home, when pir detect motion, and the opposit, it looks like just the first action i enter will work

any solution

sorry for my bad english.. :)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 23, 2015, 10:52:00 am
Post your PLEG status report ...
Also does your Light Switch support Instant status ?
To verify ... have someone change the light manually while you watch the dashboard. Does the Vera dashboard see the change withing a second or two ?
 

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: duhlin on November 23, 2015, 05:34:16 pm
hi again

no one have move the swithes i use a fibaro dimmer and a philio pir sensor. the input i used are mode1 and tvattms, and condition home1 to trigger away mode (just to get it to work) and hemma1 to set home mode,

thanks for the help


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 24, 2015, 12:07:24 am
That is not the "Status Report" and please post the PDF so we can read it.
I am not familiar with Fibaro dimmer ... so I do not know if it supports instant status ... please do the test I indicated to determine if this has instant status.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: duhlin on November 24, 2015, 01:14:55 am
Sorry my bad

Yes the fibaro dimmer have support for instant status.

attached a pdf with hopefully the status report.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 24, 2015, 10:01:05 am
It looks like it has detected the double On/Off at least once.
You may need to slow down your interactions Or Vera might not see all the transactions.
Turn On ... wait two or three seconds ... Turn Off wait two or three seconds ... Turn On

You can also turn on the PLEG log and see if Vera is seeing all of your changes from this device.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: duhlin on November 24, 2015, 11:05:21 am
The problem is not that pleg dosen?t see the action, but the only thing thats working is if i use the action home1 to set the housecode. If i put housecode 1 it will trigger it to homemode , if i set it to 2 it will trigger awaymode, regardless if i have conditoner set to trigger by the switch or the motion sensor. but i cant get i to trigger the action hemma to set it back to the opposite state.
So the problem is i can set it to awaymode but not get i back to home mode.

any clue?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on December 06, 2015, 01:32:15 am
Having a problem getting my door lock to triger a light to turn on.
I simply want the light to turn on if an valid key code is entered, and it is night time.
I think i did everything right but it doesn't seem to work

what am i missing?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on December 06, 2015, 12:03:47 pm
@grrgold, I use the following (see attached) which is working for me. Mike




Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: figgarro on January 05, 2016, 08:38:58 pm
Trying to setup up my thermostat to cycle the fan every hour for 15 minutes and then change the fan mode back to Auto, I'm stuck on how to get it back to auto.


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sasaba on January 08, 2016, 02:39:45 pm
I see two ways:

1) In the action for FanOn make a delayed action at 15:00 that sets the mode back to Auto
2) Make a new condition that is true when FanOn is false with a corresponding action that sets the mode to Auto
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: figgarro on January 08, 2016, 03:10:43 pm
I see two ways:

1) In the action for FanOn make a delayed action at 15:00 that sets the mode back to Auto
2) Make a new condition that is true when FanOn is false with a corresponding action that sets the mode to Auto

Thanks, I tried the delayed actions but it did not seem to work.  Hopefully I get sometime to play around with it this weekend.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: e50golf on January 14, 2016, 09:36:54 am
I am trying to disarm my DSC alarm, using PLEG, at a certain time of day.  I can setup the schedule and the condition, but when I try to set up the action: disarm the partition, I cannot enter the code number.  The Partition keeps returning to "0" in the code box.  What am I doing wrong?  Help would be very appreciated.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Andrew on January 17, 2016, 04:02:52 pm
Has anyone experienced problems (or had success) using PLEG to set the house mode, using the latest firmware? My condition triggers ok but the PLEG action to SetHouseMode=2 doesn't. It should switch from home to away but it stays in home.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: PeterBrown on March 07, 2016, 01:12:00 pm
Hi Richard,

Just starting to try Pleg and I am wondering which is best.

If I use Fanon = Lighton and (Lighton; NOW >5.00) this can turn on my fan after 5 minutes but does this use more or less CPU time than using a Pleg timer for the 5 mins. I understand that NOW causes an evaluation every minute but does it continue to evaluate after the condition has fired. If it does then is a pleg timer not better as this should only run once for the 5 mins and then the evaulation stops.
Also, is a timer the only way if I need a definite time or half minute for example.

I have read the guide and the examples but sometimes it is understanding the simplest parts that is the hardest.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on March 07, 2016, 03:38:23 pm
NOW is easier to use.

Timers are more accurate and efficient.

Event though NOW is less efficient, you should not be afraid to use it. Your Vera is usually 90+  % idle and it's not noticeable.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: integlikewhoa on March 07, 2016, 04:02:31 pm
I would say a timer is better in every way except for ease of use since with a timer you have to create it, start it, stop it and such. This sometimes takes 2 or 3 conditions plus a timer to complete the task. Where a NOW can be done with only one condition.

You can use now for 30sec. But like you already know a 30sec "now" can fire anywhere from 30sec to 1min 30sec depending on when it was last evaluated. So anything that you need done that can have a random time of around a min off you can use NOW. If you want something to be done right at a specific time and without waiting for up to a min over then you need to use a timer. 

All depends on how precise you want the 30 secs. For me if your asking about 30 secs you probley want a timer as 1:30 is 3 times the length of time and it's very possible it will take that long with a "NOW" condition. Things like 5min you probley are not very picky and a Now probley won't wont matter much if its 5min or 6min.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: PeterBrown on March 07, 2016, 04:26:32 pm
Thanks guys. I guess it is as I thought. If you want it accurate and efficient then take the effort and do it right or if you are not worried about too much accuracy, do it the easy way.
For simple fan control with delay on

Light on - Start timer
Timer ends - Turn fan on
Light off - Turn fan off and stop timer

3 schedules rather than two using NOW

Does this seem correct?

Richard,

Is NOW the same timestamp in every schedule (ie calculated once per cycle of all schedules in that PLEG) or is it calculated every time it appears. This is just out of interest.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on March 07, 2016, 06:57:21 pm
It has the same timestamp for evaluating all the conditions ...

It's equivalent to a 1 minute interval timer.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: PeterBrown on March 10, 2016, 07:48:29 am
NOW is easier to use.

Timers are more accurate and efficient.

Event though NOW is less efficient, you should not be afraid to use it. Your Vera is usually 90+  % idle and it's not noticeable.
Richard,
Out of interest, which way do you do it? With timers or using NOW?

I am always happy to follow the master
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on March 10, 2016, 08:01:17 am
I use both.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Mudd on April 04, 2016, 12:55:52 pm
Hi:

I am trying to use the example: "Set dimmer to level saved in VariableContainer". In the Device Properties, You have:
DimLevel  VariableContainer Variable 1.

My question: Is "VariableContainer" a plugin? If so, I cannot find it. Can I use "Multistring"?

Eventually what I want to do is use a virtual switch to turn on my porch light at about 50% at sunset. I can get it to work with a on/off switch, but when I use a dimmer and try to set the level to 50%. The light does not turn on.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 04, 2016, 05:34:03 pm
Variable container was the predecessor to MultiString ... And yes you can use it with PLEG
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 05, 2016, 12:55:53 pm
Good afternoon,
I'm just reading through the walkthrough, and I'm trying to wrap my brain around it.  It's been a long time since I did any sort of programming, and this is quite different than my days of Basic, Pascal, and C++.

I want to start off with something simple.  I'm running a Vera Plus, which I've only had since last Friday, and only got my Vista 20P alarm panel integrated yesterday.  I have a number of Window/Door sensors on my alarm panel, which, for whatever reason, Vera has categorized as motion sensors (tech support did that).  What I want to do, is have a trigger from my Front door sensor (Zone #09 - Front Door) is tripped open (condition 1), AND it's within 20 minutes of sunset (condition 2) OR less than 20 minutes after sunrise (condition 3), to turn on the entry way light.  Seems pretty straight forward, right?

How do I do this?

The next thing I need to do is more complicated, and involves the Geofencing, which may or may not work for two users.  I want to arm the my alarm panel  (action 1) if both myself and wife are away from home (condition 1), AND turn off all the interior lights (action 2).

Can someone please walk me through these?  Once I have a couple of examples on my system, I should be good to go.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 05, 2016, 01:25:39 pm
I suggest you implement a couple of the examples in the guide and understand those first.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 05, 2016, 02:33:40 pm
I suggest you implement a couple of the examples in the guide and understand those first.

I've tried the first one, as it's similar to what I want to do.  Is there a way to export what I've done to have you inspect the code?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 06, 2016, 12:13:30 pm
Use the Status Report on the control tab and print to PDF. Post the PDF.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 07, 2016, 02:36:18 pm
Here you go.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 07, 2016, 02:44:13 pm
As a minimum, the trigger containing "Whenever the Entryway is turned off" should be changed to "Whenever the Entryway is turned on"
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 07, 2016, 02:49:30 pm
Additionally, you will need to add Actions for all three conditions as indicated on page 24 of 29 in PLEG Basics.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 07, 2016, 02:53:00 pm
Additionally, you will need to add Actions for all three conditions as indicated on page 24 of 29 in PLEG Basics.

Yes, I can't figure out how to do that in U17
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 07, 2016, 03:05:21 pm

Basically,

Open PLEG.
Click the Actions tab.
Select Edit for the desired condition (for example AutoOn),
Select Immediate.
Select your device for your light and press Add Device.
Select the Control button.  Turn on your light.
Hit Save and so on ...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 07, 2016, 04:04:38 pm
Okay, got it.  So now is this correct?

Also, what is the advantage of using the "Day or Night" app vs scheduling it for daily, and using the sunrise/sunset scheduling options?  Doesn't it accomplish the same thing?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 07, 2016, 04:36:54 pm
Okay, got it.  So now is this correct?

For condition AutoOff, add an action to turn off the light.


Also, what is the advantage of using the "Day or Night" app vs scheduling it for daily, and using the sunrise/sunset scheduling options?  Doesn't it accomplish the same thing?


Since the Day or Night Plugin is also a switch, you can change it to force or test all of your automation logic in Day and Night mode.


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 07, 2016, 04:57:09 pm

Additionally, the Actions for Condition: KeepOn, needs to be revised:


Delete the existing action in Actions for Condition: KeepOn


Then using the Advanced tab in the Action editor, pick your PLEG from the device list.  Click add.


Then select StartTimer.


Then add the timerName.


Save and so on ....
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: tamorgen on April 08, 2016, 09:20:23 am
Thanks.  It's starting to make sense.  Hopefully I have it correct now.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BrianLBeaton on April 08, 2016, 09:42:20 am
Thanks.  It's starting to make sense.  Hopefully I have it correct now.


Your status report looks correct.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Mudd on April 09, 2016, 01:25:28 pm
I am experimenting with virtual switches and variable containers. What I want to do is have my porch light come on at 50% sunset for about 4hrs (I set it at 1hr for testing). I can set the level to 50%. When I play around with the Condition, I can get the light to turn on, but it won't turn off, or it won't turn on.
I am including the status, so someone can tell me what I am doing wrong.

Thanks.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: zant on April 14, 2016, 06:09:22 am
Hallo all,
I am very new on using PLEG en Vera in general.
I want to use my Minimote by short pushing a button to toggle a lamp on an on the second short push toggle is off.
I red a post form a member and want to try this in PLEG:

I have a minimote and a dimmable light.  I want to toggle it on and off. [I have it working great with Lua but moving away from all my scripts over to PLEG]

Input
Button_Pressed      Scene number 1 is activated

Device Porperties
Lamp_Status      Satus

Condition
LampOn      (Lamp_status; Button_Pressed) and (Lamp_status eq "0")   
LampOff      (Lamp_status; Button_Pressed) and (Lamp_status eq "1")

Action
LampOn      Turn on the lamp
LampOff      Turn off the lamp

It appears an issue with not being able to get status updates? I say this as the status report often errors out with ?error getting status of??


This dit not work for me but I think I am doing something wrong in this.
Please who can help me in this...
Thanks in advance..
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 14, 2016, 04:53:19 pm
If you add or rename an Input or condition it will not be available in a status report until you reload Vera.

Most edits in PLEG are not noticed until Vera restarts with the new definitions.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: grrgold on June 20, 2016, 01:28:42 am
Having a problem with my PLEG plug in. I have been using it without any issues for almost a year now.
Last week I upgraded my Vera Edge to a Vera Plus system. I transfered all my settings via the backup application from the Vera control panel and everything seems to be working fine.  Most of my scenes are running the same as before (both regular scenes and PLEG events) except for a couple:

1- I have a PLEG event that automatically locks my front door if it is left unlocked for longer than 5 minutes. This used to run in before but does not run anymore
2- I have a motion sensor that would turn on a dimmed light when you went up the stairs at night. This is conditional to 2 things, the light not already being on, and the system be set to "sleep" mode via a virtual switch. The scene is running (the lights dim) but it is not taking into account the 2 restrictions (the light dims even if the light was already on or the system is not on "sleep" mode)

Note that when i transferred everything my PLEG license did not transfer so I purchased a new one. I don't know if this has anything to do with it

thanks for any help I can get in troubleshooting. I am attaching the reports below.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on June 20, 2016, 10:02:16 am
You MUST upgrade the plugins ... when you restored your UI5 backup on UI7 ... you loaded UI5 version of software ...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: erkme73 on July 11, 2016, 10:47:40 pm
Richard, are the purchased licenses from one device transferable?  In other words, I had a number I bought for my Edge, which I've reset to factory and will likely never use again.  I'm now on the Plus, and have purchased the minimum number of Vera Alert and Pleg licenses to make it work, but wouldn't mind having the overhead from the previously purchased keys transferred over.   Is that inappropriate to ask?

ETA:
Woops... never mind.  I just read the first post of the original "license required" thread, where you clearly state the licenses are tied to a specific Vera.  No problem with that.  I am glad to continue to support your efforts.  Just didn't want them to go to waste.   Thx.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 12, 2016, 08:16:10 am
I do have an upgrade policy.

If you previously had N licenses and want to have N licenses on the new Vera than:

You purchase   N/3  rounded up to nearest integer
I will provide the  N - (N/3 rounded up to nearest integer) for free.

i.e.   
Previous Cnt (N)           You Purchase           Provided for Free
1                                  1                            0
2                                  1                            1
3                                  1                            2
4                                  2                            2
5                                  2                            3
...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Pedals2Paddles on July 12, 2016, 08:29:27 am
Does the sunrise / sunset based schedule option not work?  After i hit save, it reverts from sunrise/sunset to fixed midnight and midnight (00:00:00) for both times.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 12, 2016, 08:42:10 am
That is 00:00:00 relative to sunrise/sunset
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Pedals2Paddles on July 12, 2016, 09:41:24 am
I know.  Sorry, I left out the critical part: It's reverting to "a certain time of day", and that certain time ends up being whatever I entered for before/after sunset.  So lets say I make a schedule for at or after sunset by 00:10:00 and off before sunrise by 00:10:00.  I hit save.  It immediately changes both on and off to "a certain time of day", with the on and off times both being 00:10:00 from the before/after settings.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 12, 2016, 09:55:45 am
Sorry, not able to duplicate ... what Version are you running ?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Pedals2Paddles on July 12, 2016, 10:15:20 am
PLC was 8.11, updated to 8.13 yesterday. Behavior did not change.  PLEG is an always has been 8.11.  I hit update and it didn't change.  Is there a PLEG 8.13 that I need to do an uninstall/reinstall to force?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 12, 2016, 11:36:28 am
No That's the latest.
What browser are you using ?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dayfly on July 12, 2016, 11:40:34 am
Is there a new updated pleg basics manual for UI7 and the last version of PLEG ?

its hard to find the right manual and setup of the last version
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Pedals2Paddles on July 12, 2016, 12:16:20 pm
No That's the latest.
What browser are you using ?

Chrome at home. Firefox at work.  Same issue for both.  I've tried deleting a recreating the schedule, same thing happens.  Perhaps I should back up my PLEG, uninstall, and reinstall?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Miltos98 on July 22, 2016, 09:23:44 am
Hi,

I am new to Pleg and Luup, so please bear with me.

I have an SPC alarm system and the SPC gateway, which connects the alarm system to Vera by exporting through REST all alarm system properties as global variables.

I am trying to use Pleg to switch on the lights when the radar "on" property in the living room (G_SPC_ZONE_INPUT_10) is set to "OPEN".

I have entered a condition under UI7 which reads

luup.attr_get "G_SPC_ZONE_INPUT_10" eq "OPEN"

But I do always get nil as response.

The question is can I use luup code in a condition or how else can I use the global variable to trigger my action?

Thanks
Miltos

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: guykopel on July 28, 2016, 01:13:31 pm
I know.  Sorry, I left out the critical part: It's reverting to "a certain time of day", and that certain time ends up being whatever I entered for before/after sunset.  So lets say I make a schedule for at or after sunset by 00:10:00 and off before sunrise by 00:10:00.  I hit save.  It immediately changes both on and off to "a certain time of day", with the on and off times both being 00:10:00 from the before/after settings.

I have the same problem with sunrise/sunset scheduler.
Does anyone have a solutions for that?
(running PLEG 8.11, PLC 8.14, Vera plus firmware  1.7.2044. tried with Chrome, firefox, IE)

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Freddan101 on August 01, 2016, 12:17:55 am
I'm experiencing the sunrise/sunset issue as well...
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on August 01, 2016, 05:47:23 pm
The fix for this is pending MCV audit ... but they appear to be on Vacation ...

You can do the following to fix (Already documented in the forums)

1) Refresh the Browser
2) Edit the PLEG device
3) Advanced tab ... edit the Schedules variable.

Replace   XX:XX:XXs
With       XX:XX:XXt

If you edit the schedules again ... you will have to fix this again.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: poordom on September 07, 2016, 02:16:37 pm
Program Logic Event Generator (PLEG) is an amazingly powerful and flexible tool that can be used to implement almost any automation scenario on Vera. This forum has many examples of creative and ingenious PLEG applications. Once you learn to use PLEG, you will wonder how you managed without it - and why you didn't try it sooner!  ;D

PLEG Basics is intended to provide newcomers with an explanation of how PLEG works and how to use its many features. Each feature is described in detail with examples of how it may be used. The guide is in the form of a pdf document with bookmarks to help with navigation.

Edit: 24/01/2014 09:30 New version attached. Updated to include new features of PLEG V5.6
Edit: 29/01/2014 13:40 New version attached. Updated to include new features of PLEG V5.7
Edit: 12/02/2014 18:00 New version attached. Updated to include new features of PLEG V5.9
Edit: 05/03/2014 11:25 New version attached. Updated to include new features of PLEG V6.2
Edit: 29/01/2015 16:42 New version attached. Updated to include new features of PLEG V7.35

WOW!,

Thanks Rex,

It sure looks very interesting, I guess I will have to learn this program if I want to achieve, my goal.

I will most likely be a pain in the A. . for a while, I hope you will bare with me.

Dom
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garyd9 on September 16, 2016, 06:39:18 pm
BTW, this is a great guide.  I'm looking forward to seeing an updated version for the new v8 stuff, documentation on "Counters", and some of the schedule related functions (such as ToggleTimer() that seems to be a way for force a schedule to turn off early.)

Thank you - it was well worth the $6.

Take care
Gary
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 11:51:29 am
Hello

I have just tried to setup the Alarm example as shown on page 27 of the PLEG Basics user guide.

However when I reload the LUA I am getting this message:

Home Security[86] :   Alarm eq "Tripped" and (Alarm$Tripped; !sAlarmEntryTimer): Invalid Value token: "TRIPPED"

Attached is a screen shot of the Alarm Conditions.

I am using  VeraEdge on UI7 firmware version 1.7.2139

The PLEG versions are:

Program Logic Core (PLC) - version 8.17
Program Logic Event Generator (PLEG) - version 8.11

I am using button 2 on the multiswitch plug-in for my "Arm" switch.

sAlarmEntryTimer is the name of my 30 second self trigger timer.

I installed two new Sensative Strip door sensors today so I am keen to get this working if possible ?

Maybe I made a mistake somewhere?

Many thanks

EDIT: (http://EDIT:)

Think I just found the solution:

Your syntax looks OK to me, @mrhex. I don't see why you are getting an error flagged. Try using single quotes for the string compare to see if that helps. E.G. Alarm eq 'Tripped' and (Alarm$Tripped; !Timer30S)

I've changed them all to single quotes and now no errors after reloading the LUA.

I just need to test it now to see if it actually works?

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 01:25:55 pm
Hi

OK I think I have all the PLEG setup correctly but the alarm doesn't seem to be functioning properly.

I have armed both door sensors and turned on button 2 "Arm" on the multiswitch.

If I then open the front door and leave it open, nothing happens. Looking in the status report quickly after opening a door, the timer appears not to have started as it says false and not true as I would expect.

Timer30S   Self Trigger         None   Interval   00:00:30      None   false

I also renamed the timer to the same as in the example "Timer30S"

Its the Alarm$Tripped condition / action that should start the timer, see screen shots.

If I manually run the Alarm$Tripped action from the PLEG Logic Actions list and then run another status report the timer says true. But not when I open a door.

Timer30S   Self Trigger         None   Interval   00:00:30      None   true

Thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 01:40:30 pm
With the alarm armed and the door opened

Triggers:

Arm   MultiSwitch Switch 2 is turned on   true   

tFrontDoor   Whenever Front Door is armed and opened   true   

Schedules:

Timer30S   Self Trigger         None   Interval   00:00:30      None   false   

Conditions:

AnyDoor      tFrontDoor or tPatioDoor          true   

Alarm$Idle      Not Arm   false   

Alarm$Armed      Alarm eq 'Idle' and Arm and Not AnyDoor   false   

Alarm$Error      Alarm eq 'Idle' and Arm and AnyDoor   false   

Alarm$Tripped      Alarm eq 'Armed' and AnyDoor                   false   

Alarm$Alert      Alarm eq 'Tripped' and (Alarm$Tripped; !Timer30S)    true   

Attached is the Alarms actions list. I added TTS to most of them so the ImperiHome Android tablet speaks out the various alarm states, as I don't have a Sonos etc.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 02:42:49 pm
I was just searching for the keyword "Alarm$Alert" and found this thread here (http://forum.micasaverde.com/index.php?topic=24486.0)

Where the OP says changing the Alarm$Alert condition from:

Alarm eq "Tripped" and (Alarm$Tripped; !Timer30S)

to

Alarm eq "Tripped" and !Timer30S and (Alarm$Tripped; !Timer30S)

Made it work for him. But it didn't seem to make any difference for me.

However looking at that OP's screen shot on that thread, in his PLEG report there is a STATE VARIABLE called Alarm

I do not have this "Alarm" state variable listed in my own status or logic reports, which seems odd ?

Thanks

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: ton1968 on September 20, 2016, 04:19:32 pm
Hi cw-kid,

State machines do not seem to work well yet in PLC 8.17. See http://forum.micasaverde.com/index.php/topic,38801.0.html (http://forum.micasaverde.com/index.php/topic,38801.0.html). I hope the next PLC version will have this fixed.

I had also noticed that the list of State Variables has disappeared from the status reports. Hopefully that will be back soon as well.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 04:28:22 pm
Hi cw-kid,

State machines do not seem to work well yet in PLC 8.17. See http://forum.micasaverde.com/index.php/topic,38801.0.html (http://forum.micasaverde.com/index.php/topic,38801.0.html). I hope the next PLC version will have this fixed.

I had also noticed that the list of State Variables has disappeared from the status reports. Hopefully that will be back soon as well.

Hi Ton

Thanks for the heads up !

Not good news then for my new Alarm system  :(
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cw-kid on September 20, 2016, 04:35:57 pm
Ton

So is the problem just that the State Variable does not appear in the reports?

Or is the problem that logic based on State Variables now no longer works ?

Reading your thread quickly it sounds like the latter.

Cheers
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: ton1968 on September 21, 2016, 02:24:25 pm
Ton

So is the problem just that the State Variable does not appear in the reports?

Or is the problem that logic based on State Variables now no longer works ?

Reading your thread quickly it sounds like the latter.

Cheers

As I understand it, these are two separate issues. The latter is of course the more annoying one because it makes the logic fail. It made me spot the former one, which I regard as just an inconvenience.

I believe Richard is working on both issues so this situation should be temporary. If I were developing state variable logic right now or would have some critical State Variable logic, I would go back to the old (7.67) version. But currently I don't, so for the moment I will sit and wait. For your alarm system that may be different, of course. Instructions for downgrading have been posted in http://forum.micasaverde.com/index.php/topic,14446.msg109130.html#msg109130.

Cheers
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: shelbydave on September 28, 2016, 05:21:46 pm
Is there some strangeness with the editor?  the cursor position keeps moving back to the beginning of the line so I end up inserting things in the wrong place.  I am forced to make all my edits in Notepad, or another text editor, then copy / paste into the condition edit box.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garyd9 on September 30, 2016, 11:41:39 pm
Another request to the documentation:  How "sequence expressions" work with "state variables."

To explain the request, reference the documents existing example for state variables:
Code: [Select]
State$S1 Step and (State eq ?S3?) and (State; Step)
State$S2 Step and (State eq ?S1?) and (State; Step)   
State$S3 Step and (State eq ?S2?) and (State; Step)

Those conditionals use "State" in a sequence to determine that "Step most recently became true AFTER State most recently became true" (or non-empty in this case.)

However, how would I test that S2 followed S1 within 1 minute?  Expressions can't be used in sequences, but another thread on this forum suggests that the following might work:
Code: [Select]
(State$S1; State$S2 <= 60)
Is this a valid conditional and does it properly test that "State was most recently set to 'S2' within 60 second after it was most recently set to 'S1'"?

If so, it'd be useful in the "PLEG Basics" guide.  (If not, perhaps a mention on how to do that, or if it's even possible.)

Take care
Gary
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: ton1968 on October 01, 2016, 02:53:26 pm
Another request to the documentation:  How "sequence expressions" work with "state variables."

To explain the request, reference the documents existing example for state variables:
Code: [Select]
State$S1 Step and (State eq ?S3?) and (State; Step)
State$S2 Step and (State eq ?S1?) and (State; Step)   
State$S3 Step and (State eq ?S2?) and (State; Step)

Those conditionals use "State" in a sequence to determine that "Step most recently became true AFTER State most recently became true" (or non-empty in this case.)

However, how would I test that S2 followed S1 within 1 minute?  Expressions can't be used in sequences, but another thread on this forum suggests that the following might work:
Code: [Select]
(State$S1; State$S2 <= 60)
Is this a valid conditional and does it properly test that "State was most recently set to 'S2' within 60 second after it was most recently set to 'S1'"?

If so, it'd be useful in the "PLEG Basics" guide.  (If not, perhaps a mention on how to do that, or if it's even possible.)

Take care
Gary


Hi Gary,

I think that
Code: [Select]
(State$S1; State$S2 <= 60)

is perfectly valid syntax. The examples 'A simple alarm using a state variable' on pg 27 and 'A bathroom Fan Timer' on pg 28 of the "PLEG Basics Guide" both use it as well, although not for determining the sequence order of two state transitions.

Ton
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: garyd9 on October 01, 2016, 03:50:25 pm
is perfectly valid syntax. The examples 'A simple alarm using a state variable' on pg 27 and 'A bathroom Fan Timer' on pg 28 of the "PLEG Basics Guide" both use it as well, although not for determining the sequence order of two state transitions.
Sorry, the question at the bottom of my post wasn't intended as me asking the question.  It was intended as a theoretical new user trying to understand PLEG asking the question.  The idea of the post was a suggestion for an addition to the guide with an example explaining the request... but I can see I chose my words poorly.

How about:  On page 17-18 of the guide, a simple sentence or two might be added to mention that state conditionals/variables can be used in sequence expressions.  For example:

Quote
Just as with other conditional names, conditionals using state naming can also be used in sequence expressions.  If only the state name is used, it represents the last time the state variable was changed.  If  the "statename$stateValue" syntax is used, it represents the timestamp of the last time that the particular state value was assigned to state name.


(For myself, I didn't notice the example in the guide, but just tossed in some conditionals in to see what would happen and how it'd work. )
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: AnttiK on October 09, 2016, 06:59:23 am
Can someone help? I have used like 10 hours to get PLEG to create notification always when one of my 433mhz devices haven't updated one of its properties in last 4 hours. Now only way of noticing that my temperature sensors are not working is to check from Datamine regularly. I would prefer automatic alerts! :) P.S. these devices doesnt report battery status properly.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 09, 2016, 09:21:44 am
@AnttiK
You should always post a PDF  of your status report when you have a problem. That way we can help you tweak what you already have.

You can start by creating a 1 Hour Interval Timer
Hourly:  On - Interval 1 Hour,  Off Interval of 1 min.

Then for each of your sensors you would create an Input Var
Sensor1Val:     Bound to the value of your sensor that should be changing.

Then for each of your sensors you would create a Condition:
TimeoutSensor1                Sensor1Val; Hourly > 4:00:00

Foreach of your sensors do one of the following:
1) Add a notification to PLEG for when condition is satisfed :   TimeoutSensorN
2) Add an action to to each condition that indicates the Error

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: zonatafred on October 20, 2016, 06:03:18 pm
I'm using the UI7 for Vera and am trying to figure out PLEG. What I see on my screen looks nothing like anything in the PDF. NO actions at least. I am not figuring this out on my own. Another note, I sent my email to register but never got an email back. Any help and is PLEG still being maintained?
Thanks
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 22, 2016, 04:12:23 pm
The UI is different but the concepts are the same.

There are some new features in PLEG that are not documented in this getting started guide.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: aboyer on November 17, 2016, 01:38:50 pm
Hi,

I have been using PLEG for quite sometime now successfully. I haven't had to do anything to my Vera Lite or the PLEG plug-in until recently where I added some additional items to my system and wanted to make another PLEG instance to control them.

While I was creating my new PLEG instance, I noticed that I am still using V 7.47 and there is a newer version out. If I upgrade should everything continue to work or will I have to fix some of my PLEGs to function correctly again?

Thanks,
Antonio
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 18, 2016, 03:46:46 pm
Newer versions require UI7

Sent from my SAMSUNG-SM-G935A using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: dwillia599 on November 26, 2016, 07:07:16 pm
I was going well until I have now run across a physical device that doesn't appear in the Device Lists. I'm trying to add a GE in-Wall Smart Dimmer (Jasco ZW3004). I've tried as the Jasco item most similar or as Generic Z Wave device. I can't get it to pair either way. I am reasonably sure I've got the switch wired correctly because it works manually in the wall, including dimming function. It can work in ON and OFF directions.

I have my first PLEG of other Door Window Sensors, Motion Detectors, and an Alarm Siren. It works fine. Including SMS and Email notifications, so I believe the remainder of Controller is working fine. Other devices all paired easily.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 1937BCS on January 01, 2017, 06:55:08 pm
I've created a "simple motion-triggered light" event using the exact example in the manual, but it just won't work on my Vera Plus upgraded with the latest firmware. The reason I'm trying this is because my count down timers no longer work after the "upgrade".

The light turns on when it's night, but it won't shut off. I've attached the Logic Report and hope you can tell me what's wrong. I've looked at it so long that I can't see anymore.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: FilthyBeast on January 02, 2017, 12:46:35 am
I'm still learning, but since I spent two weeks trying different ways of this I think I have a good idea.  You did not include the actions part of the report.  do you have an action that starts the timer? What does KeepOn do, what's its action?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 1937BCS on January 02, 2017, 11:32:53 am
The KeepOn action starts the timer.

I've checked the logs, and everything fires on time, but the light doesn't go out.

I lied.....it worked once last night.

I even created another PLEG and copied and pasted the exact expressions from the instructions, adding 1 to the triggers, etc. and bypassed the first PLEG. Same results.

I think the problem is the firmware update; the problem with the PLEG light off is the exact same problem I've experienced with the countdown timers. I just don't know how to get it fixed since Vera support says it's a third party plugin.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 1937BCS on January 02, 2017, 02:22:18 pm
The KeepOn action starts the timer.

I've checked the logs, and everything fires on time, but the light doesn't go out.

I lied.....it worked once last night.

I even created another PLEG and copied and pasted the exact expressions from the instructions, adding 1 to the triggers, etc. and bypassed the first PLEG. Same results.

I think the problem is the firmware update; the problem with the PLEG light off is the exact same problem I've experienced with the countdown timers. I just don't know how to get it fixed since Vera support says it's a third party plugin.
Another possible clue is for both the countdown timer and the PLEG, when the timer completes, the screen shows the light off, but in fact, it's not.

I'm hoping Richard reads this and is able to come up with a solution.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: FilthyBeast on January 02, 2017, 04:55:41 pm
I think I see it (!LightOn ; Lighton > 10),  This says if the time between last false on lighton  and last true is greater than 10 seconds.  However if the light is off and motion turns it on, then it goes from false to true in less than a second and this statement would not be true.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 1937BCS on January 02, 2017, 05:29:49 pm
I'm sorry, but I don't understand what you're saying. I don't understand programming very well, I just copy what someone comes up with.

It appears you're telling me something about lights on, but my problem is with lights off. They come on without any problem.

If you think you have a solution, please tell me what I have to do to correct it rather than what's wrong.

Thanks a million!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: FilthyBeast on January 02, 2017, 05:42:15 pm
that statement will only be true if the lights turn on at least 10 seconds after they turned off. What are the time stamps of the true and false for LightsOn, AutoOn, Motion, Keepon and timer.  The issue is probably in the timestamps.

it would be easier to see what's going on if you posted the status report.  After tripping the motion sensor and when you think the lights should be off.



Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Life4Jesus on February 02, 2017, 02:25:54 pm
Pleg action not working all together properly.

Action - When backdoor is open and deck step lights are off and during the hours of 5pm - 5 am, turn on the deck step lights for 7 minutes and then turn off.

This sequence should allow for if the door is opened while the lights are on to not re-trigger the counter.

What happens is this:
1) When I first open door (first time in between schedule), lights don't go on.
2) Usually after the 2nd or 3rd time opening the door, light go on and act normal (according to action).
3) I have noticed that even outside of this schedule, lights will go on.

Setup of VeraPlus with U17, version1.7.2414, PLEG version 8.11, PLC version 8.21, Still in 90 trial of PLEG.

Any help is appreciated.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on February 02, 2017, 08:02:16 pm
@Life4Jesus
I see a couple of problems:

1) Looks like you changed the schedule without restarting/reloading Vera ... So it is still using the OLD schedule.
    Note: The on/off time of your timer.

2) You do on/off using delayed actions ...
     This is NOT what you really want. There is NO conditional way to extend the timer.  Exactly 7 minutes after you trigger the  light will go out ... even if you re-triggered 1 minute aqo.

You need to look at the examples using SelfTriggered timers.   You start the timer and turn on the light in one action.
And you have a second action that fires when the timer expires ... there you turn off the light.
But if the trigger happened again one minute ago ... it will extend the timer ... and so it will not expire for another 6 minutes.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: petequintanilla on March 06, 2017, 12:46:41 pm
Im trying to setup a scene to arm alarm if not home, but only during certain hours.

Ive been able to setup the on and off schedule (4pm to 11:29pm Mon-Fri)  also the device triggering (virtual switch) it but i don't know where to put the output device (arm alarm).

Could you please help?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on March 06, 2017, 01:29:05 pm
That would be an action.

Sent from my SAMSUNG-SM-G935A using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: petequintanilla on March 06, 2017, 02:18:17 pm
Thanks Richard My problem is that in the tab Logic Action it only allows me to make a start up LUA action. So im not quite sure how to do it.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on March 06, 2017, 02:30:52 pm
Create a condition first ... or create the actions from Graph (on an input)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on April 08, 2017, 02:29:24 am
Hi Need some guidance here.

I tried using a PLEG Example as my attached.

At Night it works fine auto on auto off only issue is the battery operation motion sensor sometimes it does not detect motion due to it placement and close the light on me.

I noticed that in the day, the light which i manually on, it will auto turn off after X minutes, why is this so? should this PLEG works in the night only? and when i on it manually again it will turn off in couple seconds only after i on/off/on manually again and it will stay for x minutes again before it turn off by itself.

Is there's anyway i can bypass the auto off by using the manual switch (Zwave switch btw) like on/off/on commands?

Reasoning being the crappy sensor some times don't  pick up motion or maybe it is not resetting the PLEG timer which i have no idea, i had set the sensor parameter to the most sensitivity parameter and 1 second feedback already.

Appreciate your assistance.

Thanks

 

 



 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on April 08, 2017, 06:56:44 pm
Your cAutoOn condition references the tItsNight  trigger.

Your cAutoOff and cKeepOn do NOT reference the tItsNight trigger.
You need to update your logic if your requirements are for these to only work at night.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on April 11, 2017, 02:35:42 am
Noted thanks.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on April 19, 2017, 11:44:37 pm
Hi Richard,

I am having some problem with my battery operated sensor (MotionZ) which don't pick so well due to it placement in an L shape kitchen. Need some suggestion on how the PLEG can be written up while maintaining the function of attachment PLEG. Currently MotionZ is placed in the entrance of the kitchen to activate the PLEG but in the dotted red circle zone it seems like activities detection are pretty poor to keep the light up which i have to manually on/off/on to force it to KeepON. So i am thinking of adding MotionF to extended the coverage.

I would like something like this.
MotionZ to trigger the light on only (the one at entrance)
MotionZ Or MotionF will reset the timer if either one picks up motion.
MotionZ Or MotionF no motion detected for 5 minutes lights will AutoOff

Since the AutoOn only works at night? i would like to add another AutoOn for day when Lux reading from MotionF is below 5 Lux when motion is detected in MotionZ.

Thanks a million and i am still trying my best to digest your basic write out... :'(

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on April 24, 2017, 06:30:57 am
Hi need some guidance on my PLEG.

I tried to write up the PLEG first before i goes to set up the sensors and pleg as attached.

Not sure if it will works.

Primary I want the light to be triggered on by MotionZ only.(door way)
In the day, i want the light to be on if the lux level in MotionF is below 10 lux when motionZ is triggered.
In the night, I want the light to be on if MotionZ is triggered.
The light to stay on or to reset the 5 minutes timer if either MotionZ or MotionF detected motion if not manual on/off/on switch will force the light to stay on.
When no motion detected in motionZ and MotionF for 5 minutes or timer runs out the light will be off.

Hope i can get some guidance here.

Really poor in logic so i thought i give it a try first by writing it out after i read the basic.

Thanks :'(
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: MNB on April 24, 2017, 10:18:55 am
 @9ixxerLee, how about posting your Status PDF file it allows all to both review your code which looks like a copy of previously posted PLEG code but more importantly it allows us to see how your device(s) are acting/triggering especially as your using a battery motion detector. Mike
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on April 24, 2017, 10:28:31 am
@9ixxerLee, how about posting your Status PDF file it allows all to both review your code which looks like a copy of previously posted PLEG code but more importantly it allows us to see how your device(s) are acting/triggering especially as your using a battery motion detector. Mike
Hi Mike,
I have yet tried to the put it into pleg. So no status report yet. This is my draft logic.

I will try to get it up for review.

Thanks

Sent from my SM-G925I using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Bobhaskils on May 21, 2017, 08:53:23 am
I have a rather complex PLEG serving 7 Air conditioning units using Remotec ZXT devices. After recent firmware upgrade they do not function at all causing considerable errors - overloading Vera Edge to a halt. Until solved, I would like to Delete the PLEG and to restore it at a later stage (Apparently disarming the PLEG would not stop its logic operation...)

After backing up the entire system I have downloaded a jason file using the Backup/Export from the Editor Options and then deleted the PLEG.
As a test to this concept I have tried creating a new PLEG and Restore/import the file with no results!
What's wrong??
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 21, 2017, 10:24:18 am
If you delete the PLEG device ... you will get a new device # for the PLEG device.

Backup/restore is for the exact same configuration of devices, including the PLEG device.
Backup/restore allows you to roll back your PLEG to a previous state, should you investigate some new logic and decide you want to revert.

If you think PLEG is grinding things to a halt ... then you must have some input device trigger or device property that is changing very quickly that is causing causing this problem.  That's what you need to remove, and make appropriate logic changes, until you can remedy the situation.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Bobhaskils on May 23, 2017, 10:44:06 am
Thank you. I have restored the general backup made prior to deleting the PLEG.
Then I removed all the conditions to stop PLEG from checking and compering data (with missing Temp. sensors) as stipulated.
I then tried restoring the file - with no success - please review attached screenshot with recurring errors.

Just to clarify that the undefined devices are the missing Remotec ZXTs.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 23, 2017, 01:54:44 pm
Thank you. I have restored the general backup made prior to deleting the PLEG.
Then I removed all the conditions to stop PLEG from checking and compering data (with missing Temp. sensors) as stipulated.
I then tried restoring the file - with no success - please review attached screenshot with recurring errors.

Just to clarify that the undefined devices are the missing Remotec ZXTs.
Some where you have a reference to a deleted device. Could be a trigger, device property, or an action.

Sent from my SAMSUNG-SM-G935A using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Bobhaskils on May 24, 2017, 05:38:26 am
Sorry, did not understand... Do you mean under such conditions (Undefined devices) the backup / restore would fail?
If not please explain how can I use this feature to discard the PLEG (temporarily - by only deleting the conditions) and restore once I mange the missing (undefined) devices. Am I doing something wrong with the actual operation of the Backup/Download  - Restoring procedure?
Thanks again.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on May 24, 2017, 09:23:06 pm
LOOK AT YOUR STATUS REPORT!!!!!

I can't tell what the problem is without it ...
As I said, you have an input trigger or variable  or an action that references this DELETED Vera device (The deleted device had a device number of 119)

Since the device is deleted from VERA ... PLEG does not know what to do ... you need to remove the input or action that is referencing this deleted device and adjust/modify/edit your logic as appropriate.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Bobhaskils on May 25, 2017, 10:24:27 am
I'm sorry apparently we are discussing two separate issues...
I fully understand the inability of PLEG to perform while devices are undefined - this is not my question, rather because of that I need to find a way to remove the conditions until the issue of the undefined devices is resolved, if at all.

Those conditions are very complex (containing nested IF clauses) therefore I would like to backup the PLEG (while it is not functioning as explained), then remove/delete the conditions while keeping the PLEG as a device. At a later stage once I have the Remotec ZXT devices up and running WITH A DIFFERENT ID (i.e. will still be undefined for the original PLEG), I would like to Restore the original PLEG with all the original conditions, after which I will manually replace the undefined devices in both the Properties and Actions with the NEW IDs (the newly defined devices will have the exact original name just new ID).

Could such a restore work in the current situation?  I relate to this process as merely a method to Cut & Paste the heavy syntax in the PLEG - I do not expect it to work until the devices are defined. Is this a wrong thinking?
My trials to backup and restore the PLEG as it is results in empty Conditions thus NO restore was made.

I'm attaching a status report from the time this PLEG was working as a reference.

In yet another relevant notion a saw a discussion at the PLEG Next Gen UI about the ability to resolve such issues in a systematic manner by changing the IDs or other simplified way - is this possible? (Once I have the devices operational again)

Thanks again.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Bobhaskils on May 25, 2017, 10:52:45 am


I'm attaching a status report from the time this PLEG was working as a reference.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Don Phillips on May 25, 2017, 06:00:02 pm
I changed my thermostat a couple of months ago.  I had to create new device properties for the new stat (using the old stat was a model), edit the conditions for the new properties, and edit the actions to control the new stat. When it was working, I could delete the old stat properties.

I do not think backup/restore would be helpful when changing a device, unless, you edit the json backup file, then you can restore the edited file.  I would think it is safer (for my pea brain) to not edit the json.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on July 05, 2017, 03:19:12 am
hi just like to check if I can trigger something with a sequence of condition in order, I am reading the write out but seems abit confusing for me to understand.

I am trying something like below:

1. door sensor opened
2. motion detected
3. if it is night trigger my "these" devices
4. if it is day with level light below 5 lux, trigger my "that" devices.

so item 1 & 2 must trigger in order as that's entering my home. and item 3 and 4 to determine what to trigger at the time of the day.

Thanks in advance for guiding me.


if not I will be triggering devices also if I am gg out.





Sent from my SM-G955F using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on July 05, 2017, 07:28:20 am
Trigger
DoorSensorOpen
MotionDetected

Expression:
Code: [Select]
       (DoorSensorOpen; MotionDetected)
Will be true if the last time the MotionDetected was after the DoorSensorOpen was detected.
I.e. if you open the Door yesterday ... but kept moving around today and MotionDetected was going true and false, the expression would stay true because it meets the ordering requirements. It would stay  true until the door is closed, and then opened again. Then it would stay false until motion is detected again, which might be tomorrow.

So you might want to detect motion within a short timer interval, like two minutes:
Code: [Select]
       (DoorSensorOpen; MotionDetected < 2:00)
In both cases it will still be true if the door is Closed before the Motion is detected. Also it will still stay true until the Door is opened again! In which case it will stay false until motion is once again detected within 2 minutes of the last time it was opened. If you want the expression to be false when the Motion is no longer detected, but it is still after the Door was opened ... you would use:
Code: [Select]
       MotionDetected and (DoorSensorOpen; MotionDetected < 2:00)


If you want an expression that is true only if motion happens, shortly after the door is opened, and the door is still open at the time of the motion than you may  want:
Code: [Select]
       DoorSensorOpen and MotionDetected and (DoorSensorOpen; MotionDetected)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: 9ixxerLee on July 05, 2017, 07:59:16 am
thanks for the explanation.
I will go try it out....

Sent from my SM-G955F using Tapatalk

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: WyldSide on September 06, 2017, 06:09:47 pm
Alright, hopefully this hasn't been answered somewhere before - as I haven't been able to find a previous reporting of this. I've gone through this a few times to ensure I haven't missed something but I run into issues directly after installing the PLC and PLEG. After installation, I do not have any "INPUT" tab within the PLEG device created. I simply just have:
[CONTROL] [EDIT] [NOTIFICATION]  [ADVANCED]   [LOGS]   [SCENES]
clicking on "Edit" as an example causes it to display "Opening plegInit..." indefinitely with no action happening. What did I screw up now?
I've already tried uninstalling and reinstalling both the Program Logic Core and Program Logic Event Generator 3 times now, with no change. I hope my VERA isn't on it's death bed. It will be if it keeps this up. I hope it is something really simple that I missed. (sample image attached)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on September 06, 2017, 10:41:28 pm
Try power cycling your Vera.
Also it looks like you are on UI5 ...
The latest version only supports UI7.
See:
   http://forum.micasaverde.com/index.php/topic,14446.0.html
For using UI5.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on September 22, 2017, 03:16:30 pm
Is there any way someone can do some explanation of how to get PLEG to work properly now? Since none of the screens in it look anything like the examples in the documents.....or the videos... or anything else available.... I'm having a heck of a time trying to figure out how to do even the first thing.  I've tried in 1 to 2 hour sessions here and there over the last few months and have been wholly unsuccessful at creating anything that doesn't generate an error. I'm lost on what needs to be created, how to link things up, all of it. In reading through the examples and all of the pages for this post (slowly over months), I simply do not understand where some of the things being typed even come from. 

I actually began reading on PLEG in mid 2014. I downloaded and played with it for a few days and gave up. I came back to it when My logic got more complex in 2015. then gave up. I came back to it again pretty hard in summer 2016, locked up my Vera to the point I had to do a restore, gave up.  I'm back at it now because I have a ton of LUA i've hacked together from other people's code and I just want to simplify it all. I then want to expand what my system can do.  I've considered jumping ship from VERA to another system if I can get a better logic core....and I keep hearing that despite Vera's limited hardware, PLEG still makes it the best system to use. So here I am....trying again.

Maybe I'm just code dumb, I dont know...maybe I need to re-read everything yet again, then make another backup of my system.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: kartcon on September 22, 2017, 08:16:24 pm
Priest,

I am by no means a power PLEG user, but I do feel confident enough to help you get started understanding PLEG. For the purpose of this tutorial I suggest that you create a new instance of PLEG by going to APPS > then click the [DETAILS] button of the Program Logic Event Generator plug-in then click the [Create another] button. Once the new instance is created and on your Devices page name it whatever you want. I will be using my WEATHER PLEG instance for the demo, but any instance will be fine. Next locate the new instance that you just created and click the SETTINGS icon (its the > sign in the grey circle) then select Edit from the Vera menu. This opens the PLEG editor and is where we will do all the 'magic'.

First step is to determine exactly what you want to accomplish. For this demo we will turn on a light that will trigger an event that turns on a second light. Very basic, but it will demonstrate the principal.

1. Select Device  Triggers tab then New Trigger. Fill in the following information; Trigger Name: t_MyLightOn, Comment: Room _____ Light just turned on, Trigger Device: (open the dropdown and select a binary on/off light switch), Event Type: A device is turned on or off, Which Mode: Whenever the device is turned on. Click [SAVE]
2. Select the Conditions tab then select [New Condition]. Fill in the following information; Condition Name: c_RoomLightOn, Comment: Front Porch Light turned ON, in the dropdown box, select t_MyLightOn and click [Insert After Selected] then click [SAVE]
We now have a device trigger and a condition to monitor the status of the trigger. Next we add an action that actually DOES the work of making things happen.
3. Select the Logic Actions tab then open the dropdown box and select our condition to act on (c_RoomLightOn). Notice the following information; Name c_RoomLightOn, When Condition is True. Both items are not changeable but you can add a comment. Move down to the dropdown and select another light that should come on when light #1 is turned on. Click [ACTION] and Select SetTarget, click [newTargetValue] and select 1 (1 = On, 0 = Off). Click [SAVE]
4. The final step is to Reload LUA and close PLEG via the Editor Options tab. First select [Reload Lua] then [CLOSE] then select [BACK] [BACK] from the Vera menu to return to the Devices section. Now you can test your work. Make sure both lights used for the demo are off. Turn ON light 1 and light 2 will immediately follow suit. DONE!!! Your first real action with PLEG.

Please keep in mind this example is very basic and ONLY does this ONE TASK. If you want to turn OFF light 2 using light 1 you must define to Trigger, condition and Action for that event. Using what you have, add additional lights that are Dimmable and see how that works. Keep building simple tasks and only add devices that make sense. Remember that simple coding is easier to understand and troubleshoot later. Practice on one new aspect each time you master the previous concept. Don't try to build a house until the foundation is solid. Good luck.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on September 22, 2017, 08:48:37 pm
I've just read your comment over and will attempt the exercise in a while. One thing is for certain, your explanation has already helped. I had to read the part about condition a few times because that seems to be what my missing piece of understanding was. Out at least one of the missing pieces. I've had Trigger---->ACTION methodology in my head.

Once I've gone through some exercises.... And if I can get traction on doing it correctly.... The first real one I want to build is to replace a schedule dependant action I have going right now. Just so you know the direction I'm going I'll describe the current action I use and the way I want to replace it.

Currently with LUA:
If the house is in night mode and the hall motion is triggered a time check occurs. If it is before 5:30am it brings up the the living room dimmer to 7%. If it is 5:30am or later, it brings up the living room dimmer to 25% and the dining room dimmer to 40% and sets the house to home mode.

My first PLEG goal:
I have set up Tasker to trigger a virtual switch when I get my phone in the morning and it works.

If the house is in night mode and the motion in the hall is triggered I want to check if the virtual switch has been tripped on the last 5 minutes. If it has not, just turn the living room dimmer to 7%. If it has, turn the living room dimmer to 25% and the dining room dimmer to 40% and set the house to home mode.

I'll know I understand PLEG when I can make that work. I've not tried.... Because I can't get simple things to work, but I hope with your example I can begin building on and figure things out.  Once I get that working, I'll actually want to modify it to check light levels and adjust those dimmer levels accordingly.

The goal is to get to home automation instead of just home remote control
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: kartcon on September 22, 2017, 10:30:18 pm
you wrote: Currently with LUA:
If the house is in night mode and the hall motion is triggered a time check occurs. If it is before 5:30am it brings up the the living room dimmer to 7%. If it is 5:30am or later, it brings up the living room dimmer to 25% and the dining room dimmer to 40% and sets the house to home mode.


In PLEG, set up the following:
4 new House Modes - see picture
1 new Trigger for the Hall Motion Detector
1 new Schedule to define the time you are interested in. For example, if 5:30am is the target time set up a schedule between Midnight and 5:30 am OR 5:30am until bedtime later that day (11pm for example). You condition can check the status of the trigger (is TRUE/FALSE and act accordingly).
2 new conditions to test all parameters. The final result will evaluate to either TRUE or FALSE. TRUE conditions will activate the associated ACTION. Here is one possible scenario for the Condition statement:

c_AM_LR_LightsON: m3_NITE AND t_Zone01_Trip AND s_Pre0530

m3_NITE - House Mode is Night *** evaluates to TRUE at NIGHT
t_Zone01_Trip - Hallway motion detector tripped *** Evaluates to TRUE if Device is TRIPPED
s_Pre0530 - current time is between midnight and 5:30am. *** Evaluates to TRUE between set times
c_AM_LR_LightsON *** Evaluates to TRUE IF all 3 above are TRUE. If ANY are False, the Condition will be FALSE

Logic Action 1:
Living Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=7
This accomplishes the first part of your scenario.

The second part goes like this:
c_AM_DR_LightsON: m3_NITE AND t_Zone01_Trip AND (NOT s_Pre0530)

Logic Action2:
Living Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=25
Dining Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=40
House Mode - Using the PLEG as the device - Action: SetHouseMOde, Mode: 1
  OR 
House Mode - Using House Mode PlugIn - Action: SetHMode, newHModeValue: 1
This accomplishes the second part of your scenario.

Again, this is just ONE WAY to do it. There are probably more elegant ways, BUT this works, is basic and easy to understand.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on September 23, 2017, 01:08:36 pm

1. Select Device  Triggers tab then New Trigger. Fill in the following information; Trigger Name: t_MyLightOn, Comment: Room _____ Light just turned on, Trigger Device: (open the dropdown and select a binary on/off light switch), Event Type: A device is turned on or off, Which Mode: Whenever the device is turned on. Click [SAVE]
2. Select the Conditions tab then select [New Condition]. Fill in the following information; Condition Name: c_RoomLightOn, Comment: Front Porch Light turned ON, in the dropdown box, select t_MyLightOn and click [Insert After Selected] then click [SAVE]
We now have a device trigger and a condition to monitor the status of the trigger. Next we add an action that actually DOES the work of making things happen.
3. Select the Logic Actions tab then open the dropdown box and select our condition to act on (c_RoomLightOn). Notice the following information; Name c_RoomLightOn, When Condition is True. Both items are not changeable but you can add a comment. Move down to the dropdown and select another light that should come on when light #1 is turned on. Click [ACTION] and Select SetTarget, click [newTargetValue] and select 1 (1 = On, 0 = Off). Click [SAVE]
4. The final step is to Reload LUA and close PLEG via the Editor Options tab. First select [Reload Lua] then [CLOSE] then select [BACK] [BACK] from the Vera menu to return to the Devices section. Now you can test your work. Make sure both lights used for the demo are off. Turn ON light 1 and light 2 will immediately follow suit. DONE!!! Your first real action with PLEG.

It Worked!  Well, the third time through when I realized that PLEG was bypassed.  It would have worked the first time through I'm sure now, but when it wasnt working I was retrying and didnt find that it was bypassed until my 3rd run.

I now need to figure out some of my scenes to replace with PLEG code to try to get more experience.  I have about 65 scenes, some more complex than others, so I have some things to learn with.  I can always turn off the scene as I put it in PLEG and if it doesnt work, i can just turn the scene back on until I figure it out.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Don Phillips on September 23, 2017, 06:27:53 pm
I now need to figure out some of my scenes to replace with PLEG code to try to get more experience.  I have about 65 scenes, some more complex than others, so I have some things to learn with.  I can always turn off the scene as I put it in PLEG and if it doesnt work, i can just turn the scene back on until I figure it out.

I use a test PLEG to experiment until I get the logic right. That way I can bypass it until I get it right.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on September 23, 2017, 08:09:27 pm
Now, the part I really dont understand is since all of the things in the instructions and even in the instructions I was given just a couple of responses ago.... everything looks like "c_AM_DR_LightsON: m3_NITE AND t_Zone01_Trip AND (NOT s_Pre0530)" but nothing in the interface looks like that


I now get that people are using c, m, t, s as pre-script to indicate conditions, triggers,etc.... but if someone gives me instruction in that format, I'm not sure how to make sense of it since I dont know how to build anything from that.

Thanks for the help. I'll try working on it more tomorrow if I get the chance. I'm having to work through the weekend so free time to play is low.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: kartcon on September 23, 2017, 08:14:50 pm
Priest,

First of all, congrats getting PLEG to work. Secondly, I agree with Don. Create a test instance of PLEG to test all your work. As you mentioned, you can toggle on/off each scene as you get more capable with PLEG. Once you get a couple scenes replaced, back up your Test instance and Restore that backup to your working instance of PLEG. Just remember to make ALL changes in the Test instance and only restore when everything works as planned. Bets of luck!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: kartcon on September 23, 2017, 08:23:06 pm
c_AM_DR_LightsON is the Name of the condition
m3_NITE AND t_Zone01_Trip AND (NOT s_Pre0530) is the text in the condition editor.

Since the name is prefixed with c_ it is safe to assume that this is a condition and that the name is followed by the actual condition text. Not every user uses the exact same format, but most everyone understands the concept. Consider yourself a member of that crowd now!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on September 24, 2017, 06:44:07 am
I would not put all the scenes in one PLEG.
Categorize your scenes, i.e.  Security, Lighting, Environment ...
Create a PLEG for each category ... move the scene to the appropriate PLEG device.

When you are done, you will be able to a Status report for each PLEG, and get a summary for the entire category.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Don Phillips on September 24, 2017, 07:54:24 pm
Let me add - the licenses are not very expensive so if you are up to 4 instances, just add another license.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cc4005 on October 17, 2017, 04:17:28 pm
I'm a VERA and PLEG noob and have successfully implemented a couple of the examples in this thread. But my first attempt at what should be a very simple PLEG of my own has me stumped. I'm using a timer to turn off a bathroom fan a few minutes after it was turned on (currently 2 minutes for testing). The logic appears to work: the timer starts when the fan is turned on, the timer turns off at the end of 2 minutes, and the AutoOffBath3Fan condition returns True when the timer expires. But the AutoBath3Fan action to turn off the fan fails to turn the fan off. I've attached 2 status reports: 1 immediately after turning on the fan and the 2nd a couple minutes after the timer expired. The fan continues to run (switch state remains "1"). I've verified that the PLEG is armed. Also, I'm doing this exercise remotely, including turning on the fan from the Vera web interface, in case that could matter. Advice on what I'm missing would be appreciated.

Second question: Will my condition to retrigger the schedule (cBath3FanOn) work as written (tBath3FanIsOn) or should it be #tBath3FanIsOn so the value changes in order to effect the schedule retrigger?

Thirdly, I welcome any comments or explanation on two unrelated things I'm observing when I run status reports: 1. The title seems to show "Armed" regardless of Armed/Disarmed state of the PLEG device, and 2. "Registration" shows me in the evaluation period despite having registered today, entered the registration code (seemingly successfully), and rebooted the controller.

Thanks.
Wade
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 18, 2017, 10:50:03 am
Delete the action for turning off the fan and re-create it.

I am not sure how you created it ...
The report says:
    cAutoOffBath3Fan Action is True Immediate - 1

It should say:
    cAutoOffBath3Fan Condition is True Immediate - 1
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: cc4005 on October 18, 2017, 11:03:56 am
No idea how I managed to create it that way either, but deleting and recreating fixed it. Thanks for the assist!
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Wallace4793 on October 21, 2017, 08:05:26 am
Hi,

I have a simple ish request but can't find it in the guide.  I want to set a failsFe based on motion in my house so if I'm out the heating switchs off. How do I set a condition for if motion is not detected for a time period?

So !livingroommotion > 60 type command?

Thanks

John
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on October 21, 2017, 07:07:42 pm

(!livingroommotion; NOW > 1:00:00)

Which will be true 1 hour after no motion in the living room.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 29, 2017, 05:33:15 pm
I think I have gotten some of this figured out.  I am trying to build my first complex condition now instead of a simple IF-THEN rule....  for the purposes of this test, let us assume the trigger names are all correct (i edited them to be t1, t2, and t3 for example purposes) and I set up the action correctly as well...

will this operate the way I think it does?

((t1 or t2) and t3) and (( t1 or t2), t3 < 10:00) and M_NIGHT

If M_NIGHT is true
AND
if t3 and either t1 OR t2 become true within 10 minutes of each other
THEN
my condition is met and it will perform the action I tell it to.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 29, 2017, 08:08:06 pm
This will not work ...
You missed one important point about Sequence expressions.
The elements of a sequence expression can ONLY be inputs or other conditions, it can not be an expression.
Inputs and Conditions have timestamps associated with them when they are true or false.
Expressions do NOT.
Sequence expressions operate on these timestamps.
You can make a separate condition from this expression, and use the name of he expression in the sequence expression.

Also a "," in a sequence expression means the order is not important, just that they both happened within 10 minutes.
If (t1 or t2) MUST happen first then you want:

   ((T1OrT2Expr) and T3)  and (T1OrT2Expr; T3 < 10:00) and M_Night
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 12:11:47 am
okay, I think I got it. I'm setting the rest of it up now and going to test and I guess we'll see if I really did or not.  I did want the comma and not the semicolon because I wanted them to be able to happen in any order.

One question that is unclear now, and I hope I can ask the question in a clear manner....

when I do use my real version of this, will it work if those triggers were tripped within the ten minutes of each other, but are not currently tripped? T1 goes true, then false again. 1 minute later T3 goes true. assuming m_night is true with the condition go true?  This is the way I interpreted it and have set it up for it....if this is wrong I need to know how to fix it. 

anyway, off to finish the code and test it.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 30, 2017, 04:43:10 am
Sequence expressions only look at the timestamps and NOT the values.

So  (T1OrT2Expr; T3 < 10:00)   could be true even if  all three values are false.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 07:12:17 am
Sequence expressions only look at the timestamps and NOT the values.

So  (T1OrT2Expr; T3 < 10:00)   could be true even if  all three values are false.

So, are you saying all I actually need is (T1OrT2Expr, T3 < 10:00) and M_Night  to get an action when t3 and one of the others have been true within 10 minutes.  no need for the other beginning portion of the statement?

by the way, my test last night and it's real use this morning sort of worked.  The results were not perfect but I dont have time to see why yet.  my question above may answer it though.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 09:35:38 am
I believe it does work, at least well enough for me to play with and get right. 
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 30, 2017, 10:21:17 am
The sequence expression could have been true 10 hours ago when M_Night becomes true the condition will become true.

One of the inputs will have to become true for the sequence expression to go false.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 12:09:14 pm
The sequence expression could have been true 10 hours ago when M_Night becomes true the condition will become true.

One of the inputs will have to become true for the sequence expression to go false.

I'm confused. in a status report PLEG tells me if the expression is true or not. so if it did not become true within 10 minutes of seeing M-Night becoming true, or vice versa, wouldnt the condition remain false?  I thought since it knows if a condition/expression is true or not that it would know instead of knowing that a condition had once become true.

Doesnt the <10:00 limit it to only if they have become true within 10 minutes of each other?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on November 30, 2017, 05:20:28 pm
M_Night is not in the Sequence expression ... it's in the logic part of the expression.

Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 05:42:24 pm
M_Night is not in the Sequence expression ... it's in the logic part of the expression.

AH! I get it. If the sequence becomes true, how does it become not true then?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: zedrally on November 30, 2017, 07:23:01 pm
If the sequence is not "in sequence" then it is not and cannot be true.

I find it's easier working with complex conditions to break them down into smaller elements so you can easily test which works and which doesn't.

(T1OrT2xprE; T3 < 10:00) and M_Night

initially I would create a condition for T1OrT2xprE & T3 < 10:00 define them as cT and cT10 then once you have the logic working you can combine them as cT;Ct10 and M_Night



Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on November 30, 2017, 11:37:47 pm
I think I have a working solution, it's ready to go into practice tomorrow morning to see if it works on a production environment instead of artificially triggering.  One foreseeable snag is if those triggers are activated as m_night becomes true....

Is there a way to also add the condition that m_night must have been true for at least X period of time before it can be a true condition?
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: zedrally on November 30, 2017, 11:41:48 pm
try (M_Night>xmins)
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on December 01, 2017, 11:59:14 am
try (M_Night>xmins)

Yeah....when I try that it throws an error on reload

Program Logic Event Generator[9] : (M_NIGHT > 30:00): Invalid Value token: 30:00
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on December 01, 2017, 12:26:56 pm
M_NIGHT and (M_NIGHT;NOW > 30:00)

I think this works.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Priest on December 04, 2017, 07:59:01 am
Well, I ran with it for a couple days.... I think it is working.  The scenario worked this morning....ish

I really need to set up my Vista alarm panel and get motions over on to it rather than relying on the z-wave ones. I had some things work, then not work, then work again....I think it has to do with the way the zwave motion is spotty on reliability.  I also need to figure out why having tasker trip devices through AuthomationHD worked perfectly every time on my old phone, and now it doesnt on the new phone.  I may just have to trip devices with it through Imperihome instead and see if that is more reliable.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: Davit on December 24, 2017, 03:31:25 pm
Hello guys.

Paid for Pleg license and now trying to automate my gate closure based on the car passing by the IR security sensors.
To accomplish that, i have hooked up fibaro universal sensor's two inputs to the gate. So, first sensor will trip when the gate is open and the second when there is an obstacle (car) between the gate's IR sensor.
Now, i'm trying to create an action that will close the gate when
1. gate is open AND
2. the time between the IR sensor tripped and then untripped is more than 3 seconds (i.e. car passed, not person or a dog).

i got two triggers - tIR_SensorTripped and tIR_SensorUntripped

This should be something simple with a sequential expression, but i can't seem to find the proper way to get the point 2 work. So the following expression never gets true:

tIR_SensorTripped AND (tIR_SensorTripped; tIR_SensorUntripped > 00:00:03)

How can i fix this?

Thanks for your help
D.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: zedrally on December 24, 2017, 05:51:19 pm
Try (Now>00:00:03)


Probably not the best way to do this as Now evaluates every minute, likewise your sensor would probably have a time out period which could  cause problems with your logic. Really a 3 sec timer is preferable.


If it doesn't work as expected attache a pdf of the Status report so we can get the whole picture of what is going on rather than a snippet.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: vikram.m on January 04, 2018, 02:15:15 am
Hi,

I have successfully installed PLEG plugin. I went through basics pdf. But unable to create simple basics.
I have setup 6 in 1 multisensor using vera controller, trying to get simple notification when motion is detected. I am missing something , please help me out here.
Steps that i performed:
1. Configured Device trigger
2. Conditions
3. Logic actions
4. set Notification
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 04, 2018, 03:19:36 am
5) Reload LUA
6) Test
7) Check Status Report
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: vikram.m on January 06, 2018, 01:45:29 am
Thanks for the reply Richard.
Can you please help me for below scenarios as well.
1. I have 2 motion sensor, where both will be idle/no motion detection happens at same time i.e. 30mins in onecase and 1hr idle in another case and then need to send notifications using AND operations. I tried where device is armed and no motion detects in vera but didn't work.
2. I have 1 motion sensor , where it will be idle/no motion detection occurs for 30mins in onecase and 1hr idle in another case and then need to send notifications. I tried where device is armed and no motion detects in vera but didn't work.
3. How get notification when no motion detection occurs between the time range for example: 5 AM to 9 AM
4. Is there way to get notification so that  i can identify a person fall detection using motion sensors.
5.  Can you please share link or documents which provides details and example of using expression like when use sequence expression, multi trigger expression and general expression .
This details will really help for my project.

With regards,
Vikram
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: RichardTSchaefer on January 06, 2018, 07:49:36 am
You really should start a new thread for your question.

Strategy:
Input Timer:  Named Morning  Starts at 5AM every day ... ends at 9AM every day.
Inputs   Motion1 ... MotionN

Conditions:
AnyMotion                  Motion1 or Motion2 or ... MotionN
MorningMotion            Morning; AnyMotion; !Morning
NoMorningMotion        !MorningMotion and (!MorningMotion;!Morning)


Attach your alert to NoMorningMotion


Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: sely on September 30, 2018, 02:08:02 pm
I recently had my PLEG program give a 'Lua Startup Failure'.  Searching around I found people recommending reloading the PLEG and PLEG Core.  After doing this I tried importing my logic and keep getting a "Could not find:Program Logic Event [177]" error message.  I don't know what this is, I list all my devices and don't have a 177.  I think this is my old PLEG device number?  Can't restore my old programming.  Any help is appreciated.  See screen shots attached.
Title: Re: PLEG Basics - An Introduction to the Program Logic Event Generator
Post by: BerrytH on February 17, 2019, 07:27:09 pm
Priest,

I am by no means a power PLEG user, but I do feel confident enough to help you get started understanding PLEG. For the purpose of this tutorial I suggest that you create a new instance of PLEG by going to APPS > then click the [DETAILS] button of the Program Logic Event Generator plug-in then click the [Create another] button. Once the new instance is created and on your Devices page name it whatever you want. I will be using my WEATHER PLEG instance for the demo, but any instance will be fine. Next locate the new instance that you just created and click the SETTINGS icon (its the > sign in the grey circle) then select Edit from the Vera menu. This opens the PLEG editor and is where we will do all the 'magic'.

I?m sorry to border you but your explanation is very clear, but I can?t get PLEG working...I?ve VERA UI7.
On the devices page below the new instance that I?ve created are two buttons: ARM and Bypass and the settings button.
If I push the settings icon, I can select the edit button but after doing that I always get an Error: ?Error executing function plegInit(): Expect Function.
What am I doing wrong, I?ve uninstalled and installed the PLEG app several times without success.
Any help would be appreciated,
Thanks