I seem to encounter quite a few scenarios where I want something else to happen after another event.
E.G
I have a rule that when someone triggers the front gate to unlock, that it turns on the front yard lights when its night. This works. However, when the visitors exit the front gate (which will trip the doorbell motion sensor, meaning they have left) I want the lights to then switch off.
Im struggling to work out whats the best way to do this in a single or multiple rules.
Any pointers would be great!
Cheers
EDIT:
The only way I can think of, is to create a proxy item
Switch Leaving "Visitors Leaving"
rule "Trigger Front Lights when Gate unlocked"
when
Item DoorBird_DoorOpener received command ON
then
if(vTimeOfDay.state == "NIGHT"){
FrontYardSw1.sendCommand(ON)
FrontDoorSw1.sendCommand(ON)
Leaving.sendCommand(ON)
}
end
rule "Turn the lights off when the Doorbird Motion sensor trips"
when
Item DoorBird_MotionSensor received command ON
then
if(Leaving.state == ON){
FrontYardSw1.sendCommand(OFF)
FrontDoorSw1.sendCommand(OFF)
Leaving.postUpdate(OFF)
}
end
If you were to add an expire on the switch proxy, would you need to still need both rules?
I’ve just started enhancing various rules of mine as I have run into scenarios where I either need different expire timers for the same item or have a switch (example snow shoveling) that prevent the expire binding from killing my outside lights while I’m shoveling out my driveway.
I have a similar rule that turns on my kitchen light at 30% if I walk by my motion sensor (for a late-night snack), and turns the light off when I head back to bed. There’s no need for the proxy item, you just need an if/else condition that checks if the light is off or on.
rule "Trigger Front Lights when the Doorbird Motion sensor trips"
when
Item DoorBird_DoorOpener received command ON
then
if(vTimeOfDay.state == "NIGHT"){
if (FrontYardSw1.state == OFF) {
FrontYardSw1.sendCommand(ON)
}
else createTimer(now.plusSeconds(30)) [ FrontYardSw1.sendCommand(OFF) ]
}
end
I wrapped the OFF command in a createTimer so that the light doesn’t go off too quickly when the person leaves.
I’ve read numerous comments saying that expire should never have been allowed into the system, so I’m avoiding it in case it gets removed in the future.
Hi Russell, I configured a very similiar approach about 30minutes ago, see attached I’d hoped to use the Doobird motion sensor but it only triggers when ON and won’t trigger when motion detection is reset, if it was, I could use that rather than a Timer.
var DoorBird_Timer = null
var DoorBird_TimeOut = 2
rule "Trigger Front Lights when Gate unlocked"
when
Item DoorBird_DoorOpener received command ON
then
if(vTimeOfDay.state == "NIGHT"){
gOutsideFrontLights.sendCommand("ON")
logInfo("Doorbird", "Lights on as its Night and the Gate was unlocked")
DoorBird_Timer = createTimer(now.plusMinutes(DoorBird_TimeOut)) [|
gOutsideFrontLights.sendCommand("OFF")
DoorBird_Timer = null // Reset the timer after 2 minutes
logInfo("Doorbird", "Lights off as its Night and the Timer expired")
]
}
end
How long does the Doorbird stay on before resetting? I was assuming it resets after a few seconds (as my Wemo motion sensor does). If that’s the case, you don’t need to worry about using the Doorbird reset as a trigger. You just need to trigger the rule when the Doorbird turns on, and have different actions based on current conditions.
In the rule I suggested, the rule is triggered when the Doorbird turns on (gate opens). The if/else condition checks that the light is off (which it is), so it turns on the light.
When the person leaves, the light will still be on as they walk away from the house. When they open the gate, the Doorbird will be triggered again. The if/else will see that the light is on, and the light will turn off after 30 seconds.
Does Doorbird_DoorOpener only turn ON when the gate is first opened upon arrival, and never again during their visit? Or does it turn ON when the gate swings close, then ON when the person opens it to leave, and ON when it closes for the last time?
My first suggestion assumed that DoorOpener turned ON one time when the person arrived, and ON again when they left (which is how my kitchen nightlight rule works). It sounds like that’s not the case.
It turns ON, once and only once when the gate is unlocked via the relay inside the unit. Without a method to switch it off, theres no way to do this. Blue Iris allows for ON motion to send a HTTP command and OFF motion to send a HTTP command, but Doorbird does not.
Gotcha. It does seem like just setting a timer is the simplest solution, then.
Alternatively, you could have DoorOpener turn the light on, then keep the light on as long as motion is detected (or turn it off after no motion has been detected for a period of time). However, that only works if the person will be in full view of your motion sensor until they leave.