(Dis)able alarm scenario

For the moment, we’ve got some global homestatus (home, away, sleep).
And we’ve got some door and window sensors.

I would like to create a rule that waits fe 2 minutes to alert when we come home. This allows us to change it to home.
And doesn’t do anything for 5 minutes after the status change to away. This to safely leave the house with the status away.

Something like:
. if doorsensor change to open
. and homestatus was 5 minutes ago = home
… do nothing, else
… if homestatus = away
… delay 2 minutes
… status = home
… do nothing
… else ‘trigger alarm’

I don’t have an idea how I could check the status of fe 5 minutes ago.
Other suggestions are of course also welcome to complete this idea.

Thanks!!!

Use a status item (no local variable but an item defined in items file) and persistence. Use historicState or one of the other methods to query past states, see wiki.

You can also use timer that starts when your home state change to a special status. When a sensor detect something you check the timer against a limit and do nothing or act following this check result.

I would create a virtual Item (an item not connected to any real device) and use it control the “alarm” status e.g. a switch for alarm-enabled. That allows you to separate alarm from home/away conditions that you are setting yourself.

When something happens you want to trigger alarm, e.g. door changes to open
First check if the alarm is wanted e.g. “alarm enabled” state
If enabled, start a 2 minute timer that will perform the alarm action when it expires, but only if alarm is still enabled at that time.
You might immediately start a beep or flash device to remind you to cancel the alarm, too.

That’s your basic alarm sequence.

Set up other rule(s) that will act when you “disable” the alarm
e.g. when changing status to "at home"
Set the alarm enabled switch to off.
(and cancel any beep/flash)

That gives your grace period (entry timer) when coming home.

Set up other rule(s) that will act when you “enable” the alarm
e.g. when changing status to "away"
You might want some cleverness first that checks for e.g. windows open and immediately alerts you if there is a problem. You’d miss out your usual exit doors
And/Or you might start a beep or flash device to tell you that the alarm will be enabled soon.
If all OK then start a 5 minute timer that will set the alarm-enabled switch to on (and cancel any beep/flash), when it expires.

Later on you could add more sophistication like real alarms e.g. what to do after an alarm is made, do you want to alert on more violations later or not.

Hello @brononius

as @1technophile mentioned, I recommend timers too.

Szenario Leaving:

  • Activate Away-Szene
  • Start Timer
  • Activate alarm

Coming home:

  • Detect open door
  • grace period with optical and/or acustic countdown
  • if state isn’t changed to home --> alert
  • else cancel all

Be aware, that you only start the grace period when the door is opend (I think you never come home through a window :wink:

BTW: I plan something similiar with additional bluetooth and WiFi detection of allowed people to raise the usability and/or a small touchscreen to enter a pin.

regards
Michael

I guess I’ll use an item (extra) status to put this all together.
It same to me the easiest way to do this (I’m rather new to openhab and this scripting stuff :blush:)
And this way, the status can be used elsewhere as well?

Something like:

rule "Set Alarm Phase"
        when
        	Item AlarmButton changed
        then
         	if (AlarmMode.state == "GREEN") {
         		AlarmMode.sendCommand("YELLOW")
         		Thread::sleep(5000)
		AlarmMode.sendCommand("RED")
	        	logInfo("AT_Bureau", "Alarm is now ON")
  				} else {
  					Thread::sleep(5000)
  					AlarmMode.sendCommand("GREEN")
	        			logInfo("AT_Bureau", "Alarm is now OFF")
  				}
		end


rule "Open DOOR"
	when 
		Item Sensor01 changed to OPEN or
		Item Sensor02 changed to OPEN 
	then
		if (AlarmMode.state == "RED") {
			Thread::sleep(5000)
			logInfo("AT_Bureau", "Alarm must be deactivated in 5sec")
			Thread::sleep(5000)
		if (AlarmMode.state == "RED") {
			pushover ( "Alarm is being activated...." )
				}
			} 
	end

Of course, suggestions for improvement are more then welcome!