Intro: ESP8266 Door/window Sensor With SMS Alarm
In this tutorial we will show how to build WiFi door/window sensor connected to EasyIoT Cloud and then configure SMS alarm to notify when door/window are opened.
Step 1: Create Security Token
Register to EasyIoT Cloud service. If you do not receive registration email check spam folder. If it's not there contact us and we will activate your account. We need just security token to connect to EasyIoT Cloud. Go to Configure->Tokens and press button Add token. Remember this token - you will need this token later in program. If you remove token from you account later module will stop sending values to EasyIoT Cloud. One token can be used with more than one device.
Step 2: ESP8266 Program
Program is written in Arduino ESP8266 IDE. See Arduino ESP8266 IDE tutorial how to connect ESP8266 module to computer to upload program. Program is available at our GitHub. You will also need EIoTCloudRestApi library V1.0. Instructions how to install EIoTCloud REST V1.0 are here.
In program set access point name and password and security token we generated before.
#define AP_USERNAME "xxx"
#define AP_PASSWORD "xxx"
#define TOKEN "xxx"
If you are change GPIO pin on ESP8266 then also change GPIO pin in program.
Step 3: Hardware
In our case we use NodeMcu ESP8266, but you can use any other ESP8266 with FDTI programmer. For power supply you can use 2 AA batteries or 3.3V regulator.
One wire of magnetic switch connect to GPIO5 and other to ground and that's it.
Step 4: Configure SMS Alarm
So far we created WiFi door/window sensor. Now we will configure EasyIoT Cloud to send SMS alarm if door/window is opened between 10 PM and 8 AM.
Steps are following:
- add additional parameter Settings.Smsalarm to door/window module to enable/disable SMS alarm sending
- add automation program to enable SMS alarm at 10 PM
- add automation program to disable SMS alarm at 8 AM
- add automation program to send SMS message if SMS alarm is enabled and door/window sensor detects open door/window
Step 5: Add Additional Parameter
First we go in Configure->Modules and select Door/Window module we previously added. Now press button Add Parameter and add new parameter. Name parameter Settings.Smsalarm and then press button Save parameter.
Step 6: Add Automation Program to Enable SMS Alarm
Go to Configuration->Automation and press button button Add automation program. Enable program, set program name to AlarmOn, Scheduling type time to 22:00. All times are in European CET (GMT + 1).
Next we select door/window module and parameter Settings.Smsalarm. Set value to 1 and press button Save. All settings are on picture below.
Step 7: Add Automation Program to Disable SMS Alarm
In next step we add automation new program to disable alarm. In Automation press button Add automation program, enable program, set name to AlarmOff, select Scheduling type, and set time 8:00 (European CET). Then select Door/window module and parameter Settings.Smsalarm. Set value to 1 and press Save button.
Step 8: Add Automation Program to Send SMS
In last step we will configure automation program to send SMS message if door/window is opened. Again add new automation program. Name it DoorSMS, enable program and select Condition program type. Under "If" select our door/window module and corresponding Sensor.Parameter1. Condition is set to "=". Next we will select Condition value and compare this value with our parameter which is set with Schedule program. Select our door/window module and parameter Settings.Smsalarm. As an action select Send SMS. Enter your international phone number and enter Message.
Parameter Settings.SmsAlarm is 1 between 10PM and 8AM CET. If door/window is opened Sensor.Parameter1 is equal 1. If booth conditions are meet SMS message is sent.
To send SMS messages you need SMS message credit. You can check SMS message credit under Configure->Account limits SMS in period (total / limit). You can buy SMS limit in Configure->Account administration->New order and order one of SMS packages. After you finish configuring Automation you should see three automation modules.