A control panel powered by Raspberry Pi 3 using a touchscreen and Android Things to communicate with Home Assistant over MQTT.
This project is an MQTT Alarm Control Panel for pairing with Home Assistant’s Manual Alarm Control Panel component or with any home automation platform that supports the MQTT messaging protocol such as OpenHab, Node-RED, or cloud-based MQTT services.
This project was built using a Raspberry Pi 3, an externally powered speaker (the Piezo Buzzer is no longer used), and a 7″ touch screen display running Android Things. Optionally I am using an Raspberry Pi Camera Module v2 to capture images when the alarm is deactivated.
Home Assistant and Android Things
Home Assistant is an open source home automation platform with the ability to integrate with many hardware components, as well as offer custom features for automation and MQTT messaging. I created a prototype alarm panel using a Raspberry Pi which interfaces with Home Assistant’s Manual Alarm Control Panel and communicates using MQTT.
Using Android Things for the software allowed me to create a rich user interface, and gives me the flexibility to deliver the same product on multiple platforms including Android tablets and phones.
Through the alarm panel interface, I can set the alarm state to away or home, or disarm the alarm using a code. Home Assistant controls the sensors and automations, which trigger the siren and notifies me of a possible intrusion.
In my home I have several Z-Wave door sensors, a motion detector, and a siren, all hooked to Home Assistant using an Aeotec Z-Stick. Home Assistant can read the state of the sensors, and using the manual control panel, publish MQTT messages.
For example, if my alarm has been triggered by an open door, a MQTT message is sent and the hardware alarm panel responds by displaying the disarm dialog with a constant beep to alert me. I can then disarm the alarm system from the alarm panel by entering the code which sends a MQTT message back to Home Assistant to reset the alarm system. If no code is entered in the set period of time, the alarm will sound.
Preparing Home Assistant and MQTT
To use the application with Home Assistant you need Home Assistant v.0.50 or above, which includes the new Manual Alarm Control Panel, as well as the MQTT service properly setup and configured. I won’t go into details about how to setup Home Assistant or MQTT because the documentation provided by Home Assistant is better than I could provide.
Be sure to have the the Home Assistant’s manual alarm control panel component setup. Here is the default setup for the manual alarm control component in the configuration yaml file:
- platform: manual_mqtt
command_topic: home set
Here is an example automation in Home Assistant for triggering the alarm from a sensor state change:
- alias: 'Trigger alarm while armed away'
- platform: state
- platform: state
- condition: state
If you decide to use an automation system other than Home Assistant, you will need to use the same publish states and commands to communicate with the alarm control panel.
Default Command and Publish States
- Command topic: home/alarm/set
- Command payloads: ARM_HOME, ARM_AWAY, DISARM
- Publish topic: home/alarm
- Publish payloads: disarmed, armed_away, armed_home, pending, triggered.
The Alarm Control Panel will send the command topic with a payload to notify your home automation system to arm or disarm. The MQTT service will use the publish topic with the payload to notify the Alarm Control Panel of the current alarm state, which will update the interface accordingly.
I am using a basic set of components for the hardware. Sm Here is a complete list of the hardware used.
- Raspberry Pi (needs to be compatible with Android Things)
- Touchscreen display, I used a 7″ screen but any touch screen compatible with Android Things would work.
- Micro SD card to burn the Android Things image
- Micro USB cable for power.
- (Optional) Externally powered USB speakers with analog connection
- (Optional) Raspberry Pi Camera Module v2 to capture images
Raspberry Pi Setup
Make sure you properly setup the RPi3 with the 7″ Touchscreen display. You won’t need any special software setup if you use the The Raspberry Pi Foundation 7″ Touchscreen, as it’s compatible with Android Things. Other compatible touch screens may require additional configuration for use with Android Things.
Download the latest build (zip file) from the project’s GitHub release release section, which includes Android Things Preview 0.4.1 with the alarm panel application already pre-installed. This option also allows you to receive future OTA (over the air) updates.
- Download the latest release zip: MQTT_Alarm_Control_Panel_1.x.x.zip.
- Unzip the file to get the the image: iot_rpi3.img.
- Burn the image to your SD card using a tool like Etcher.
- Insert the SD card into RPi3 and boot.
Setup Network Access and Timezone
Be sure to set up network access either using WiFi or ethernet. If you set up WiFi be sure to unplug the Ethernet cable, at this time Android Things can’t use both.
Once you have the application running, go to Settings -> Device Settings and enter your WiFi SSID (name) and password, it should connect automatically. Optionally, you can use the Android Things Setup Utility to setup the device WiFi connection and update the timezone from the application settings or you can use the adb command line tool to change them manually.
# Use the adb tool to connect over ethernet to the device
adb connect Android.local
# Then set your your WiFi SSID and password
adb shell am startservice \
-n com.google.wifisetup/.WifiSetupService \
-a WifiSetupService.Connect \
-e ssid <Network_SSID> \
-e passphrase <Network_Passcode>
You probably also want to set the time and timezone of the device. You can do this within the application by going to Settings -> Device Settings and set the time zone. This can also be done from within the application settings or manually using the adb command line tool:
Reboot ADB into root mode
Set the date to 2017/12/31 12:00:00
adb shell date 123112002017.00
Set the timezone to US Mountain Time
adb shell setprop persist.sys.timezone "America/Denver"
Alarm Panel Setup
When you first start the application, you will be asked to go to the settings screen and where you can setup the device and alarm code. You also need to enter your MQTT broker address, port number, and credentials, if applicable.
Be sure to adjust the pending time intervals to match those set in the Home Assistant manual alarm control panel component, if not using the default values.
Once setup, the application should connect to your MQTT broker and display the current state of the alarm control panel in Home Assistant.
Whenever the state of the alarm control panel in Home Assistant changes, the alarm control panel will reflect those changes. In order to deactivate the alarm, you will need to enter you pin code within the time allowed.
To set the alarm, just select the main icon on the alarm screen, and then select Arm Home or Arm Away options.
A small countdown will appear to indicate the time remaining before the alarm is activated.
Home Automation Platform page
You can also load your home automation platform website by entering the address with port into the settings. It slides from the right on the main screen.
If you would like to get weather updates, create and enter a Dark Sky API keyand your current latitude and longitude into the weather setting screen. You can get your current location by using maps.google.com in a web browser and copying the lat/lon from the url (they look like -34.6156624,-58.5035102 in the url).
Capture Images (Telegram/Mailgun)
If you would like to capture and email images when the alarm is deactivated then you will need a camera that works with Raspberry Pi 3 (I am using the Raspberry Pi Camera Module v2).
If you would like email images when the alarm is deactivated then you also need to setup a Mailgun account. You will need to enter the domain address and API key from your Mailgun account into the application setting screen along with other information.
You may also use Telegram to receive a notification with the image when the alarm is deactivated. To use Telegram you need a chat Id and a Telegram Bot API token. Follow the Telegram guide on Home Assistant to setup Telegram. Enter the chat Id and token into the application settings screen.
PIR Sensor (Optional)
If you would like the alarm panel to awake when motion is detected then add a PIR sensor following the Fritzing diagram provided.
Current Project / Post can also be found using:
- alarm home assistant
- home assistant alarm mqtt