Program Logic Event Generator (PLEG) for dummies

I’ve tried to search and read everything that I can on this app but can’t get something I would think is really simple to work. All I’m trying to do is to set a porch light to come on based on a schedule but only if a virtual device is also on. Basically I want a light to come on every day at Sunset but only if my Guest Status virtual device is ON. I would think that I’d set a schedule in the Input tab and then put a conditional for the Guest Status device. I’ve tried this every way that I know how and still can’t get it to work.

Any help would be greatly appreciated.

Thanks.

[quote=“beerguy, post:1, topic:174288”]I’ve tried to search and read everything that I can on this app but can’t get something I would think is really simple to work. All I’m trying to do is to set a porch light to come on based on a schedule but only if a virtual device is also on. Basically I want a light to come on every day at Sunset but only if my Guest Status virtual device is ON. I would think that I’d set a schedule in the Input tab and then put a conditional for the Guest Status device. I’ve tried this every way that I know how and still can’t get it to work.

Any help would be greatly appreciated.

Thanks.[/quote]

Yes - that doesn’t sound too difficult. Try this:

Set up your PLEG with:

Inputs - Schedules
Name: Sunset Type: DayofWeek Days: Check all Time: Sunset
Name: OffTime Type: DayofWeek Days: Check all Time: as required

Inputs - Triggers
Name: GotGuest Device: Event Type: Turned On or Off Mode: Turned On

Conditions
Condition Name: DoLightOn Condition Expression: (GotGuest and Sunset)
Condition Name: DoLightOff Condition Expression: (GotGuest and OffTime) -or- b[/b] so it doesn’t get left on if you turn off GotGuest whilst the light is on!

Actions
Condition: DoLightOn then select the required device On button in the GUI.
Condition: DoLightOff then select the required device Off button in the GUI.

Close the device window then click the usual Save button then, when the save has finished, reload your browser page.

You can test whether it works by temporarily setting the Sunset and Offtime schedules to times shortly in the future. Don’t forget to save and reload whenever you make changes.

Thanks much and sorry for the delay responding. I hadn’t realized there was a reply to my original post. I’ll have to dig into the settings on this forum. I’m used to forums that let you know when someone has replied to a post that you start.

Thanks again.

This is still way beyond my capabilities. I have read everything, too, and still can’t grasp it. As difficult as I find using Luup in scenes, it’s easier for me than this. I must be extremely dense.

I must be extremely dense.
I'm sure that isn't the case but it is a very different approach to coding in Luup.

I recommend setting-up a few VirtualSwitch (VS) plugins and a PLEG for testing. Define some of the VSs as PLEG inputs and try some simple condition expressions to AND and OR these inputs. Set actions for these conditions to change the rest of the VSs. Once you get the hang of this, add some time clauses (E.g. Now > 10) to see how to achieve timing. Before too long, it will all make sense. Honestly. :slight_smile:

[quote=“RexBeckett, post:2, topic:174288”]Yes - that doesn’t sound too difficult. Try this:

Set up your PLEG with:

Inputs - Schedules
Name: Sunset Type: DayofWeek Days: Check all Time: Sunset
Name: OffTime Type: DayofWeek Days: Check all Time: as required

Inputs - Triggers
Name: GotGuest Device: Event Type: Turned On or Off Mode: Turned On

Conditions
Condition Name: DoLightOn Condition Expression: (GotGuest and Sunset)
Condition Name: DoLightOff Condition Expression: (GotGuest and OffTime) -or- b[/b] so it doesn’t get left on if you turn off GotGuest whilst the light is on!

Actions
Condition: DoLightOn then select the required device On button in the GUI.
Condition: DoLightOff then select the required device Off button in the GUI.

Close the device window then click the usual Save button then, when the save has finished, reload your browser page.

You can test whether it works by temporarily setting the Sunset and Offtime schedules to times shortly in the future. Don’t forget to save and reload whenever you make changes.[/quote]

Rex,
Thanks for posting this - I’ve been trying to crack this nut too and this has been a great post.

One question though - would you use the GotGuest virtual switch as a trigger or a device property? Does it make a difference?

thanks

CC

@Richard but others chime in please

I am 2 months out now installing all my goodies I have been benchtesting for several months. Elk, Vera 3, monoprice systems just to name a few.
I will have 40 Fibaro dimmers and relays thrown around a 3 story townhouse. Everything is hardwired and homerun to my “server room” on the 1st floor.

Looking at the big picture with Vera, I want to start off setting things up and avoiding reorganizing rooms, devices, scenes, etc in Vera over and over. I want to learn from all you guys mistakes. So I guess I am looking for ideas how best to approach Vera’s base structure organizing. My biggest problem is that I still don’t understand too much about Richard’s amazing PLEG and PLTS. I don’t have enough experience to appreciate all it’s abilities as it works with devices and/or scenes. All I know is that I from what I know thus far, I want to be using PLEGs and PLTSs for my automation as opposed to programming LUUP code.

In that light please comment on my thinking process here. Is any of this totally off the wall or what?

