First project, Security alarm, comments?

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

nice one, i just used parts of your coding to make mine , when finished i will post the improvements as i am still making some extra rules to my motion and door sensors

I look forward to some improvements, I am sure there can be a few. I have added a few more motion sensors and put the server on a UPS.

Cheers,

Hi man,
I only want to make a simple alarm system using for the beginning only one magnetic contact installed on my front door. This contact works with mqtt and it shows me when the door it’s open or closed.
I would like to make the simplest alarm system using this contact (later I want to add a motion sensor) so when arming the system in case the front door it’s open to send me an email after lets say 15 sec that it is alarm! When I come back home, I enter the password within 15 sec and the alarm is disarmed!
I don’t know what to take from your settings to make this simple alarm system.
Could you please help with an advice?
Thanks!

Any news here?
@George_Whitehouse i suppose you have a Rpi gateway or so as a main server together with arduino or your reeds connected directly to your pi. Is the mqtt gateway stable? I have something similar using the mqtt but not the mysensors solution. I use nr24l01 to connect my Rpi with arduino and time to time I can say that the info isn’t sent well! I mean I can open the door and the reed will not get the info or the info isn’t sent to the server! How did you connected the reeds? Directly to your controller?
Do you have some other scripts running with your rules?
It would be great if you’d post here the latest config you have.
All the best!

Hi,

In the last few days I have switched my openhab over to a RPi3, so far so good and a bit of a leaning curve from a old windows box. (I found this very helpful for getting the base setup working although can not get the Designer running on 32bit Ubuntu (works fine on a 64bit laptop), loads and shuts down immediately)

Yes, I have found the mysensors MQTT gateway to be a reliable way to get states (reeds, relays & distance) to openhab. I like that it is separate from my openhab install so I can test just the messages coming/going via MQTT and it has made fault finding easier in the past with MQTTlens. Certainly useful to be able to check at a raw level if yours sensors/actuators are operating ok.

No other scripts running with the rules above, I have not really changed much from the above just using Telegram a bit more for notifications.

Cheers,
George