Diy home alarm system wifi

Building a DIY Home Alarm System with Arduino and WiFi

Learn how to build your own home alarm system using an Arduino, a motion sensor, and a WiFi module. This step-by-step guide will show you how to set up the hardware and write the code to send notifications to your phone or email when the alarm is triggered. Keep your home safe and secure with this simple DIY project!

Building a DIY Home Alarm System with Arduino and WiFi

Building a DIY Home Alarm System with Arduino and WiFi

Here’s a brief explanation of the code:

  • We first include the necessary libraries for Wi-Fi and HTTPClient.
  • We then define our Wi-Fi network name and password, as well as the URL of our server.
  • We define the pin to which our motion sensor is connected and set it to input mode.
  • We then set up the Wi-Fi connection and wait until we are connected to the network.
  • In the loop function, we check the state of the motion sensor. If it detects motion and the alarm is not already triggered, we send a notification to the server and set the alarmTriggered variable to true . If the motion sensor detects no motion and the alarm is triggered, we set alarmTriggered to false .
  • The sendNotification function takes a message parameter, constructs a URL with the message as a parameter, and sends an HTTP GET request to the server. The server can then process this request and send a notification to the appropriate parties.
#include #include #include const char* ssid = "your-ssid"; //replace with your Wi-Fi network name const char* password = "your-password"; //replace with your Wi-Fi network password const char* serverName = "http://yourserver.com/"; //replace with your server URL const int motionSensorPin = D1; //motion sensor connected to pin D1 bool alarmTriggered = false; void setup() < Serial.begin(115200); pinMode(motionSensorPin, INPUT); WiFi.begin(ssid, password); while (WiFi.status() != WL_CONNECTED) < delay(1000); Serial.println("Connecting to WiFi. "); >Serial.println("Connected to WiFi!"); > void loop() < if (digitalRead(motionSensorPin) == HIGH && !alarmTriggered) < Serial.println("Motion detected! Alarm triggered!"); sendNotification("Motion detected in your home!"); alarmTriggered = true; >else if (digitalRead(motionSensorPin) == LOW && alarmTriggered) < Serial.println("Motion stopped. Alarm deactivated."); alarmTriggered = false; >delay(100); > void sendNotification(String message) < WiFiClient client; HTTPClient http; String url = serverName + "?message=" + message; Serial.println(url); http.begin(client, url); int httpCode = http.GET(); if (httpCode >0) < String payload = http.getString(); Serial.println(payload); >else < Serial.println("Error on HTTP request"); >http.end(); > 

Note that this is just a basic example code and you may need to modify it to fit your specific use case. Also, make sure to properly secure your Wi-Fi network and server to prevent unauthorized access.

Читайте также:  Вай фай зона знак

Our website is for sale! The domain and website has been running for more than 3 years, but it’s time to part with it. There is no price, so I consider any offer. Contact us if you are interested in buying in the feedback form, we will discuss options, price and details for transferring the site. (script, database and everything else for the site to work).

Widget code for your site.

You can embed the widget on your site by placing the code anywhere on the page. (The widget is still being worked on!)

Источник

How to Create a DIY alarm system with Home Assistant

Are you tired of paying monthly fees for an antiquated alarm system, in this blog post I’m going to show you how you can build your custom made alarm system with a piece of software called home assistant.

DIY alarm system will feature a tablet as a home alarm panel, a Sonos speaker as a siren and a mobile phone notification, the brains of the system is home assistant, a free open source software can can be installed on a computer that is always on or on a dedicated micro computer such as a raspberry pi.

Home Security Alarm System Course!

home security course

If you are just getting started with home assistant I suggest you enroll in my Free Home Assistant Course !

If you want to follow my home security system course then click here

List of Products used in this project:

Check latest prices on Amazon

Philips Hue Motion Sensor: US or UK

Home Assistant

To Install home assistant you can reference this guide: here

Installation Steps

First thing to do is to enable the file editor add-one. This will give us easy access to the configuration files.

Alarm Panel

The alarm panel needs a name, I’m calling it home_alarm, this is an optional configuration. I’m enabling a code to use to disarm the alarm. This code is stored in a secret file, which will enable you to share you configuration file. The arming time is set at 45 seconds which is the time that it takes from when the alarm is armed. This will give you time to leave the property after you armed the alarm. The delay time is the grace period between when the alarm is triggered and the alarm is sounded. Configured at 60 seconds, feel free to change these values as you wish.

