Fibaro Motion Sensor and Turning off devices when motion not detected for X time

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.

If you don’t need special rules (like time of day etc), you can change the “untripped” parameter on the Fibaro to be much longer so behavior more like what you want. Infact you could just direct associate the light to the Fibaro in that case and not have to do any scene programming.

Otherwise looks up threads on “wasp in a box” for being smart about if a room is occupied and when to turn off the light.

I’m using the time restrictions part of the triggers gui to restrict when the scene can run so I guess I could carry on using that even if I amend the fibaro tripped value?

I’m using my system for a house alarm too, therefore I don’t really want this value being too high, as whatever the remain tripped value is set to, the alarm would have to wait longer than this to become active, else it might go into intrusion mode as soon as it’s set (I think).

I’ll search around for the wasp in a box solution and see if it will help.

Thanks very much :slight_smile:

Also, if you use the PRogram Logic Event Generator PLEG. The first example in the help doc walks you through how to do a motion sensor based lighting.

I think PLEG will be your friend with the things you want to do. I did the LUA route at first but have been moving to PLEG for everything at this point, it is easier to deal with and exposes some great advanced scenarios.

Thanks for the tip - PLEG has worked a treat…it took a little while to get my head around it, the pdf i found around PLEG did have a section explaining the high level elements to the scenario i had, however not an exact how to…but i got there in the end!

Thanks again :slight_smile: