Rule Example Wasp in Box

Hi @Andrew_Rowe,
thank you for this tutorial, which seems very interesting to me.

I have some questions and hope you can answer them.

  1. Are I’m correct that the network binding/mobile phones cannot be used to identify “buzzInBox”?
    The mobile phone could connect to the network even if I do not enter my home. E.g. sitting in the garden or walk on the street.
    My assumption is that only sensors that can be triggered within the house can be used.

  2. Please can you explain the confidence in more detail.
    It’s great that you have added a confidence calculation already, but unfortunately I cannot get how it works.
    Lets assume you left the home at 8:00 AM. The wasp is out of the box.
    Now there is a false alarm triggered by the motion sensor at 9:00 AM
    Calculation:

  • foneIsHome == OFF --> -20
  • openTime.isBefore(motionTime) --> +40
    One minute later the rule will be executed once again.
  • foneIsHome == OFF --> 20
  • openTime.isBefore(motionTime) --> +60
    Another minute later the rule will be executed once again.
  • foneIsHome == OFF --> 40
  • openTime.isBefore(motionTime) --> +100
    –> wasp in the box is now set to ON
    One (false) event set the wasp in the box to ON, which follows the algorithm, but the calculation just delays the behavior.
  1. How works your motion sensor? Does it make sense to trigger the rule “buzzInBox” with “received update”.
    My motion sensor triggers just the ON event, but not the OFF event. I’m using my motion sensor in combination with the expire binding (10 min).
    Lets assume the motion sensor recognized motion and set the switch item to ON for at least 10 mins. Now the door will be opened, but I’m coming back within 10 minutes.
    The motion sensor wouldn’t change from OFF to ON, so the wasp in the box will stay OFF.

I have some further questions, but honestly I’m not sure if I should post them here or if would be better to create a new topic for those questions.
4. I would like to combine @rlkoshak’s Generic Presence Detection Tutorial with your tutorial. The most important advantage is to have an anti-flapping timer and also the possibility to use the network binding for presence detection.

What do you both think about the following approach?

Switch Presence "Someone is Present" <present> // master presence switch, represents to the rest of OH where someone is home
Group:Switch:AND(OFF,ON) Presence_Sensors <present> 
Switch Presence_Timer { expire="5m,command=OFF" } // anti-flapping timer
Switch MobilePhonePerson1 (Presence_Sensors)
Switch MobilePhonePerson2 (Presence_Sensors)
Switch WaspInBox (gPresence_Sensors) 
Switch DoorSensor
Group gWaspSensors // all presence sensors in the building belong to this group
Switch MotionSensor1 (gWaspSensors) { expire="10m,command=OFF" }
Switch ... (gWaspSensors)
rule "Reset Presence and sensors to OFF on startup"
when
    System started
then
    Presence.sendCommand(OFF)
    Presence_Sensors.sendCommand(OFF)
end
rule "A presence sensor updated"
when
        Item Presence_Sensors changed
then

    if(Presence_Timer.state == ON && Presence_Sensors.state == Presence.state) {
        logInfo(logName, "Timer is running but group and proxy are the same, cancelling timer")
        Presence_Timer.postUpdate(OFF)
    }
    else if(Presence_Sensors.state == Presence.state) {
        logInfo(logName, "No timer and both group and proxy are the same, nothing to do")
        return;
    }

    if(Presence_Sensors.state == OFF) {
        logInfo(logName, "Everyone is away, setting anti-flapping timer")
        Presence_Timer.sendCommand(ON)
    }
    else if(Presence_Sensors.state == ON) {
        logInfo(logName, "Someone came home, setting presence to ON")
        Presence.sendCommand(ON)
    }

end
rule "Presence timer expired, no one is home"
when
    Item Presence_Timer received command OFF
then
    logInfo(logName, "Everyone is still away, setting presence to OFF")
    Presence.sendCommand(OFF)
end
rule "buzzInBox"
when
    Member of gWaspSensors received update //Use received update not changed, because of expire binding on Motion Sensors
then
    Wasp_in_Box.sendCommand(ON)
end
rule "boxOpened"
when
    Item DoorSensor changed to ON // OPEN
then
    Wasp_in_Box.sendCommand(OFF)
end
  1. With the approach above, the presence switch could be set to ON before I open the door. (Based on the network binding). I’m looking for an option to set the presence to ON, earliest when the door will be opened. Could you give some hints how to implement this requirement?

Thanks in advance :slight_smile: