We have moved at community.getvera.com

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

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #465 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.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #466 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.
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #467 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.

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #468 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!

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #469 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!

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #470 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.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #471 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.
Vera 3, 1.7.1040, CT101, Everspring Motion, GE/Jasco Switch/Dimmer, Leviton outlet, AeonLabs sensor, NuTone garage door, Blue Iris, Sricam SP011, iPhone locator, APCUPSD, VeraMate, VeraAlerts, PLEG, House Modes, Countdown Timer, DVR, Virtual/Multi Switch, LB60Z-1 bulb, Hue, Alexa, Zooz 4-1

Offline cc4005

  • Full Member
  • ***
  • Posts: 103
  • Karma: +6/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #472 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

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #473 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

Offline cc4005

  • Full Member
  • ***
  • Posts: 103
  • Karma: +6/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #474 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!

Offline Wallace4793

  • Jr. Member
  • **
  • Posts: 95
  • Karma: +0/-2
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #475 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

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #476 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.

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #477 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.

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #478 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

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #479 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.