Concept #1- Using a PLEG (or PLEGS) to define my various devices including condition rules, scheds, triggers, all neatly packed into the PLEG. Then, as I create Vera scenes, I can utilize the devices, events, and conditions I set up in the PLEG to create these Vera scenes.

Concept #2- Avoid using Vera scene building completly, and create multiple PLEGS for specific to different devices (or rooms?), whereas these devices are controlled via the PLEG itself. Essentially have the PLEG do all the heavy lifting completely and do away with any scenes. (Is this even possible?)

Concept #3- Integrate Vera scenes AND PLEGs, working together, to acheive the various device automation functions.

My limited understanding of Richards PLEG and PLTS use has me asking these questions. Sorry if it sounds dumb, but I am just looking for a direction to start building my system correctly from the start. I don’t want to keep redoing things over and over.

I envision laying out Vera by creating rooms based on my house layout and organizing devices based on what room they are in. Maybe make an extra room for the Elk stuff or plugins that are global in nature, i.e datamine, heliotope,push notify, etc.

What have you experienced guys figured out is best for starting?

I wish there were more info around, but I cannot find any of it in the forum. It would be nice to create a thread that discusses the set-up and organizing of Vera’s CP. People could share screenshots, do’s and don’ts managing devices, that sort of thing. Not so much nuts and bolts, but how to “manage” or “organize” things. I can already tell as one starts automating everything, it would be easy to get totally lost on what is controlling what, where/how multiple devices interact with each other. How best to avoid conflicts when doing all this rules, triggers, conditions scheds programming. Thinking about it all makes my head explode. How do you all keep it straight and neat???
I hope you understand what I’m asking.

Thanks all…

Probably deserves it’s own thread … but let me answer about how I look at things.
There are almost as many ways to organize this as there are people reading this!

Scenes: I pretty much use these only for manually invoked automation tasks. By that I mean a NAMED group of things I want to happen at one time … but that are invoked when I want them to be … and not part of strict automation. The concept of scheduled/delayed commands in Vera’s scenes should NOT or RARELY be used. Vera does not honor these if it’s restarted in the middle of the Scene execution. The longer the delay … the more likely to be a problem!

Examples: All Lights On, All Lights Off, Secure the House
I place scene’s in the most appropriate room for the house.

PLEG can do a lot of lifting. You can equate a single condition in PLEG, and it’s associated inputs, actions, and notifications to a single Vera Scene. However with PLEG, I group similar things together. I.e. a single PLEG device for Lighting and Fan Management for bathrooms, Utility rooms, etc. Another PLEG device for Security Entry and Exit automation and Locking down the house and Thermostat overrides. Another PLEG device for my Water management … Pump for Instant Hot Water … and various other tasks … I live strictly on rain water collection … and it’s all automated … including anti-freeze logic.

From a Vera Resource perspective … it’s about 2MB per Vera device … So If you can collapse related things than you will reduce Vera Resources.

I started with PLTS, I was motivated by integrating Futzle’s Combination and CountDown timer plugins.
But then I realized how useful just the condition engine was and created PLEG. Now my feeling is that PLTS is useful if you also need to occasionally interact with the timing schedules. I.e. you need a device to manipulate. I wish more 3rd party apps had support for this device.

I have some virtual rooms:
Environment: Contains Day or Night, Weather Plugins, …
Automation: Contains PLEG Devices, Many of the PLTS Devices, GC100 for iTach relays for Garage Doors, Vera Alerts, … In general … things I do not typically interact with directly. I use the Garage Door plugin and it’s devices are in the garage room.
And other pseudo rooms:
Shop Ceiling: I have 26 individually addressable lights for a 2500 sq ft garage/shop that I control from a single switch. Actually the pattern of lights, based on what I am working on, is managed separately. The quantity, and shared usage justified it’s own pseudo room.
Upper/Lower Deck: Areas around, the house, not actually rooms.

@ColdCowboy

One question though - would you use the GotGuest virtual switch as a trigger or a device property? Does it make a difference?

I would define a VirtualSwitch as a trigger. Triggers are usually most suitable for devices with simple on/off states. Use a Device Property for analogue or variable quantities - like temperature - so you can test the quantity in a condition statement (E.g. Temp > 25). Some devices will allow you to set a trigger for a variable quantity using a fixed limit (E.g. exceeds 100). VariableContainer is one device that supports this.

[quote=“RexBeckett”]@ColdCowboy

One question though - would you use the GotGuest virtual switch as a trigger or a device property? Does it make a difference?

I would define a VirtualSwitch as a trigger. Triggers are usually most suitable for devices with simple on/off states. Use a Device Property for analogue or variable quantities - like temperature - so you can test the quantity in a condition statement (E.g. Temp > 25). Some devices will allow you to set a trigger for a variable quantity using a fixed limit (E.g. exceeds 100). VariableContainer is one device that supports this.[/quote]

Thanks!

There’s very little difference from an implementation perspective.

I also tend to use triggers … then I just use names:
Nightime

Is more readable than:
DayNight == 0

Thank you again Richard for your “concept” approach to your PLEG. This helps me a lot to get started.

Too easy thanks!

Just programmed a light for some evenings literally 10 minutes! ;D