Advanced Events handling in Domoticz

In previous post (can be found here) we created a simple event handler in Domoticz to control a power plug based on the events from a motion sensor. In this post we will step it up a notch and build a basic alarm system. If you are not familiar with the Events interface in Domoticz, we recommend you go through our previous post first.

Building a basic alarm system using the Events interface in Domoticz

We want our alarm system to be able to do the following once we have set up the handling of the events:

  • Arm/disarm the alarm system
  • Trigger the alarm (if armed) with a delay of 45 seconds. The reason for this is that we want to be able to enter the door and have time to disarm the alarm without triggering
  • Stop the siren if entering the correct pin code
  • Let the siren time-out after 3 minutes. The alarm system will still be in ”armed” mode. If the burglar has not been scarred after 3 minutes, the siren will most likely only annoy your neighbours.

For this project, we will use the following hardware:

We will be using the Z-Wave Power Plug to switch on a lamp instead of a siren, since it’s more friendly for our ears while developing. Once you’re done, it’s simple to exchange the power plug for a Z-Wave siren.

Starting with a map of states for the alarm system

Since this is a slightly more advance event handling then simply have a motion sensor control a lamp, we need to map out which states our alarm system can have during operation:

  • State 1: Disarmed
  • State 2: Armed
  • State 3: Motion Triggered
  • State 4: Sound siren!

The alarm system will switch state dependant on the events appearing. Here is how the system will jump between different states:

  • Person arming the system on the security panel: the system will jump to ”Armed”.
  • Person disarming the system on the security panel: the system will jump to ”Disarmed” regardless of previous state, the siren will be turned off.
  • If the system is armed and the motion sensor is triggered: the system will jump to ”Motion Triggered”
  • If the system is in ”Motion Triggered” after 45 seconds: the system will jump to ”Sound siren!”
  • The siren has sounded for 3 minutes: the system will jump to ”Armed” and the siren will be turned off. The system is ready to detect new motion.

Sketching this on a piece of paper looks something like this:


I know it looks a bit cluttered but it will be a big help when building the event handling.

Controlling events using states in Domoticz

First we need to create two things that we need for building our alarm system:

  1. A user variable that we call: ”Alarm State”
  2. A dummy switch that we call: ”Sound Siren”

Creating a user variable in Domoticz

Go to the Domoticz ”Setup” drop-down menu and select ”More Options” -> ”User variables”.


Then enter the name ”Alarm State” and the variable value ”1”, and click ”Add”.


Creating a dummy switch in Domoticz

Go to the ”Setup” menu and select ”Hardware”. This view should be familiar to you by now.


Enter the name ”Sound Siren” and select ”Dummy” in the ”Type” drop-down list. Click ”Add”.


The dummy hardware appears in the list where your Raspberry is. Next, click on ”Create Virtual Sensors”.


Enter the name ”Sound Siren Dummy” and select ”Switch” in the ”Sensor Type” drop-down list. Click ”OK”. We will use this dummy switch to decide if we should start the siren. The condition is that we are in alarm state ”Motion Triggered” and that the delay time of 45 seconds has passed. Now, on to building the events handling.

Building the events handling using the Events (Blockly) interface

Select ”More Options” -> ”Events” from the ”Setup” menu. You can check the previous post if you’re not familiar with how the Events interface works (here). To arm our alarm system, we build the following event handler.


This will move the alarm system from state 1 (Disarmed) to state 2 (Armed). You find the ”Alarm State” variable in the category ”User variables” in the left side menu. The ”Security status” switch is found in the ”Security” category and is directly controlled by the Domoticz security panel that we will use later on. We save the event with the name ”Arm alarm”. Don’t forget to tick the check box ”Event active”. Next we create an event handler for disarming the alarm system.


This event handler puts the alarm system in state 1 (Disarmed) regardless of previous state. We also sets our Z-Wave power plug to ”Off” since this represents our siren and we want the siren to be turned off once a valid pin code is entered on the security panel. Most often the siren is not on when someone enters the pin code since the most common use case is that you enter the pin code as soon as you open the door. In this case you have 45 seconds to disarm the alarm system before the siren goes off. We also make sure the dummy switch ”Sound Siren Dummy” is set to ”Off”. We save this event handler with the name ”Disarm alarm”. Next we will create the event handler for state 2 (Armed).


This event handler captures the event of the motion sensor, puts the alarm system in state 3 (Motion Triggered), and starts a timer to sound the siren after 45 seconds. This time allows the owner of the house to disarm the alarm system without the siren going off. Save it as ”Motion triggered”. We’re almost done, we now make the event handler for jumping from state 3 to state 4 (Sound siren!).


If we get the event of ”Sound Siren Dummy” after the 45 seconds time delay in state 3, we should sound the siren. We also sets a 3 minute (180 seconds) time-out on the siren. Save this as ”Sound siren”. Finally we need to create an event handler for state 4 (Sound siren!).


This will turn off the siren after 3 minutes and put the alarm system in state 2 (Armed) and the system will be ready to detect new movement. We save this event handler as ”Siren time-out” which will give us the following complete list of event handlers:


Next we go on to using the security panel of Domoticz.

Using and configuring the security panel in Domoticz

If you go to the ”Setup” menu and select ”More Options” -> ”Security Panel”, you see this view.


With this panel, you can arm and disarm the alarm system with just built. You can select the pin code in the ”Setup” menu under ”Settings”. Here you can also set a delay time in order for you to have time to exit your house before the alarm system is armed. Once you have tested the alarm system to make sure it works ok, you can replace the Z-Wave power plug with a Z-Wave siren.