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
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
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.