Node-RED + Home Assistant Security System

In this post, I will show how I setup my home security system. Setup this way, it is a manual system, and will need to be manually armed and disarmed. I will share how I’ve automated the system in later posts, that will be linked here.

My last two houses were smart homes. SmartThings was my hub of choice at the beginning, and it was good. One of the things I liked so much about SmartThings was the Smart Home Monitor that is built in. This does a few things, one of which is act as a security system, which is what we used it for. There is nothing like this built into Home Assistant out of the box, so one of my first goals when learning Node-RED was to create a home security system.

Home Assistant has a built in Manual Alarm Control Panel that can be used to build a security system, which all has to happen in the config files. Since I’m doing all of my automations in Node-RED, I wanted to try building a security system from a combination of the built in panel and Node-RED. I wanted to be able to set the alarm mode from the panel and have Node-RED handle the rest.

To start off, I created an “alarm.yaml” in the config directory of Home Assistant, and made sure to add “alarm_control_panel: !include alarm.yaml” in the config file. This is the code that I used, which will allow the away alarm to trigger after 120 seconds, and give you 30 seconds to leave the house once it’s armed. All other modes arm instantly.

This will create a “alarm_control_panel.home_alarm” entity, which when used in Lovelace, looks like this:

So now that the front-end is done, time to move on to the back-end of the machine. I built all of the logic within Node-Red. This is how the finished result looks.

The “events: state” node undefined grabs the status of the Manual Alarm Control Panel, and passes it on to the switch node undefined which then filters the alarm status to the appropriate output.

Below that, is the trigger automation. The “Alarm Triggers” sub-flow contains all of the doors and windows in the house, which is connected to another sub-flow that checks if the alarm is armed either home, or away, and then passes it on to a call service node that triggers the alarm, and finally sends a Telegram notification letting us know the alarm has been triggered, along with a button to Disarm the alarm. Example of the “Armed Home” sub-flow.

Sub-flow for the Armed Home mode for reference,

Since there’s so much going on with this flow, I won’t go through it in detail, but I will post the code which you should be able to work off. It’s pretty straight forward.

Here’s the Node-RED code: Security System
Here’s the yaml code for the panel: alarm.yaml

Currently, there is zero automation involved. This has to be manually set, but I have location and timed based automations which I will share in future postings.

Updates:

8/24/2020 – Updated the alarm.yaml code to reflect recent updates Home Assistant has had regarding the manual alarm panel.