We have moved at community.getvera.com

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

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #450 on: May 23, 2017, 01:54:44 pm »
Thank you. I have restored the general backup made prior to deleting the PLEG.
Then I removed all the conditions to stop PLEG from checking and compering data (with missing Temp. sensors) as stipulated.
I then tried restoring the file - with no success - please review attached screenshot with recurring errors.

Just to clarify that the undefined devices are the missing Remotec ZXTs.
Some where you have a reference to a deleted device. Could be a trigger, device property, or an action.

Sent from my SAMSUNG-SM-G935A using Tapatalk


Offline Bobhaskils

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-1
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #451 on: May 24, 2017, 05:38:26 am »
Sorry, did not understand... Do you mean under such conditions (Undefined devices) the backup / restore would fail?
If not please explain how can I use this feature to discard the PLEG (temporarily - by only deleting the conditions) and restore once I mange the missing (undefined) devices. Am I doing something wrong with the actual operation of the Backup/Download  - Restoring procedure?
Thanks again.

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #452 on: May 24, 2017, 09:23:06 pm »
LOOK AT YOUR STATUS REPORT!!!!!

I can't tell what the problem is without it ...
As I said, you have an input trigger or variable  or an action that references this DELETED Vera device (The deleted device had a device number of 119)

Since the device is deleted from VERA ... PLEG does not know what to do ... you need to remove the input or action that is referencing this deleted device and adjust/modify/edit your logic as appropriate.

Offline Bobhaskils

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-1
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #453 on: May 25, 2017, 10:24:27 am »
I'm sorry apparently we are discussing two separate issues...
I fully understand the inability of PLEG to perform while devices are undefined - this is not my question, rather because of that I need to find a way to remove the conditions until the issue of the undefined devices is resolved, if at all.

Those conditions are very complex (containing nested IF clauses) therefore I would like to backup the PLEG (while it is not functioning as explained), then remove/delete the conditions while keeping the PLEG as a device. At a later stage once I have the Remotec ZXT devices up and running WITH A DIFFERENT ID (i.e. will still be undefined for the original PLEG), I would like to Restore the original PLEG with all the original conditions, after which I will manually replace the undefined devices in both the Properties and Actions with the NEW IDs (the newly defined devices will have the exact original name just new ID).

Could such a restore work in the current situation?  I relate to this process as merely a method to Cut & Paste the heavy syntax in the PLEG - I do not expect it to work until the devices are defined. Is this a wrong thinking?
My trials to backup and restore the PLEG as it is results in empty Conditions thus NO restore was made.

I'm attaching a status report from the time this PLEG was working as a reference.

In yet another relevant notion a saw a discussion at the PLEG Next Gen UI about the ability to resolve such issues in a systematic manner by changing the IDs or other simplified way - is this possible? (Once I have the devices operational again)

Thanks again.
« Last Edit: May 25, 2017, 10:49:10 am by Bobhaskils »

Offline Bobhaskils

  • Jr. Member
  • **
  • Posts: 58
  • Karma: +0/-1
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #454 on: May 25, 2017, 10:52:45 am »


I'm attaching a status report from the time this PLEG was working as a reference.

Offline Don Phillips

  • Hero Member
  • *****
  • Posts: 1464
  • Karma: +41/-36
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #455 on: May 25, 2017, 06:00:02 pm »
I changed my thermostat a couple of months ago.  I had to create new device properties for the new stat (using the old stat was a model), edit the conditions for the new properties, and edit the actions to control the new stat. When it was working, I could delete the old stat properties.

I do not think backup/restore would be helpful when changing a device, unless, you edit the json backup file, then you can restore the edited file.  I would think it is safer (for my pea brain) to not edit the json.
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 9ixxerLee

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #456 on: July 05, 2017, 03:19:12 am »
hi just like to check if I can trigger something with a sequence of condition in order, I am reading the write out but seems abit confusing for me to understand.

I am trying something like below:

1. door sensor opened
2. motion detected
3. if it is night trigger my "these" devices
4. if it is day with level light below 5 lux, trigger my "that" devices.

so item 1 & 2 must trigger in order as that's entering my home. and item 3 and 4 to determine what to trigger at the time of the day.

Thanks in advance for guiding me.


if not I will be triggering devices also if I am gg out.





Sent from my SM-G955F using Tapatalk


Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #457 on: July 05, 2017, 07:28:20 am »
Trigger
DoorSensorOpen
MotionDetected

Expression:
Code: [Select]
       (DoorSensorOpen; MotionDetected)