Читайте также:  Расшифровка кода от wifi

I’m adding in ios: to enable notification on IOS devices.

The automation split file of code is there to help us keep the code organised neatly in folders.

Add the following lines of code in the configuration.yaml file and save and restart hass.

automation split: !include_dir_list ./automations/ alarm_control_panel: - platform: manual name: home_alarm code: !secret alarm_code arming_time: 45 delay_time: 60 ios:

Now add your alarm code in the secrets.yaml file

In my example I’m using 1111

Sensors

Now this section is open and flexible, in the video I use a Philips Hue bridge with some motion sensors paired, I also have some Aqara sensors and some contact sensor. You can use any type of sensor to detect motion.

The list of compatible sensors you will find them here

Automation to Trigger Alarm

Now in the file editor create the following folders:

automations and inside create an alarm folder.

Now we need to create two automation files, the first file will change the state of the alarm panel to “triggered”.

The second automation will trigger a series of actions based on the fact that the alarm panel is triggered.

Create a new file and call it sound_alarm.yaml within the alarm folder you just created.

Now add this code into the file and save and reload automations:

Replace the binary_sensor with your own sensor, in my example I have three, but you can have more or less.

 alias: 'Trigger alarm while armed away' trigger: - platform: state entity_id: binary_sensor.hallway_sensor_motion to: 'on' - platform: state entity_id: binary_sensor.landing_sensor_motion to: 'on' - platform: state entity_id: binary_sensor.landing_sensor_2_motion to: 'on' condition: - condition: state entity_id: alarm_control_panel.home_alarm state: armed_away action: service: alarm_control_panel.alarm_trigger entity_id: alarm_control_panel.home_alarm

Now, create another file in the same folder called notification_alarm.yaml and add this code:

 alias: 'Send notification when alarm triggered' trigger: - platform: state entity_id: alarm_control_panel.home_alarm to: 'triggered' action: - service: notify.mobile_app_giordano_s_iphone_7 data: message: "ALARM! The alarm has been triggered" - service: media_player.play_media data: entity_id: media_player.kitchen media_content_id: 'http://192.168.1.153:8123/local/siren.mp3' media_content_type: 'music'

Save and reload automations.

Читайте также:  Кнопка через вай фай

For all of this to work you will need to install home assistant on your mobile device and find out the mobile app name in my case “mobile_app_giordano_s_iphone_7” change the code above with your value.

Add your sonos device to home assistant and keep track of its entity id. In my example it is “media_player.kitchen”.

In the media_content_id replace the IP address with the IP address of your own home assistant.
Then go back to the file editor and create a folder called www
Upload any mp3 that you want to use as a siren. I’m using siren.mp3. Now restart the whole home assistant server.

If you are using a google mini you need to change the media_content_type to ‘audio/mp3’.

DISCLAIMER: This blog post contain affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This allows us to continue to make posts like this.

Gio loves rabbits, smart home tech, WWII, travelling to Thailand & my favourite pizza is margherita with parma ham!

Recent Posts

Automations in home assistant by default run on a sequential basis, this means that each action will be run in a sequence one after the other waiting for the previous to be complete. Parallel.

Media players give great automation options with Home Assistant, the following ideas and example are to give you some inspiration for your own automations! Camera Stream alias: Play Stream.

About Me

Hey I’m Gio! I run a YouTube channel called Smart Home Makers and run a blog too.
I’m a Software Engineer with a passion for smart home tech.
I have been living in a smart home for about 5 years. At one point I had more than 20 Smart Apps on my phone, I since decided to control my smart home with Home Assistant and help people learn this powerful platform.
When I was getting started with Home Assistant I struggled to get everything working, but now I feel the need to pass on this knowledge and get more and more people using Home Assistant as their home automation platform.
I recently decided to create a video course series to help more people out in a more structured way!

This site, Leonardo Smart Home Makers Ltd. is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. We are compensated for referring traffic and business to Amazon and other companies linked to on this site.

Источник

Оцените статью
Adblock
detector