Smart automatic door with ESPHome

Tags: #<Tag:0x00007f738dba97a0>

Hello everyone! :wave:

One of the things I always wanted to add to Home Assistant was a door. Just how cool would it be to control a door through Home Assistant. I did some googling but there didn’t seem to be anything like this. So I did it myself :muscle:

The door automatically opens

and automatically closes

In short, this is a 5V motor with wheels being controlled by an L298N motor controller being controlled by an ESP8266 NodeMCU using ESPHome. It is almost the same thing as @DrZzs automatic shades, but instead the motor has wheels and is attached to a door. A Xiaomi contact sensor on the door and a button I’ve attached to the wall acts as stop points for the motor. It works quite well but I needed to add some weight ( I added a rock ) to the motor since our carpet is a bit uneven.


Here is my ESPHome code


# ESP8266 NodeMCU
esphome:
  name: smart_door
  platform: ESP8266
  board: nodemcuv2

# Wi-Fi config
wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password
  ap:
    ssid: "Smart Door"
    password: !secret ap_passowrd

# Fallback portal    
captive_portal:

# Web server
web_server:
  port: 80

# Logging
logger:

# Home Assistant API
api:
  password: !secret api_passowrd

# OTA updates
ota:
  password: !secret ota_passowrd

# 5V motor
# These pins control the direction
output:
- platform: gpio
  pin: D1
  id: direction_pin2
- platform: gpio
  pin: D2
  id: direction_pin1 
# This pin controls the speed
- platform: esp8266_pwm
  pin: D3
  id: speed_pin
  frequency: 200hz
# A buzzer I added, potentially to alert people that the door is closing
- platform: esp8266_pwm
  pin: D5
  id: buzzer
  frequency: 800hz
switch:
  - platform: output
    output: 'direction_pin1'
    id: direction_switch1
    internal: true
  - platform: output
    output: 'direction_pin2'
    id: direction_switch2
    internal: true

# Buzzer
light:
  - platform: monochromatic
    output: buzzer
    name: "Smart Door Buzzer"

# Button on the wall to stop the motor
binary_sensor:
  - platform: gpio
    pin: D4
    id: door_stop_button
    internal: true
    filters:
      invert:
    on_press:
      then:
        - output.turn_off: speed_pin
        - switch.turn_off: direction_switch1
        - switch.turn_off: direction_switch2

# Xiaomi contact sensor
  - platform: homeassistant
    id: door_reed_sensor
    entity_id: binary_sensor.bedroom_door
    internal: true
    filters:
      invert:
    on_press:
      then:
        - delay: 2s
        - output.turn_off: speed_pin
        - switch.turn_off: direction_switch1
        - switch.turn_off: direction_switch2

# Create a cover in Home Assistant
cover:
  - platform: template
    name: "Smart Door"
    id: smart_door
    assumed_state: true
    device_class: door
    lambda: |-
        if (id(door_reed_sensor).state) {
          return cover::COVER_CLOSED;
        } else {
          return cover::COVER_OPEN;
        }
    open_action:
      - switch.turn_on: direction_switch1
      - switch.turn_off: direction_switch2
# I am lowing the speed here because I'm using a 5V motor with a 12V power supply
      - output.set_level:
          id: speed_pin
          level: 32%
      - delay: 99s
      - output.turn_off: speed_pin
      - switch.turn_off: direction_switch1
      - switch.turn_off: direction_switch2      
    close_action:
      - switch.turn_off: direction_switch1
      - switch.turn_on: direction_switch2
# I am lowing the speed here because I'm using a 5V motor with a 12V power supply
      - output.set_level:
          id: speed_pin
          level: 35%
      - delay: 99s
      - output.turn_off: speed_pin
      - switch.turn_off: direction_switch1
      - switch.turn_off: direction_switch2  
    stop_action:
      - output.turn_off: speed_pin
      - switch.turn_off: direction_switch1
      - switch.turn_off: direction_switch2

Hope you like it :smiley:

2 Likes

Sure do.

But I may be missing something - how do you unlatch the door?

Yes… that is a bit of a problem.

I’ve put a tape over the door bolt so the door doesn’t latch upon closing.

The motor doesn’t have enough power to close the door all the way so it latches (if you don’t use the tape). That means the system will continue to work unless you manually close the door fully which could be some sort of manually override :thought_balloon: :speech_balloon:

1 Like

There is a far amount of wheel spin there, your poor carpet !
:joy:

1 Like

I also kinda wanted something like this, not really sure what for :wink:
And my idea for the mechanism was to mount one of those powerful servos above the door, near the hinge side, with a 10cm long or so arm. The door would be attached at a point also around 10cm from the hinge, with a rubber band to the end of the servo arm.
That way the servo sets the target angle for the door but a person can override it, possibly without even noticing the door is “automated”. The servo can open and close the door when there are no obstacles or locks engaged.
Aliexpress has some very powerful digital servos for very cheap.

1 Like

Good job buddy.

In your videos there is no cable connected to the motor. How is it powered?

It’s wirelessly powered… :shushing_face:

No, in all seriousness the wires run under the door then beside the wall which eventually reaches the control box. It is tucked under so you can’t see it :wink:

1 Like