Project 3: entrance door

This article continues the short-stories on the home-automation. For my previous article, on the automation of my heat unit, click here.

main unit
The device box, all sensors inside: an 220-5v power supply, temperature, movement, light sensors, a single relay, all connected to the ESP8266 module.

For the door, I didn’t want to use some existing devices to lock/unlock via bluetooth or create an alternative for that. The idea that made me have this device was after we forgot to lock the door one evening 😀

Hardware

button inside door lock
The KEYES KY-004 button, inside the door lock.

As before, we have an ESP8266 as the main unit, along with light, temperature and movement sensors, and a relay – used to control a light in the entrance door hall.

One new hardware sensor used here was a button, placed inside the door lock mechanism, used to see if the door is locked or not. See below the hardware list:

  • just one relay, a single module, was needed here, to control the hall light;
  • motion, temperature and light sensors – same as in the other projects
  • the button, a KEYES KY-004, placed inside the lock mechanism.
  • a 220v – 5v power supply – in this case, it was an older phone charger 🙂
  • the main module, the ESP8266 – on which are connected all sensors, and transmits the data to the Raspberry Pi hub (more on that setup, on my previous article).
esp and the movement sensor
Testing the movement sensor.

Regarding hardware, I’ve faced a problem in this setup – seems like the motion sensor was interfering with the hardware setup, with the wifi from the ESP8266 module. So it was triggering false positive messages regarding the movement. The only difference between this and another hardware setup (the one from bathroom) was that the motion sensor wasn’t around the esp module. So, in the end, I figured out the difference and had to move the movement sensor out of the box 🙂

testing, testing: lock and arduino
Testing the lock button placement and functionality: in the left, the door lock and the esp module, set for tests; in the right, the Arduino Serial Monitor, with logs on the door lock/unlock (button pressed/unpressed).

Software

Some parts of the arduino app.

As in software, the code is in Arduino, basically used most of the code from the heat unit and bathroom&hall devices, with some differences, because of the different hardware sensors.

A quick walkthrough in the Arduino app, from the ESP8266: starts with the library includes (for http, library for temperature sensor, a “setup” library I’ve added for code that’s shared in all device apps), declaration on the used pins (from the ESP8266 – and each sensor), some intervals used to send data to the hub (send temperature every 5 minutes, light details every 5 seconds), a list on the MQTT channels used (to send data, via MQTT, to the hub).

door - arduino code
Arduino app – the loop() method

In the app setup (inits the application): input/output pin initialisation, setup the temperature sensor, subscribe to some MQTT channels (one for relay to turn on/off hall light).

For the application loop, in the loop() method: checks if wifi disconnected, if so, will reconnect, reads from the light, temperature, movement and the button sensors, and, if there’s the case, sends the data to the hub, using the MQTT protocol.

door - home assistant
Home Assistant tab, where door specific sensor details are displayed.

The next part of the software, besides the Arduino code, is in the Home Assistant setup. I’ve grouped all sensors and in a tab and added a few automations:

Telegram Bot: notification sent, every minute, if door is unlocked
Home Assistant automation – checks and sends a message to Telegram, each minute, if the door is unlocked.
  • automation to turn the door light on, when there’s not enough light and motion is detected;
  • one to turn the door light off when no motion is detected for a minute;
  • to turn the door light off when the door is locked – in the end, I’ve disabled this one, because: If I just entered home, and locked the door, this automation was turning the light off – needing me to wave to the motion sensor, in order to have light back on. So, without this automation, the door light will eventually turn off, if we leave the house, with the above automation;
  • in the end, a few notification-automations, that are sending messages to the Telegram Bot:
    • to notify when door motion is detected (in the end, I disabled it, it was annoying 😀
    • notify when the door gets locked/unlocked
    • an automation that checks every minute if the door is locked and sends a message on the telegram bot – this one is also annoying, but … in an useful way:
- action:
  - alias: Notify when door is unlocked
    data: {}
    data_template:
      message: DOOR IS UNLOCKED!
    service: notify.telegram
  alias: Notify when door is unlocked
  initial_state: true
  condition:
  - condition: state
    entity_id: binary_sensor.door_lock
    state: 'off'
 trigger:
 - platform: time_pattern
   minutes: /1
   seconds: 0 

In this automation, it uses a service (notify.telegram) to send a message (DOOR IS UNLOCKED!) when the the door lock button (binary_sensor.door_lock) is pressed (state off) for a minute (using a platform trigger – time_pattern). You can read more on Home Assistant automations here.

I think that covers the device I’ve added for the door entrance. Please let me know on what you think about it in the comments below 🙂

Next, an article about some IoT applied to my car 🙂 See you soon!

Leave a Reply

Your email address will not be published. Required fields are marked *