Hi guys,
I have a device which i’ve created two scenes for…
Scene ON - turns it on, between a restricted time period, IF this sensor detects motion, and then sets a virtual switch to ON (to prevent it trying to turn the device on every time it detects motion etc).
Scene OFF - turns the device off, between a restricted time period, IF this sensor stops detecting motion, and then resets the virtual switch back to OFF for similar reasons to above.
Currently, as my motion sensor is configured to detect motion and become tripped, then 30 seconds later, become “untripped” the Scene OFF runs if we simply stop moving for more than 30 seconds, but are usually still in the room…obviously i’d like to extend this, so it only turns off the device after no motion is detected after say 30 minutes.
The sensor I have is the Fibaro FGMS101 which looks like a cat-eye. It has a variable “LastTrip” which stores values similar to “1436696968” rather than an obvious time.
I?d tried using the LUA script below to calculate the difference between the current time and the last trip time and if greater than 5 minutes (in this instance) run the scene, however currently it runs the scene after the standard 30 second period still.
local SID_VSwitch1 = "urn:upnp-org:serviceId:VSwitch1"
local lastTrip = luup.variable_get("urn:micasaverde-com:device:MotionSensor:1","LastTrip",3)
local status = luup.variable_get(SID_VSwitch1,"Status", 43)
if(status == "1" and ((os.clock() - lastTrip >= 300)))then
return true
else
return false
end
Two issues I have, I?m not sure how os.clock presents the time, nor am I sure how fibaro are getting the time to data like ?1436696968? and what that might actually mean in clock speak!?
I did try searching here before posting and only came across one post, which had the code below as a solution to this exact problem, however I?m struggling to decipher it.
[url=http://forum.micasaverde.com/index.php/topic,30513.msg218756.html#msg218756]http://forum.micasaverde.com/index.php/topic,30513.msg218756.html#msg218756[/url]
[code]var Timer timerChambre
rule “D?tection mouvement chambre”
when
Item DetecteurChambre changed
then
if (previousState.toString == “CLOSED” && DetecteurChambre.state.toString == “OPEN”) {
var Number luminosite = LuminositeChambre.state as DecimalType
if (luminosite < 30) {
if (timerChambre != null) {
timerChambre.cancel
timerChambre = null
}
LampeChambre.sendCommand(ON)
}
}
else if (previousState.toString == “OPEN” && DetecteurChambre.state.toString == “CLOSED”) {
if (timerChambre != null) {
timerChambre.cancel
timerChambre = null
}
timerChambre = createTimer(now.plusSeconds(90)) [|
LampeChambre.sendCommand(OFF)
]
}
end[/code]
Can someone please help me either decipher the ?solution? code, or work out a way to do this please? I?m still learning all this and what seems to be a simple standard pair of scenes is once again not so simple with Vera. I am becoming ever more drawn to the HomeSeer software, which seems to offer a very simple method to achieve anything like this.
Thanks in advance.