VeraAlerts using sequence expressions as variables

I am trying to figure out how to use sequence expressions (timestamps) in custom VeraAlerts programmed through LUA. I am able to pull device statuses and transmit them as variables in the VeraAlerts messages (called using LUA), but I have not figured out how to create a local variable using timestamps for various triggers. For instance, I wanted to create a custom message that says something like: “The garage has been closed. It was open for XX minutes” with the XX providing the variable calculated via the timestamps. I believe this information may be obtained from the PLEG device from the field “ObjectStatusMap” (“urn:rts-services-com:serviceId:ProgramLogicC”,“ObjectStatusMap” ) under the values seq and oseq, but I cannot figure out the syntax necessary to make those values local variables in LUA. Has anyone been able to do this? As always, thanks!

Input
WindowOpened - True when window is opened.

Use a message:
The window was open for: {( (#!WindowOpened - #WindowOpened) / 60 )} minutes.

This is helpful, but I actually wanted to create the message via a Lua scene, if possible, since that allows for greater customization of the message, including the ability to reference the status of other devices, etc. I was hoping to get the timestamp from the array within the ObjectStatusMap of the PLEG device (device # 34 in my case) with the code being something like the following (with comments):

– door statuses
local frontdoortimestamp1 = luup.variable_get(“urn:rts-services-com:serviceId:ProgramLogicC”,“ObjectStatusMap”,“cFrontDoorOpen”,“seq”, 34)
local frontdoortimestamp2 = luup.variable_get(“urn:rts-services-com:serviceId:ProgramLogicC”,“ObjectStatusMap”,“cFrontDoorOpen”,“oseq”, 34)
local frontdoorminutes = frontdoortimestamp2 - frontdoortimestamp1 / 60

– day or night status message
local dayornightstatus = luup.variable_get(“urn:rts-services-com:serviceId:DayTime”,“Status”, 32)
local dayornight32statusmessage = “night”
if tonumber(dayornightstatus) > 0 then dayornight32statusmessage = “day” end

– message to be sent via Lua action
local actionmessage = “The front door has been locked. It is " … dayornight32statusmessage … " and was unlocked for " … frontdoorminutes… "
minutes.”
luup.call_action(“urn:richardgreen:serviceId:VeraAlert1”, “SendAlert”, {Message =actionmessage, Recipients = “VeraMobil”}, 63)

My biggest issue is with the line frontdoortimestamp1 = luup.variable_get(“urn:rts-services-com:serviceId:ProgramLogicC”,“ObjectStatusMap”,“cFrontDoorOpen”,“seq”, 34)

While I am able to pull the entire ObjectStatusMap, I cannot figure out how to pull the timestamps for each condition, which I believe are represented by seq and oseq. Any advice on that?

Please review “An Introduction to the Program Logic Event Generator”
http://forum.micasaverde.com/index.php/topic,21603.0.html

See the section on Lua Code in Actions.

Again, this is helpful, and it definitely works well when selecting the action as “SendAlert” and typing in the Message using these variables, but even after a few hours trying different things to follow the examples in “An Introduction to the Program Logic Event Generator” I still cannot seem to get it to work. It looks like the manual is saying that the syntax is XXXX.seq, XXXX.oseq, and XXXX.state, where XXXX is the name of the condition in upper case and the .seq, .oseq, and .state indicate timestamps and condition status.

My condition is named cBasementBedroom1. I am trying to pull the timestamps from that condition, which works fine in PLEG actions but not in Lua.

When testing simple code via LuaTest1.6, such as “local XXXX = CBASEMENTBEDROOM1.seq” or “print(CBASEMENTBEDROOM1.seq)” I get the following error “Runtime error: Line 1: attempt to index global ‘CBASEMENTBEDROOM1’ (a nil value)”.

As always, any help would be appreciated. I think just being able to do a simple print(XXXX) command that would actually pull the timestamp would give me what I need.

You can’t use these in LuaTest

You can only use these in LUA for the PLEG where the variables are defined.

I see. Is there any conceivable way to pull these timestamps for the purposes of LuaTest? Or do you have other methods of testing using PLEG condition timestamps other than causing a condition to become true and waiting to see if an error occurs or the message fails to send?

One additional question, I defined a function in my Startup Lua but found that it was not accessible in my PLEG action Lua. That function was as follows:

foo = function (t1,t2)
local days = math.floor((t1-t2)/86400)
local hours = math.floor((t1-t2-(days86400))/3600)
local minutes = math.floor((t1-t2-(days
86400)-(hours*3600))/60)
local time_to_return = days … "d "… hours …"h "… minutes … "m "
return time_to_return
end

It converts two timestamps to days, hours, and minutes. I found that it does in fact work if I redefine the function in the Lua code, but it does not work by referencing the function in the PLEG action Lua. In other words, it does not appear to be accessible by PLEG when the function is only defined in the Start Lua.

The function does work in LuaTest without defining it there, which would seem to indicate that it is pulling the function from Startup Lua.

As always, any help is appreciated.

There is a Startup LUA for each PLEG.

PLugins do NOT have access to the LUA namespace of any other plugin or for “Scenes/Vera Startup LUA”