Will be true if the last time the MotionDetected was after the DoorSensorOpen was detected.
I.e. if you open the Door yesterday ... but kept moving around today and MotionDetected was going true and false, the expression would stay true because it meets the ordering requirements. It would stay  true until the door is closed, and then opened again. Then it would stay false until motion is detected again, which might be tomorrow.

So you might want to detect motion within a short timer interval, like two minutes:
Code: [Select]
       (DoorSensorOpen; MotionDetected < 2:00)
In both cases it will still be true if the door is Closed before the Motion is detected. Also it will still stay true until the Door is opened again! In which case it will stay false until motion is once again detected within 2 minutes of the last time it was opened. If you want the expression to be false when the Motion is no longer detected, but it is still after the Door was opened ... you would use:
Code: [Select]
       MotionDetected and (DoorSensorOpen; MotionDetected < 2:00)


If you want an expression that is true only if motion happens, shortly after the door is opened, and the door is still open at the time of the motion than you may  want:
Code: [Select]
       DoorSensorOpen and MotionDetected and (DoorSensorOpen; MotionDetected)

Offline 9ixxerLee

  • Sr. Newbie
  • *
  • Posts: 29
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #458 on: July 05, 2017, 07:59:16 am »
thanks for the explanation.
I will go try it out....

Sent from my SM-G955F using Tapatalk


Offline WyldSide

  • Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #459 on: September 06, 2017, 06:09:47 pm »
Alright, hopefully this hasn't been answered somewhere before - as I haven't been able to find a previous reporting of this. I've gone through this a few times to ensure I haven't missed something but I run into issues directly after installing the PLC and PLEG. After installation, I do not have any "INPUT" tab within the PLEG device created. I simply just have:
[CONTROL] [EDIT] [NOTIFICATION]  [ADVANCED]   [LOGS]   [SCENES]
clicking on "Edit" as an example causes it to display "Opening plegInit..." indefinitely with no action happening. What did I screw up now?
I've already tried uninstalling and reinstalling both the Program Logic Core and Program Logic Event Generator 3 times now, with no change. I hope my VERA isn't on it's death bed. It will be if it keeps this up. I hope it is something really simple that I missed. (sample image attached)

Offline RichardTSchaefer

  • Moderator
  • Master Member
  • *****
  • Posts: 10091
  • Karma: +764/-143
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #460 on: September 06, 2017, 10:41:28 pm »
Try power cycling your Vera.
Also it looks like you are on UI5 ...
The latest version only supports UI7.
See:
   http://forum.micasaverde.com/index.php/topic,14446.0.html
For using UI5.

« Last Edit: September 06, 2017, 10:44:02 pm by RichardTSchaefer »

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #461 on: September 22, 2017, 03:16:30 pm »
Is there any way someone can do some explanation of how to get PLEG to work properly now? Since none of the screens in it look anything like the examples in the documents.....or the videos... or anything else available.... I'm having a heck of a time trying to figure out how to do even the first thing.  I've tried in 1 to 2 hour sessions here and there over the last few months and have been wholly unsuccessful at creating anything that doesn't generate an error. I'm lost on what needs to be created, how to link things up, all of it. In reading through the examples and all of the pages for this post (slowly over months), I simply do not understand where some of the things being typed even come from. 

I actually began reading on PLEG in mid 2014. I downloaded and played with it for a few days and gave up. I came back to it when My logic got more complex in 2015. then gave up. I came back to it again pretty hard in summer 2016, locked up my Vera to the point I had to do a restore, gave up.  I'm back at it now because I have a ton of LUA i've hacked together from other people's code and I just want to simplify it all. I then want to expand what my system can do.  I've considered jumping ship from VERA to another system if I can get a better logic core....and I keep hearing that despite Vera's limited hardware, PLEG still makes it the best system to use. So here I am....trying again.

Maybe I'm just code dumb, I dont know...maybe I need to re-read everything yet again, then make another backup of my system.

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #462 on: September 22, 2017, 08:16:24 pm »
Priest,

I am by no means a power PLEG user, but I do feel confident enough to help you get started understanding PLEG. For the purpose of this tutorial I suggest that you create a new instance of PLEG by going to APPS > then click the [DETAILS] button of the Program Logic Event Generator plug-in then click the [Create another] button. Once the new instance is created and on your Devices page name it whatever you want. I will be using my WEATHER PLEG instance for the demo, but any instance will be fine. Next locate the new instance that you just created and click the SETTINGS icon (its the > sign in the grey circle) then select Edit from the Vera menu. This opens the PLEG editor and is where we will do all the 'magic'.

