Our project is about securing your home with voice commands. In day-to-day life, there are many robberies going on. This is our main motivation in building our Home Security System. But why voice controlled?
We started using our security system by manually setting it but we missed many times securing the home when we are in hurry. Sometimes we secured the home without checking the doors. This became troublesome for us, so when Alexa came into the picture, we thought it would be great if we can set it function by voice. After designing it to work with Alexa it became very easy to set it, even my 5 year old can secure our home now. It will also help people with disabilities. People who are not able to operate it, could do so easily with a conversation. The features provided in our project will definitely make you feel the importance of voice conversation.
Here is the link for our application.
Here is the demo video of a few Alexa conversations.
HardwareWe used Alexa to experience effective interaction and the Home Assistant application to build the security system which includes Z-Wave smart devices with the help of Raspberry Pi. I hope you all feel secure with our effort.
FeaturesAs it is a security system, there are many things to be taken care of. The following are features provided by our project. Here we go:
- Securing the home by saying Alexa, ARM HOME / STAY / ARM AWAY / DISARM
- Gives the status of doors (open/close)
- Switching on/off the security camera / siren
- Gives information about temperature
We provided two options in securing your home. They are as follows:
- You can secure your home directly by saying Alexa, ARM HOME / STAY / ARM AWAY / DISARM.
- You can just say Secure my home then Alexa will ask for your choice of options and will set accordingly.
There are two ambiguities you may notice in the above description.
Firstly, setting ARM AWAY while staying at home with Alexa!! We came up with an Alexa Scheduler in order to perform this. By saying ARM AWAY Alexa will schedule it after 2 mins which is defaulted and can be customized. A confirmation notification will come to your phone once your scheduled event is processed successfully.
Secondly, if any third person knew about disarming the alarm with Alexa!! Yes we may fall into trouble. We care about security so we provided an option for disarming with authentication. To disarm the security system with Alexa, an authentication process is made mandatory. If it passes, then it will disarm the security system, and if not, it will give you notifications about the presence of stranger.
Securing the Home by Keeping the Doors Open!
If you say Alexa ARM HOME / ARM AWAY, then it will check all the doors and if they are open, it will warn you to close the doors. This is where voice helps, otherwise we would check each and every door. Even if we are in hurry, we will be safe with this. It usually happens in this busy life that we may forgot closing doors, so Alexa is a really helpful friend by securing you. You can ask Alexa about doors status.
Switching ON Camera/Siren When Securing
If you tell Alexa to Secure, it will switch on the camera/siren automatically. If you do not want the camera to turn on, you can toggle off/on the camera by a voice command.
Setting Security to Already Existing State
If you ask Alexa, you can set ARM HOME, and if it is already presently in that state, it won't set it again, instead it will give you the information.
It also gives more information like temperature in the home.
DevelopmentWe had developed it using the following components:
- AWS IOT
- AWS Lambda
- Alexa skill
- Custom PI service
- Custom API's for the Z wave Devices.
- Home assistant for configuring z wave devices and security system.
Let’s go through the steps of development. For developing, you need an Amazon developer account and access to Amazon web services.
Step 1: Setup AWS IOT- Go to https://console.aws.amazon.com. Select AWS IOT.
- Click Create Resource and then create a thing
- A thing with the given name will be created. Click on the thing which opens a side panel, make a note of REST API endpoint and MQTT topic which will be used later. Then click on connect a device.
- Then select nodejs and navigate to generate certificate and policy.
- It will generate public key, private key and certificate. Download all three keys - this is very important as it will generate only once, and if we miss them, we need to do the whole process again. These keys will be used later. Then click on confirm & start connecting.
Now AWS IoT is done. Let’s create Lambda Function in the next step.
Step 2: Creating Lambda FunctionGo to https://console.aws.amazon.com
- Select Lambda function
- Click on “Create a Lambda function”
- Go down to the bottom of the page, and “Skip” selecting a blueprint.
- In configure triggers select Alexa Skills kit and then click next.
- Name your lambda function as desired and make a note of function name which will be included in upload script later. We uploaded our code using script. Leave runtime as Node.js, and select “Edit Code Inline”
- Select role as create a custom role then a new window will pop up as below.
- Click on view policy Document and then replace policy document with below snippet in order to allow access to AWS IoT.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:*:*:*"
},
{
"Action": [
"iot:*"
],
"Resource": [
"*"
],
"Effect": "Allow"
}
]
}
- Then click on Allow. Change the time out to 12 sec then click next.
- Review all the details and click on create function.Make a note of ARN number and function name.
- Click on Alexa and then select Alexa Skills kit. Click on add a new skill then give skill information as desired.
- In the next step of interaction model give the below intents and speech assets.
Intent Schema
{
"intents":[
{
"intent": "ArmMyHomeIntent",
"slots": [
{
"name": "secure",
"type": "LIST_OF_SECURITY"
}
]
},
{
"intent": "ARM"
},
{
"intent": "SetCameraIntent",
"slots": [
{
"name": "camera",
"type":"LIST_OF_STATES"
}
]
},
{
"intent": "GetSecurityStatusIntent"
},
{
"intent": "GetDoorStatusIntent",
"slots": [
{
"name": "door",
"type":"LIST_OF_DOORS"
}
]
},
{
"intent": "GetAllDoorStatusIntent"
},
{
"intent": "AuthenticatingIntent",
"slots": [
{
"name": "authenticate",
"type":"AUTENTICATIONS"
}
]
},
{
"intent": "GetTemperatureIntent"
},
{
"intent": "AMAZON.HelpIntent"
},
{
"intent": "AMAZON.YesIntent"
},
{
"intent": "AMAZON.NoIntent"
},
{
"intent": "AMAZON.StopIntent"
},
{
"intent": "AMAZON.CancelIntent"
}
]
}
Sample Utterance
ArmMyHomeIntent {secure}
ArmMyHomeIntent as {secure}
ARM to secure
ArmMyHomeIntent to secure my home as {secure}
ArmMyHomeIntent to secure as {secure}
ArmMyHomeIntent to set as {secure}
ArmMyHomeIntent to {secure}
GetSecurityStatusIntent what is my home status
GetSecurityStatusIntent whether home is secure
SetCameraIntent switch {camera} security camera
SetCameraIntent to switch {camera} security camera
SetCameraIntent switch {camera} camera
GetSecurityStatusIntent whats the statuts of security system
GetSecurityStatusIntent tell me the status of security system
GetSecurityStatusIntent let me know the status of security system
GetSecurityStatusIntent security system status
GetSecurityStatusIntent security status
GetDoorStatusIntent what is the {door} door status
GetDoorStatusIntent tell me the {door} door status
GetDoorStatusIntent {door} door status
GetAllDoorStatusIntent list the open doors
GetAllDoorStatusIntent which doors are open
GetAllDoorStatusIntent which doors need to close
GetAllDoorStatusIntent tell me the open doors
GetAllDoorStatusIntent list me which doors are open
AuthenticatingIntent my password is {authenticate}
GetTemperatureIntent what is the temperature at home
GetTemperatureIntent tell me the temperature at home
GetTemperatureIntent what is the present temperature at home
- Next select Lambda ARN and then give the ARN Number of lambda function which is noted before.
- Then complete the publishing information, once setup is ready and working fine then submit for certification.,,,
1. Installations Required
- Raspbian Installation: Install raspbian jessie image. You can find installation instruction here. Connect your raspberry pi to ethernet. Find the ip address of the network. Connect to the terminal using ssh.
- Install Dependencies:
$ sudo apt-get install cython3 libudev-dev python3-sphinx python3-setuptools nodejs npm zip
$sudo pip3 install --upgrade paho-mqtt awscli homeassistant cython
- Install z wave component: In order to work with Z-Wave devices it is required to install this. Please refer this link for more information. Give following commands on shell.
$ git clone https://github.com/OpenZWave/python-openzwave.git
$ cd python-openzwave $ git checkout python3
$ PYTHON_EXEC=$(which python3) make build
$ sudo PYTHON_EXEC=$(which python3) make install.
2. Z-Wave devices Used
- Aeotec USB stick (acts as Z wave Controller)
- Z wave Devices
- 4 in 1 Philio multi sensor
- Fibaro door sensor
- Wall Plug
3. Pairing z wave devices to z wave controller (USB stick)
- Z-Wave controller should be set to inclusion mode by pressing the button on USB stick.
- Press the Z-Wave button on the Z-Wave device to pair it.
- The controller confirms the pairing success by blinking the led 3 times. The same need to be done for all the devices.
Note: Refer the manual for pairing the devices if you are having any trouble.Each device has its own mode of setup.
4. Starting Home Assistant:
- Now you are good to connect the USB stick to Raspberry Pi. And now start home assistant by giving the shell command.
$ hass
- By the above command you can view a default webpage.
Go to the developer tools -> states and collect the names of list of sensors which are paired which will be used later for customizing. (Names of sensors can be defaulted with the manufacturer name.)
Now your Home assistant and its z wave components are good to go.
5. Establishing communication between Pi and Lambda using AWS IOT
Download the source from repo:
$git clone https://github.com/cvsandeep/MyHome
Customizing home assistant:
- You can customize home assistant so that it will be user friendly and can add or remove desired elements.
- Edit your sensors.yaml and replace sensor names with sensor names noted in previous step.
$vi MyHome/HomeAssistant/sensors.yaml
E.g.: Binary_sensor.__sensor_2 => Binary_sensor.__sensor_9
- Make sure you are not changing friendly name. As those are used in building API.
- Modifying pi service: The collected certificates from IOT should be placed in “MyHome/AlexaApp/src/awsCerts”
- Things to be changed in PI service:
$vi MyHome/PiService/MyHomeService.py
host = "xxxxxxxx.iot.us-east-1.amazonaws.com" (Collect the thing host name)
returntopic = "$aws/things/cvshome/shadow/return" (make your own topic)
sendtopic = "$aws/things/cvshome/shadow/send" (make your own topic)
Now you are done with raspberry pi setup.You can start Pi Service Using
$cd MyHome/PiService
$(which python3) MyHomeService.py
Generating zip for lambda function
- Things to be updated in lambda source
$vi MyHome/AlexaApp/src/index.js
config.host = "xxxxxxxxxx.iot.us-east-1.amazonaws.com";
config.returntopic = "$aws/things/cvshome/shadow/return";
config.sendtopic = "$aws/things/cvshome/shadow/send";
config.app_id = "amzn1.echo-sdk-ams.app.xxxxxxx-YOUR-APP-ID-xxxxxx"
$vi MyHome/AlexaApp/src/index.js
"name": "MyHome",(Replace with Lambda function name)
$vi MyHome/AlexaApp/src/upload.sh
ROLE="arn:aws:iam::xxxxxxxxx:role/lambda_basic_execution"
(Replace with role ARN which will be available in this link )
FUNCTION="MyHome"(Replace with Lambda function name)
- Install sdk dependencies
$cd MyHome/AlexaApp/src
$npm install aws-iot-device-sdk
- Configure AWS command line
Create a user in IAM Role and generate Access and secret key to configure AWS
$ aws configure
AWS Access Key ID [None]: xxxxxxxxxxxxxxxxx
AWS Secret Access Key [None]: xxxxxxxxxxxxxx
Default region name [None]: us-east-1
Default output format [None]:
- Now setup is done we need to start Home Assistant and Pi service
$hass --config MyHome/HomeAssistant
$python3 MyHome/PiService/MyHomeService.py
To make it auto start you can make it as system service or setup a cronjob to start at reboot.
Now your Raspberry Pi is live with the help of AWS IOT. Now we are good to communicate with the Z-Wave device and security system with Alexa using Lambda.
Comments