Smart automatic door with ESPHome

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:

9 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:

2 Likes

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.

3 Likes

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, the wires run under the door then beside the wall which eventually reaches the control box. It is tucked under the carpet so you can’t see it.

1 Like

Cool project! Do you have a diagram of your electronics/connections?

Unfortunately not. However, as mentioned above, it is essentially the same as @DrZzs automatic shades. He does include a diagram in his video.

Exactly what I would like to do too. so I can open the door between the garage and the living room with the voice from the coach when my cat wants to enter and scratches the other side of the door. Which is all the time :wink:
I don’t want to install a cat flap there as it’s a door inside.
Basically a version of this : https://www.amazon.de/-/en/PortaMatic-4511903-Mounting-Material-Consumption/dp/B0191G0BYI/ref=sr_1_6?crid=2P1251R03ZTYA&keywords=automatischer%2Btüröffner&qid=1652422163&sprefix=automatic%2Bdoor%2Bopen%2Caps%2C167&sr=8-6&th=1
But with esphome.

Did you ever find a powerful enough cheap servo for that ?

I suspect that a device called a linear actuator is what you want.

Thanks @nickrout.
Linear actuator is indeed the first thing I evaluated for this solution, but an actuator kind of require a perpendicular wall next to the door, need one quite a powerful which is rather expensive and the door might not be manually opened anymore easily.
Which is probably why the commercial solution that I saw ( Hörmann, opensesamedoor, olide, …) seem to use a rotation mechanism that can push/pull the door from the top of the frame. Solutions look to be powered by a clutch motor, windshield type of motor or even nema 23 step motor.

Here is what I found so far:
Based on a recycled windshield motor:

Based on Nema 23 but is a theoretical paper:

This commercial solution looks to be based on a clutch motor:

Still wondering what cheap motor alternative to take. The automation side of it should be fairly easy with an ESP32 and ESPHome. Case could be 3D printed. Then for the arm not sure what is most appropriate to still look good. Ideally could go with something cheap like that:
Burg-Wächter TS 501 SB Door Closer : Amazon.de: DIY & Tools
empty what is inside and try to fit a motor and the electronics.
Anyone has ever done that ?

Hi, thanks for sharing this.
Exactly what I needed

My thought was to have a vacuum in a closet out of the way. Door opens to…UNLEASH THE VACUUM! Then it docks when finished and closes the door behind itself.