PLEG Basics - An Introduction to the Program Logic Event Generator

Thanks Rex.
I am looking forward to be able to use PLEG better.
And thanks to Richard for the great work.
Regards
CE

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?

[quote=“SanderL, post:22, topic:178580”]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?[/quote]
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.

Thanks. And what would “AutoOff” and “LightOn” be? Triggers?

AutoOff would be a Condition.

LightOn would be a Trigger.

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?

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.

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?

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.

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?

OK I am on UI6 so maybe that’s the problem.

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

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.
Is it possible to test substrings? Use RegEx on the string and extract just the "Code 7" part etc?
I'm afraid not.

Thanks, I’ll give it another go.

John

[quote=“clippermiami, post:32, topic:178580”]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[/quote]Clippermiami, I use this to get the Users name:

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.

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?

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.

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?

[quote=“SaucyPig, post:36, topic:178580”]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?[/quote]
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…

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.