PLEG - Variables in LUUP ?

Guys - I am sure this is possible, but not sure how… ???

so, I use this on several actions in luup:

luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”,
{Message = “{tone:2} HI It’s Vera, Letting you know the front door is still unlocked!”, Recipients = “”}, 85)

is it possible it to create a variable, or some code, where I can replace front door with “open trigger” and avoid a separate action code for each entry point.

I am doing one for my attic door as well, and was planning on a whole new trigger, of course, but a new condition, and a new action…

luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”,
{Message = “{tone:2} HI It’s Vera, Letting you know the ATTIC door is still unlocked!”, Recipients = “”}, 85)

And what if multiple are open at the same time, is it possible to say Front door and attic door in the same action event?

I can figure out the condition , if front door, or attic , etc, but not sure how to handle the LUUP action code.

Thanks!

You can do anything you want in LUA code …
Vera’s physical resources, comprehension of available programming resources, development patience and imagination, are the only things to limit the scope.

great, thats good news. As a non developer, can PLEG handle this, or will it have to be in Luup?

So, I know how to define a Did, and get the properties, but how would you recommend going about bringing multiple device properties into a single action event?

Should I could create a “local” entry for each possible entry trigger, and if any one of them has a property where the door is open, do something?

ie
local aTTicOpen = Luup.variable.get ("urn:upnporg:
serviceId:etc, etc

local FrontDoorOpen = Luup.variable.get ("urn:upnporg:
serviceId:etc, etc

local opendoors = " The " … aTTicOpen … " Door is open"

luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”,
“SendAlert”, {Message = opendoors , Recipients =
“”}, 510)

How would I aggregate the open devices? so, if property of attic door, and property of front door are tripped, how would I create that statement?

Thanks!

Hi all, looking for some help with advanced luup conditions if anyone has ever done anything like this.

Just looking to announce all triggers that are open using the vera alerts plug in. Not sure if this is better suited for a different section, like the vera alerts board, but I am creating inside of my PLEG sensors group.

Thanks!

[quote=“MrAutomate, post:4, topic:186433”]Hi all, looking for some help with advanced luup conditions if anyone has ever done anything like this.

Just looking to announce all triggers that are open using the vera alerts plug in. Not sure if this is better suited for a different section, like the vera alerts board, but I am creating inside of my PLEG sensors group.

Thanks![/quote]

I don’t understand what you are looking for here. You are asking for help with luup conditions for use with Vera Alerts but you have posted on the PLEG board. It would help if you explained what you wanted to achieve and what part you are having difficulty with.

Rex - Sure, so I have VERA alerts speak when a door is left open. I need some help knowing when MULTIPLE doors are still left open. So instead of having separate conditions for each door, here is my current condition:

cDoorLeftOpen : tDoorUnlocked AND (tDoorUnlocked; NOW > 15:00)

would be changed to :

tFrontDoorUnlocked AND (tFrontDoorUnlocked; NOW > 15:00) or ( tAtticDoorDoorOpen AND (tAtticDoorOpen; NOW > 15:00)

That part I get…The VERA alerts part I need some help with in the LUUP code.

In PLEG LUUP section , I currently have :

luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”,
{Message = “{tone:2} HI It’s Vera, Letting you know the front door is still unlocked!”, Recipients = “”}, 85)

I think I can do something like:
(I need to get the state, and if it is open fire the alert…)

local AtticState = luup.variable_get(“urn:upnp- org:serviceId:xxxxxxx”, “xxxxxxx”, xxx)
local FrontDoorState = luup.variable_get(“urn:upnp- org:serviceId:xxxxxxx”, “xxxxxxx”, xxx)
etc
etc

if attic is open:
local AtticTrigger =“Attic”

if Front Door is open :
local FrontDoorTrigger =“Front Door”
– combine these – maybe:

local allTriggers = …AtticTrigger… “and” … FrontDoorTrigger…

local TriggerMsg = “The following doors are still open” … allTriggers…

then maybe something like:
luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”, {Message = TriggerMsg , Recipients = “”}, 85)

what if only one is open, Vera will say “Front Door AND” but there will not be more than 1 trigger, so , a bit clumsy.

Am I on the right track ? Thanks

If you are running this code as part of a PLEG action, you can use the values of the PLEG Triggers instead of using luup.variable_get(…) calls. E.g:

local AtticState = TATTICDOOROPEN.state local FrontDoorState = TFRONTDOORUNLOCKED.state

There are lots of different ways to handle the assembly of multiple message components. With a large number of triggers, it would be worth loading them into a table and then looping through them. For a small number, you could use something like this:

[code]local TriggerMsg = "The following doors are still open: "
local multiple = false

if FrontDoorState then
TriggerMsg = TriggerMsg … “Front Door”
multiple = true
end

if AtticState then
if multiple then TriggerMsg = TriggerMsg … " and " end
TriggerMsg = TriggerMsg … “Attic”
multiple = true
end

if AnotherState then
if multiple then TriggerMsg = TriggerMsg … " and " end
TriggerMsg = TriggerMsg … “Another”
multiple = true
end


[/code]

Rex - I am running this in a PLEG action.

Here is what I have, but it is not running the action. I must be overlooking something. is the >0 valid on an open close trigger ?

local AtticState = tAtticDoorOpen.state
local FrontDoorState = tDoorUnlocked.state

local TriggerMsg = "The following doors are still open: "
local multiple = false

if FrontDoorState >0 then
TriggerMsg = TriggerMsg … “Front Door”
multiple = true
end

if AtticState >0 then
if multiple then TriggerMsg = TriggerMsg … “and”
TriggerMsg = TriggerMsg … “Attic Door”
multiple = true
end

luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”,
{Message = “{tone:2} HI It’s Vera, letting you know” …TriggerMsg … , Recipients = “”}, 85)

Here is what I have, but it is not running the action. I must be overlooking something.

You must specify PLEG items in all caps:

local AtticState = TATTICDOOROPEN.state local FrontDoorState = TDOORUNLOCKED.state ...

Thanks!! As I get to know you better, I should assume if something is in a different case, it is not for aesthetics :slight_smile:

Here is what worked (for anyone seeing this thread later)

local AtticState = TATTICDOOROPEN.state
local FrontDoorState = TDOORUNLOCKED.state

local TriggerMsg = "The following doors are still open: "
local multiple = false

if FrontDoorState then
TriggerMsg = TriggerMsg … “Front Door”
multiple = true
end

if AtticState then
if multiple then TriggerMsg = TriggerMsg … " and " end
TriggerMsg = TriggerMsg … “Attic”
multiple = true
end
luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”,
{Message = “{tone:2} HI It’s Vera, letting you know” …TriggerMsg , Recipients = “”}, 85)

I was just about to start a thread about getting, storing, and using variables in PLEG, and then I saw this one. So, I’ll add my question in here for now. Feel free to let me know if it belongs somewhere else… :slight_smile:

I want to grab the current state of the lights in my living room, store in some sort of variable, and then be able to recall those states to resume the exact same lighting conditions.

To put it into context, I’m brainstorming a PLEG condition to shut off the livingroom lights if there hasn’t been any motion for a while. But, if motion resumes shortly after the lights have been shut off, I want the lights to go right back to where they were.

I know that I could just have them come up to a preassigned scene, but for HAF (Housemate Approval Factor) I really need to allow for the flexibility of various custom lighting setups that my wife and housemate may come up with for any given situation.

Here’s a bit of pseudo-code I’ve come with as part of the brainstorming for how to make this work:
(You’ll notice that I also want the lights to go dim for 15 seconds before they shut off, in case there is someone in teh room, sitting very, very still :slight_smile: )

[code]If any Livingroom lights are on
and
no motion detected for 5 minutes
- get power level status for all livingroom lights and save to variables
- dim all lights to 50% current state
If still no motion after another 15 seconds
- shut off all livingroom lights

If Motion detected and last motion detected within 1 hour
- turn lights back on to last level, using variables saved above.
[/code]

I’m pretty confident with how to do everything except for getting and storing the variables for the lights’ last state. Where is the best place for these variables to exist? Is there a way to simplify the getting and saving of the variables, rather than writing a long line of lua for every bulb?
And how do I make sure that, each time this condition runs, it overwrites the old variables? And doesn’t create dupes?

Where is the best place for these variables to exist?

The first decision is whether you need the variables to survive a Vera/Luup restart. Global Lua variables will cease to exist on restart. If you want persistence through a restart, you would need to use a device (state) variable. You could use the MultiString plugin for this or just create your own variables on an existing device. Variables are created just by setting their value.

Is there a way to simplify the getting and saving of the variables, rather than writing a long line of lua for every bulb?

One way is to write a function to perform this operation on a single variable and then call it for each item that you want to save. You could also set up a loop that processes the variables that you specify in a table.

And how do I make sure that, each time this condition runs, it overwrites the old variables? And doesn't create dupes?

With either global Lua variables or device variables, provided you write new data to the same variable name, it will overwrite the old data.

Thanks! I think I’m starting to get the hang of this… slowly. I really appreciate your assistance!