Complex Alarm rules

homematic
array
Tags: #<Tag:0x00007f1e5bb3b098> #<Tag:0x00007f1e5bb3af08>
(Kevin) #1

I want to build a alarm system with multiple states and actions depending on what caused the alarm.

First some Setup Information
I’m running openHAB 2.3.0 on a local Debian 9 Server (x64, 8GB RAM).
My Smarthome componeds are mostly Homematic and I use the CCU2 as bridge with the homematic binding.

About myself
I’m a full time PHP Developer, but I don’t have any clue about Java

My plan is to have 2 armed states. One that ohnly checks if someone opens a door or window, and one that also checks for activity inside the home.

I also plan to have 3 alarm levels. Depending on the armed state, and what caused the alarm, I want to definie if the alarm starts on Level 1 or 2.

Currently I have items to define the armed state and the alarm level, and also some rules that react to this items.

In my old rule I had only a group with all Sensors and reacted to changes in the Group. But that has two problems. First i dosn’t work when one window is open (for example the sleeping room during night) and the second problem is that I don’t know which door has been opened.

My attemp as a PHP Programmer would be to save every state in an array, and when the group get’s an update compare these to see what items have changed. How can i do this in openHAB? I don’t want to go over the persitence becaus it is slow and in my test far away from reliable

0 Likes

(anonymous.one) #2

You may want to check out triggering items, here is an example:

rule "Member pressed"
when
    Item group_1 received command or
    Item group_2 received command
then
   logInfo("GroupTest", "Member " + triggeringItem.name + " to " + triggeringItem.state)
end
0 Likes

(Rossko57) #3

You might find member of myGroup rule triggering helpful, as it allows identification of the triggering Item.

0 Likes

(Kevin) #4

Looks like Member of goes into the right direction. But one problem left. How do I ignore windows that where already open at the moment of arming?

0 Likes

(Patrick Malcolm) #5

I think using ‘changed from … to …’ in the trigger should work:

when
    Member of MyGroup changed from CLOSED to OPEN
then
     ...

This won’t trigger if a window is already open and receives an OPEN update.

0 Likes

(anonymous.one) #6

You can use an if condition in the rule that checks armed.state == ON as an example. If its off then the rule won’t continue.

0 Likes

(Kevin) #7

from CLOSED to OPEN is not safe, because the wind could close the window and reopen it.

0 Likes

(Patrick Malcolm) #8

If you want to account for that possibility, the only way I can think of is to have a rule that triggers when the security system is armed which populates a “triggering group” with only the windows which are closed at that time. This triggering group is then used in the trigger of the main rule. Something like:

rule "Arm Security System"
when
    Item securitySystem changed to ON
then
    // Empty the trigger group
    trigGroup.members.forEach[ item | trigGroup.removeMember(item)]
    // Add back the closed windows
    WindowGroup.members.filter[s | s.state == CLOSED].forEach[item | trigGroup.addMember(item)]
end

Note, I haven’t tested this code and I’m not that familiar with dynamically creating groups, so this might need some modification to work correctly. You can see some similar examples here.

1 Like

(Kevin) #9

That sounds good, I will test that.

Update:
Seems to work so far :slight_smile:

1 Like