Gday,
I have had a steep learning curve so far but enjoying learning openHAB and its amazing possibilities. It has been great to get some weather binding stuff along with owntracks & geofences working (thanks again for the fellows who helped out) as well as some of the basics on items and sitemaps.
While I eagerly await delivery of a some zwave & mysensors.org hardware I thought I would start exploring rules with a security alarm project.
Would be great to get any suggestions for improvement or change.
If you have put in a security type rules what have you added?
One part I am a bit stuck on is stopping it going into ‘ON’ or ‘Internal’ mode if Item Alarmenable is OFF. Any thoughts there would be great.
Inputs:
Reed switches, Windows (mysensors MQTT gateway & hardwired reed switches)
Reed switches, Doors (mysensors MQTT gateway & hardwired reed switches)
Movement, PIR’s (x2) (Zwave Aeotech multisensor 6)
Presence, myself & dear wife (owntracks region based presence, reminder to turn on)
Outputs:
Siren & strobe
Trigger all lights on (a little down the track)
Email & my.openHAB notifications
Items:
Number Alarmmode “Alarm mode” /[1=OFF, 2=ON, 3=Internal]/
Switch AlarmOFF “AlarmOFF"
Switch AlarmON “AlarmON"
Switch Alarmenable “Alarmokenable"
Switch Alarminternal “Alarminternal"
Switch Alarmtriggered “Alarmtriggered"
Switch Windows “Window Reeds” {mqtt=”<[mosquitto:MyMQTT…to fill in],<[mosquitto:MyMQTT…to fill in]”}
Switch Doors “Door Reeds” {mqtt=”<[mosquitto:MyMQTT…to fill in],<[mosquitto:MyMQTT…to fill in]”}
Switch PIR1 “PIR1” {mqtt=”<[mosquitto:MyMQTT…to fill in],<[mosquitto:MyMQTT…to fill in]"}
Switch Siren “Siren” {mqtt="<[mosquitto:MyMQTT…to fill in],<[mosquitto:MyMQTT…to fill in]"}
Sitemap:
Frame label=“Alarm” {
Text item=Siren label=“Siren ON/OFF [MAP(NoOFFYesON.map):%s]” icon="siren"
Text label=“Alarm” icon=“settings” {
Switch item=Alarmmode label=“Alarm mode selection” mappings=[1=OFF, 2=ON, 3=Internal] icon="settings"
Text item=Alarmenable label=“Alarm ABLE TO BE TURNED ON [MAP(NoOFFYesON.map):%s]” icon="info"
Text item=Alarmtriggered label=“Alarm triggered [MAP(NoOFFYesON.map):%s]” icon="info"
Switch item=Windows label=“Windows MANUAL” icon="settings"
Switch item=Doors label=“Doors MANUAL” icon="settings"
Switch item=PIR1 label=“PIR1 MANUAL” icon=“settings"
Text label=“Information Items” icon=”_down"
Text item=Siren label=“Siren ON/OFF [MAP(NoOFFYesON.map):%s]” icon="siren"
Text item=Windows label=“A Window open? [MAP(NoOFFYesON.map):%s]” icon="info"
Text item=Doors label=“A Door open? [MAP(NoOFFYesON.map):%s]” icon="info"
Text item=PIR1 label=“PIR1 triggered [MAP(NoOFFYesON.map):%s]” icon=“info”
}
}
Rules:
//Alarm Rules
rule "GW & NW not home but alarm off"
when
Item PresenceGW changed to OFF or
Item PresenceNW changed to OFF
then
if(PresenceGW.state==OFF && PresenceNW.state==OFF && AlarmON.state!=ON) {
sendMail("myemail@gmail.com", "No one home, set alarm?", "")
sendBroadcastNotification("No one home, set alarm?")
}
end
rule "Alarm Mode"
when
Item Alarmmode received command
then
if(receivedCommand==1) {
sendCommand(AlarmOFF, ON)
sendCommand(AlarmON, OFF)
sendCommand(Alarminternal, OFF)
}
else
if(receivedCommand==2) {
sendCommand(AlarmOFF, OFF)
sendCommand(AlarmON, ON)
sendCommand(Alarminternal, OFF)
}
else
if(receivedCommand==3) {
sendCommand(AlarmOFF, OFF)
sendCommand(AlarmON, OFF)
sendCommand(Alarminternal, ON)
}
end
rule "Alarm ok to enable"
when
Item Windows changed or
Item Doors changed or
Item PIR1 changed or
Time cron "1 * * * * ?"
then
if(Windows.state == OFF && Doors.state == OFF && PIR1.state == OFF){
sendCommand(Alarmenable, ON)
}
else
sendCommand(Alarmenable, OFF)
end
rule "Alarm triggers 'ON' mode"
when
Item Windows changed to ON or
Item Doors changed to ON or
Item PIR1 changed to ON
then
if(AlarmON.state==ON) {
sendCommand(Alarmtriggered, ON)
}
end
rule "Alarm triggers 'Internal' mode"
when
Item Windows changed to ON or
Item Doors changed to ON
then
if(Alarminternal.state==ON) {
sendCommand(Alarmtriggered, ON)
}
end
rule "Alarm triggered"
when Item Alarmtriggered changed to ON
then
sendCommand(Siren, ON)
sendMail("myemail@gmail.com", "ALARM has been triggered!!!!!", "")
sendBroadcastNotification("ALARM has been triggered!!!!!")
atimer = createTimer(now.plusSeconds(300)) [|
sendCommand(Siren, OFF)
atimer = null
]
end
rule "Alarm turned off, reset all"
when
Item AlarmOFF changed to ON
then
sendCommand(Alarmtriggered, OFF)
sendCommand(AlarmON, OFF)
sendCommand(Alarminternal, OFF)
sendCommand(Siren, OFF)
// Add other resets here
end
Kind Regards,
George