First step is to determine exactly what you want to accomplish. For this demo we will turn on a light that will trigger an event that turns on a second light. Very basic, but it will demonstrate the principal.

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.

Please keep in mind this example is very basic and ONLY does this ONE TASK. If you want to turn OFF light 2 using light 1 you must define to Trigger, condition and Action for that event. Using what you have, add additional lights that are Dimmable and see how that works. Keep building simple tasks and only add devices that make sense. Remember that simple coding is easier to understand and troubleshoot later. Practice on one new aspect each time you master the previous concept. Don't try to build a house until the foundation is solid. Good luck.
« Last Edit: September 22, 2017, 08:22:58 pm by kartcon »

Offline Priest

  • Full Member
  • ***
  • Posts: 223
  • Karma: +9/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #463 on: September 22, 2017, 08:48:37 pm »
I've just read your comment over and will attempt the exercise in a while. One thing is for certain, your explanation has already helped. I had to read the part about condition a few times because that seems to be what my missing piece of understanding was. Out at least one of the missing pieces. I've had Trigger---->ACTION methodology in my head.

Once I've gone through some exercises.... And if I can get traction on doing it correctly.... The first real one I want to build is to replace a schedule dependant action I have going right now. Just so you know the direction I'm going I'll describe the current action I use and the way I want to replace it.

Currently with LUA:
If the house is in night mode and the hall motion is triggered a time check occurs. If it is before 5:30am it brings up the the living room dimmer to 7%. If it is 5:30am or later, it brings up the living room dimmer to 25% and the dining room dimmer to 40% and sets the house to home mode.

My first PLEG goal:
I have set up Tasker to trigger a virtual switch when I get my phone in the morning and it works.

If the house is in night mode and the motion in the hall is triggered I want to check if the virtual switch has been tripped on the last 5 minutes. If it has not, just turn the living room dimmer to 7%. If it has, turn the living room dimmer to 25% and the dining room dimmer to 40% and set the house to home mode.

I'll know I understand PLEG when I can make that work. I've not tried.... Because I can't get simple things to work, but I hope with your example I can begin building on and figure things out.  Once I get that working, I'll actually want to modify it to check light levels and adjust those dimmer levels accordingly.

The goal is to get to home automation instead of just home remote control
« Last Edit: September 22, 2017, 08:53:26 pm by Priest »

Offline kartcon

  • Full Member
  • ***
  • Posts: 158
  • Karma: +7/-0
Re: PLEG Basics - An Introduction to the Program Logic Event Generator
« Reply #464 on: September 22, 2017, 10:30:18 pm »
you wrote: Currently with LUA:
If the house is in night mode and the hall motion is triggered a time check occurs. If it is before 5:30am it brings up the the living room dimmer to 7%. If it is 5:30am or later, it brings up the living room dimmer to 25% and the dining room dimmer to 40% and sets the house to home mode.


In PLEG, set up the following:
4 new House Modes - see picture
1 new Trigger for the Hall Motion Detector
1 new Schedule to define the time you are interested in. For example, if 5:30am is the target time set up a schedule between Midnight and 5:30 am OR 5:30am until bedtime later that day (11pm for example). You condition can check the status of the trigger (is TRUE/FALSE and act accordingly).
2 new conditions to test all parameters. The final result will evaluate to either TRUE or FALSE. TRUE conditions will activate the associated ACTION. Here is one possible scenario for the Condition statement:

c_AM_LR_LightsON: m3_NITE AND t_Zone01_Trip AND s_Pre0530

m3_NITE - House Mode is Night *** evaluates to TRUE at NIGHT
t_Zone01_Trip - Hallway motion detector tripped *** Evaluates to TRUE if Device is TRIPPED
s_Pre0530 - current time is between midnight and 5:30am. *** Evaluates to TRUE between set times
c_AM_LR_LightsON *** Evaluates to TRUE IF all 3 above are TRUE. If ANY are False, the Condition will be FALSE

Logic Action 1:
Living Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=7
This accomplishes the first part of your scenario.

The second part goes like this:
c_AM_DR_LightsON: m3_NITE AND t_Zone01_Trip AND (NOT s_Pre0530)

Logic Action2:
Living Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=25
Dining Room Dimmer - Action=SetLoadLevelTarget, newLoadLevelTarget=40
House Mode - Using the PLEG as the device - Action: SetHouseMOde, Mode: 1
  OR 
House Mode - Using House Mode PlugIn - Action: SetHMode, newHModeValue: 1
This accomplishes the second part of your scenario.

Again, this is just ONE WAY to do it. There are probably more elegant ways, BUT this works, is basic and easy to understand.