PLEG Basics - An Introduction to the Program Logic Event Generator

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.

[quote=“flyveleder, post:41, topic:178580”]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.[/quote]
I’m not sure what you mean. Can you explain what you want to achieve?

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.[/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?

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.

[quote=“RexBeckett, post:44, topic:178580”]

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.[/quote]
I do have a Vera Lite so I will try to keep my number of PLEGs down. Thanks.

[quote=“flyveleder, post:41, topic:178580”]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.[/quote]
Hello,
As PLEG action, you can run a scene containing the luup code…

Thanks duck, this is what I do now, I just thought you could avoid scenes with PLEG.

One day I will add LUA to PLEG/PLTS actions.
I just wanted to see how far this idea could go without LUA code.

[quote=“RichardTSchaefer, post:48, topic:178580”]One day I will add LUA to PLEG/PLTS actions.
I just wanted to see how far this idea could go without LUA code.[/quote]
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 ?

second that

I tried to let a PLEG-action write to “VariableContainer” using Luup and that didn’t succeed ::slight_smile: 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

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.

[quote=“C4Vette, post:50, topic:178580”]second that

I tried to let a PLEG-action write to “VariableContainer” using Luup and that didn’t succeed ::slight_smile: 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[/quote]
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

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 ? Temperature : LastTemp

Actions
LowTemp

@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 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.

But won't this fail the first time because there is no 'LastTemp?
The first time this runs, [b]LastTemp[/b] will be 0 - but not for long...
LastTemp will be tru if if (? 'Temperature' exists maybe?). But what is the use of this?
Think of it this way: Each time [b]Temperature[/b] changes, [b]LastTemp[/b] will be set to the new value. But this happens [u]after[/u] the Condition [b]LowTemp[/b] has been evaluated to see if the new Temperature is lower than the previous one. [b]LastTemp[/b] just keeps the last value of [b]Temperature[/b].
For the example after "- or -" LastTemp becomes true if 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 becomes true,[b] LastTemp[/b] gets the first value which is the current value of [b]Temperature[/b]. If not, it gets the second value which is its own value so no change. If 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.

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.

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?

@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!

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.

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