We have moved at community.getvera.com

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

Offline hamishb

  • Sr. Newbie
  • *
  • Posts: 22
  • Karma: +1/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #30 on: January 29, 2014, 11:41:45 pm »
OK I am on UI6 so maybe that's the problem.

Offline clippermiami

  • Hero Member
  • *****
  • Posts: 1394
  • Karma: +27/-6
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #31 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
« Last Edit: February 02, 2014, 06:07:32 pm by clippermiami »
Two Vera Plus UI7 Linked via HTTP, 90+ Devices. PlugIns: PLEG, DSC, Blue Iris, MySensors,  AutoVera, ImperiHome, VeraAlerts, EventWatcher

Offline RexBeckett

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

Offline clippermiami

  • Hero Member
  • *****
  • Posts: 1394
  • Karma: +27/-6
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #33 on: February 02, 2014, 07:44:11 pm »
Thanks, I'll give it another go.

John
Two Vera Plus UI7 Linked via HTTP, 90+ Devices. PlugIns: PLEG, DSC, Blue Iris, MySensors,  AutoVera, ImperiHome, VeraAlerts, EventWatcher

Offline Vreo

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

Offline SaucyPig

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #35 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?

Offline RexBeckett

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

Offline rtt3821

  • Newbie
  • *
  • Posts: 16
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #37 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?

Offline RexBeckett

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

Offline RexBeckett

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

Offline flyveleder

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

Offline RexBeckett

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

Offline Freddan101

  • Sr. Member
  • ****
  • Posts: 347
  • Karma: +12/-2
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #42 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?

Offline RexBeckett

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

Offline Freddan101

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