I am running openhab2 and trying to setup some rules around my motion sensors. Here is what I am thinking.
Using some design patterns and virtual switches I am looking at the following concept.
Group gMotionSensors
Group gMotionSensors_raw
Group gMotionSensors_LastUpdate
Switch LivingroomMotionSensor_raw <input from motion sensors>
Switch LivingroomMotionSensor (gMotionSensors)
DateTime LivingroomMotionSensor_LastUpdate (gMotionSensors_LastUpdate) "Livingroom [%1$ta %1$tR]" <clock>
So when the motionsensor triggers it updates the state of _raw, updates the item for the lastupdate timestamp, updates the virtual switch
rule "Raw Motion Sensor State Changed"
when
Item gMotionSensors_raw changed from OFF to ON
then
gMotionSensors_raw.members.forEach[motionsensor |
val dtStr = motionsensor.name + "_LastUpdate"
val nameParts = motionsensor.name.split("_")
val virtName = nameParts[0]
val DateTimeItem assocDT = gMotionSensors_LastUpdate.members.filter[dt|dt.name == dtStr].head as DateTimeItem
assocDT.postUpdate(new DateTimeType(motionsensor.lastUpdate))
val SwitchItem virtNamer = virtName as SwitchItem
virtNamer.send(ON)
]
end
So at this point, the raw sensor would trigger only when the trigger is updated to âONâ. it will ignore the motion sensors âOFFâ trigger because I am not as concerned with that as I am handling off via code.
When it triggers to âONâ it will turn on the virtual switch and update the â_LastUpdateâ item (i know, this is also handled in persistance, but I want to be able to display this info later on a sitemap)
Next I want to put a rule that will allow the motion sensors to still be triggered off even through a reboot. This is why i am not using expire binding.
rule "Motion Sensor Done"
when
Time cron "0 0/1 * * * ?"
then
gMotionSensors.members.forEach[motionsensor |
if (motionsensor.state == ON) {
if (!motionsensor.updatedSince(now.minusMinutes(Settings_MotionSensorTimeout.state))) {
#the motion sensor is on, and it was updated more than X minutes so it's time to turn it off
motionsensor.send("OFF")
}
}
]
end
So that is my concept so far. I have not implemented it because I am looking at one other feature and have a couple routes I could go.
Basically what I want to do is compensate for this scenario. My wife likes to read. So she will sit down with her kindle and barely move. Because of the pets the sensitivity is set a little lenient to compensate. So what i would like to do is if the light turns off because she didnât move, if she triggers it again to turn on, but it triggered with in say 30 seconds of when it turned off, to add say 10 minutes to the default timeout. if it happens again, maybe add 15. Since i donât think variables are persistent through triggering of rules, the only thing i can think of is to add something like this.
Number LivingroomMotionSensor_triggercount
DateTime LivingroomMotionSensor_shutofftime
and then do something with the rule to look at the shutofftime instead of lastupdated. Then in the triggering rule for turning on, check the lastupdate time and what that state was. If lastupdate < 30 seconds ago, set shutofftime = + (TriggerCount * 5). If lastupdate > 30 seconds. proceed as normal and set triggercount = 1
so if it default time is 10 minutes, then first motion detect will set the lights to turn off after 10 minutes and set trigger count = 1. if the lights turn off and turn back on with in 30 seconds, timeout is set to + (TriggerCount = 1 * 5) so now itâs 15 minutes. Update trigger account to 2. Repeat.
Any thoughts on this? Or does it seem feasible enough to say, do it and see what happens?
Thanks! any feedback is appreciated.