We have moved at community.getvera.com

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

Offline Theduck38

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #45 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...
-- TD38 --
MacPro OSX10.6.8 -- MCV Vera3 - Rfxcom Rfxtrx433 -- Foscam FI8910W - Vision Security ZP-3102 -- Oregon BTHR918 / THGR810(x4) / THN132N - AeonLabs 4in1(x2) - Owl CM180 -- Duwi 05439(x7) -- ARC Plugs Diagral (x3) - Everspring AN157 - Fibaro FGD-211 -- Eaton 650 & 1200 + APC UPS PRO 900

Offline flyveleder

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

Offline RichardTSchaefer

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

Offline Theduck38

  • Full Member
  • ***
  • Posts: 124
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #48 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 ?
-- TD38 --
MacPro OSX10.6.8 -- MCV Vera3 - Rfxcom Rfxtrx433 -- Foscam FI8910W - Vision Security ZP-3102 -- Oregon BTHR918 / THGR810(x4) / THN132N - AeonLabs 4in1(x2) - Owl CM180 -- Duwi 05439(x7) -- ARC Plugs Diagral (x3) - Everspring AN157 - Fibaro FGD-211 -- Eaton 650 & 1200 + APC UPS PRO 900

Offline C4Vette

  • Full Member
  • ***
  • Posts: 157
  • Karma: +3/-8
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #49 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
VeraLite UI7 1.7.649
Fan of: PLEG, DataYours, dutchSmartMeter, MySensors

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1576
  • Karma: +191/-85
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #50 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.
« Last Edit: February 20, 2014, 01:56:15 pm by Bulldoglowell »

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #51 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>




« Last Edit: February 20, 2014, 07:22:31 pm by RexBeckett »

Offline C4Vette

  • Full Member
  • ***
  • Posts: 157
  • Karma: +3/-8
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #52 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.
« Last Edit: February 21, 2014, 05:24:22 am by C4Vette »
VeraLite UI7 1.7.649
Fan of: PLEG, DataYours, dutchSmartMeter, MySensors

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #53 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.


Offline C4Vette

  • Full Member
  • ***
  • Posts: 157
  • Karma: +3/-8
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #54 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.
VeraLite UI7 1.7.649
Fan of: PLEG, DataYours, dutchSmartMeter, MySensors

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #55 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?

Offline RexBeckett

  • Beta Testers
  • Master Member
  • *****
  • Posts: 3891
  • Karma: +483/-12
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #56 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...

Offline tomgru

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

Offline tomgru

  • Hero Member
  • *****
  • Posts: 1403
  • Karma: +18/-6
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #58 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. 

Offline BulldogLowell

  • Hero Member
  • *****
  • Posts: 1576
  • Karma: +191/-85
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #59 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
« Last Edit: February 23, 2014, 09:11:59 pm by Bulldoglowell »