How to build an office alarm system with Home IoT devices

Oliver Thamm

Building a security system with alarm and notifications using Home IoT hardware

Office security is a 100 billion dollar business. Trustworthy products and service providers come with a steep price tag. Specialised cloud-based solution providers come with the potential threat of misusing or selling your office’s IoT sensor data. Data privacy raises major concerns, since every supplier with access to data gets a full view of an office schedule—how employees behave and when the office is empty.

Hiring a security service company offers a good alternative to this. The security company could install a closed IIoT system within your company WiFi. But such services are very expensive.

A less pricey option is to use consumer market Home IoT devices and install it yourself. In this blog post, we show you how to make your own security system with just a bit of time and hacker spirit. Save a lot of money and no trust into an external security service company is required. We will show how to set up a text notification, play an alarm sound and change the color of a light to red when a motion sensor detects movement after 8pm.

Setting up the Home IoT motion sensor with lights

In Home IoT applications, motions sensors are often used to switch lights on only when they register movement within their range. In the right room this saves energy and money. The motion sensors keep associated lights switched off and switch them on only for a configurable timespan when they detect movement. If there is further movement around the sensor, the devices will remain switched on.

Home applications for this type of setup are often found in garages or driveways. Rooms in which people sit and stay usually don’t benefit. Also, pets can create unwanted side effects when they trigger motion sensors. In a small office, usage patterns are different to a private home. In an office before and after a workday, movement should trigger an alarm. Plus, it’s the kind of thing an office manager would like to know about.

For this post, we use the motion sensors of a global swedish furniture chain. Follow the basic setup as described by the vendor and our initial post. Screw open the back of the motion sensor device so you can see three buttons and put in batteries. Pair the motion sensor first with your hub device and then with the lights.

Go into the manufacturer's mobile app and test your setup. Use the app to name your light, e.g “room-a”.

Creating a service to report events and trigger an alarm

To access and react to events sent by the motion sensor, find out the device’s communication protocol. If the device communicates using keep-alive connections, e.g. CoaP or MQTT, then observe it’s messages. Otherwise frequently request, or poll, the device’s state.

The hardware we use works best when it does not directly observe the motion sensor but observes the associated light instead. That too is handled by drivers in IIoT Server. In Xapix IIoT Server drivers for this are included and you only need to configure the devices in the file “./config/devices.yml”. Additionally configure your speaker and put your desired alarm audio file, e.g. “alarm.wav”, into a new folder “./tmp/iiot_office/media/”.

One option to trigger alarms and send text notifications is to create your own local web server application. The web application needs to have an HTTP POST endpoint accepting JSON formatted data. In the code for the endpoint,put the decision logic for the alarm and notifications. Enter the endpoint’s URL as an environment variable named EVENT_WEBHOOK_URL for IIoT server.

A second option is to use our free Xapix Community Edition and it’s web UI to trigger data pipelines which change the light color, play an alarm sound and send text notifications.

Setting up a serverless alarm system pipeline on Xapix Community Edition

Create a Xapix account if you haven’t already. Follow the steps in our introduction blog post describing how to connect your IIoT Server with Xapix and create two External Executor Data Sources in Xapix Community Edition for your IIoT Server. On the sidebar click “Data Sources”, then in the top right corner “Add Data Source” and choose “External Executor”. Set them up like this:

In IIoT server configure your Xapix project and the External Executors just created. Enter the external executor names into the configuration option list called “executors”. Also set the “events_endpoint” name you will create in the next step.

First, create the data pipeline to respond to motion sensor events. On the left sidebar below “REST Endpoints” click “Add New”. Enter path “events” and select HTTP method POST.

On the pipeline dashboard click on the Request unit and within body parameters add the properties “name” and “value” of type literal and the property “data” of type object. Within the data object add properties “id”, “on”, “hsl” and “name” of type “literal”.

On the pipeline dashboard add a Decision Unit and create a branch named “intrusion”. The criteria identifying an intrusion event are:

  1. The source of the event is a light switch.
  2. The light switch has been switched on.
  3. The color of the light is not red. If the color is red already then the intrusion has already been detected and responded to correctly.
  4. The current time of the day is past the office hours.

Accordingly, enter this formula into the “intrusion” branch of your Decision Unit:

Next, add the External Executor units. Add the unit “play-sound”, connect the unit to the “intrusion” branch and fill in the parameters “cmd” with value “play”, “tune” with value “alarm.wav” and “device” with value “speaker”. Add the unit “change-bulb-color”, connect the unit to the “intrusion” branch and fill in the parameters “cmd” with value “bulb_on”, “color” with value “red” and “device” with value “room_a_bulb”. Connect both units with the Endpoint unit.

Click on the Endpoint unit and set the status to “201”. The alarm part of your system is now set up successfully.

Sending alarm text notifications and logging access 

For an alarm system in production you want to send text notifications for example as an SMS (e.g. through Twilio or Pager Duty) and log access through a different service (e.g. to a Slack channel). To test the setup use our webhook service and replace the Data Sources later on. 

Set up a webhook test site receiving and displaying the text notifications by clicking this link and wait for 5 seconds to get redirected. Keep the URL from the webhook test site and create a REST Data Source in Xapix Community Edition by clicking “Data Sources” on the left sidebar, then “Add Data Source” and next “Setup Data Source Manually.” Use the webhook URL as address here, set the HTTP method to “post” and make the body parameters look like this screenshot. When clicking the “Preview Data Source” button your webhook test site should receive a request and display its content. Finally, click “Save Data Source.”

On your pipeline dashboard add two webhook text notification units. Connect one of them to the “intrusion” branch, click on the webhook unit and for the parameter “message” enter the value “Intrusion detected!”. Connect the other webhook unit to the Request unit, click on the webhook unit and for the parameter “message” enter a formula containing the information you are interested in, for example:

Publish your project. The motion sensor events will now be logged and every detected intrusion will now trigger an alarm sound, turn the lights red and send a text notification.

The three events registered by the webhook upon an intrusion read like this:

Join our Home IoT community

We are working on follow-ups to this blog series and will post updates in our Discord community to inspire you with new ideas about how to use the Xapix IIoT Server once you have set it up. We would love to hear your ideas and collaborate! 

Contact us on our Discord community channel if you’d like to discuss this tutorial or have questions about the Xapix Community Edition. We look forward to hearing from you!

About the author

Oliver is a senior software developer and an API and data transformation enthusiast. He’s a co-founder of Xapix, writer and conference speaker on all things API. Most recently, he’s bringing his perspective and experience to the world of Industrial IoT.

You can get in touch with Oliver via or find him on our Xapix Community Discord.