variable modification time

Hello,

According to the wiki

luup.variable_get() returns 2 things, the value of the variable requested and the time it was last modified. The wiki suggests doing something like to make sure you are using value and not the time:

local lul_temp=luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",3) if( tonumber(lul_temp)<26.6 ) then return false end

The thing is I need the time, not the value.

Im working with a z-wave motion sensor and I need the time that the device “tripped” variable was last changed( it actually changes twice when tripped, first to tripped=1 then back to tripped=0 a few minutes later, but thats fine).

Thanks foir any help.

In Lua, if a method has multiple return values, then they can be gotten using the construct:

local temp, timestamp = luup.variable_get("urn:upnp-org:serviceId:TemperatureSensor1","CurrentTemperature",3) if (tonumber(temp) < 26.6) then return false end

You’ll see this in the Lua Manual, under the examples for Expressions:

http://www.lua.org/manual/5.1/manual.html#2.5

That said, I’ve tried to get this “timestamp” component before, and not had success. YMMV.

i can not even get the basic example above to function. i was hoping to be able to do some basic luup stuff. i wrote basic many years ago so i thought this would be fun.
:frowning:

local lul_temp=luup.variable_get(“urn:micasaverde-com:serviceId:TemperatureSensor1”,“CurrentTemperature”,5)
if (tonumber(lul_temp)>10) then
return false
end

well thats not very encouraging…

Is there an easy way to pull the current time in unix format?

If so I can use an event to write the current time to a new variable attached to that device

try it first, and make sure your experience matches. I wouldn’t be discouraged on this stuff, as what can “fail” in early releases, can often work later on when it’s fixed (or it’s functionality is better understood)

Is there an easy way to pull the current time in unix format?

http://www.lua.org/manual/5.1/manual.html

Look for [tt]os.time()[/tt]

can anyone tell me why this does not work on vera2 with the latest beta, this is my first attempt. the device that I am using is the hsm100. The device works just fine I am just trying to add a condition. e3 is the device id for the temp. if i use the the device master id #5 it tells me “Bad Device”
Wayne.

local lul_temp=luup.variable_get(“urn:upnp-org:serviceId:TemperatureSensor1”,“CurrentTemperature”,e3)
if( tonumber(lul_temp)>10 ) then
return false
end

Use the ‘id’ as shown on the ‘Advanced’ tab instead of the ‘ID’ shown on the ‘Settings’ tab …

The ‘ID’ is not unique: all composite devices have 'ID’s e1, e2, e3, …

under the advanced tap of the temperature sensor of the HSM100 there are three id’s

  1. called altid = e3
  2. called id_parent = 4
  3. called id = 7

under the advance tap of the 3 in 1 sensor of the HSM100 there are three id’s

  1. called altid = 5
  2. called id_parent = 1
  3. called id = 4
    ???

The id of your temperature sensor is 7, the id of its parent, the HSM100, is 4.

Use id 7 for getting the temperature, use id 4 for getting the time of the last wake up of your HSM100.

ok some more details and where I’m at.

Goal: Every day at 11:00 send me an email if motion senson 1 hasn’t tripped in the last 4 hours. ( I want to make sure my dad is up and moving around.)

Plan: I am planning to use the timespamp on the Motion sensor’s “Tripped” variable to calulate how long since the last time it was tripped. If at 11:00am it hasnt been tripped in 4 hours send an email.

Monkey wrenches: From what I’ve seen, I have to set up a scheduled scene to send the email, then if the sensor has tripped, prevent the sending. which makes the code “feel backwords”. Email alerts are seamingly tied to the motion sensors tripped state which I can’t rely on.

Scene setup: I have scene named “Dad not up”. In it is a timer, set for 11:00 AM daily. There is an event I’ve lovingly named “stupid settings” with the selected device being Device “#47 Motion Sensor” Event type “An armed sensor is tripped”, and Tripped? “No”. All this seems very awkward and kludgy but was nessicary to expose the notify checkbox. which I have of course clicked.

Code: In the luup scene code box I have the following(Im using 1200 seconds as a test for now):

[code]local ght_current_time=tonumber(os.time())

local ght_tripped, ght_tripped_time=luup.variable_get(“urn:schemas-micasaverde.com:serviceId:MotionSensor”,“Tripped”,47)

if( tonumber(ght_tripped_time)>(ght_current_time-1200)) then
return false
end
[/code]

Result: nothing. Even with the code removed I get no emails, which is confusing since Iwith no code to stop them I should be getting the emails automaticly when the timer goes off. I assume that the event code is some how screwing this up, but Im not sure how to get that configured the correct way.

i am trying to use the tab "Test Luua code (Lua) under “MIOS Developers” section of the UI4 to test the code, not sure if this is the correct thing to do. if i use anything else for device other than e3 it gives me Bad Device.

http://forum.micasaverde.com/index.php?topic=3794.0 might be of help.

ok so it’s clear that usding the event is the wrong way to go, as it basiclly emails me when ever the motion sensor transitions back from tripped to reset, which is not what I want…

Is there a way to generate the notification email out of LUUP?