Simple Garage Door Hack V3 - Using a Telegram Bot

by Pilgrim in Circuits > Arduino

1508 Views, 1 Favorites, 0 Comments

Simple Garage Door Hack V3 - Using a Telegram Bot

Telegram.png
GarageOpener.jpg

This is a high-level discussion around my latest iteration of my Garage Door Hack. To see the components that I used, please refer to Simple Garage Door Hack.

My biggest issue with my previous iterations was giving my family or guests easy but secure access to my web portal that would then allow them to open the garage door at will.

A couple of days ago I came across Telegram Group: Control ESP32/ESP8266 Outputs (Arduino IDE); another excellent Random Nerd tutorial. Using this I modified my code (see attached) so that I could use a bot, with a Telegram channel, to control devices in my house. No all I need to do is to add users to this group in order for them to open or close the garage door. This is done by them typing the following instruction in the channel "/garage". If I no longer want someone to have access, I simply remove them from the channel.

The only bit I battled with in the above tutorial was getting the channel ID. I solved this by watching https://www.youtube.com/watch?v=Mjx4OruxTwM.

The only downside of this approach is that the entire process of controlling the door is bit slower i.e. there is no button and instead one needs to type in a command. Also once the command is issued, there is a second or two delay before it is executed on the controller. In my opinion, the ease with which I can manage access and with which my users can use the channel far outweighs these slight delays/inconveniences.

Just some final comments:

  • This works on the ESP-01 so if I was building it again, I would use something like this.
  • As this channel is only meant for use by a bot, users need to mute it so that they are not notified every time someone opens the garage door or accesses some other device.
  • Many other ESP-01 control devices could be controlled using the same bot, making it a great hub for controlling other devices in your home (as well as getting feedback from them).
  • The channel provides an audit trail of when any devices were used and by whom.

Finally in order to be able to easily update the firmware in the future (without needing to physically access the controller), I added OTA (over the air) update functionality. Once again I followed a Random Nerd Tutorial: https://randomnerdtutorials.com/esp32-ota-over-th... The only note here is that I put the AsyncElegantOTA.h file in the project folder so that I could set the password on the upload page for just this project (if I edited it in the libraries folder it would the same for all future projects). This login credentials were set on line 35 of this file. As the login session appears to be remembered by the browser for a while, should you need to access the update page from a shared computer, I would suggest that you only access it via a private or incognito page.

Further considerations

Without a sensor on the door there is no way to know if the door is not closed (or not closed properly). It would be good to extract location or IP details from the requester so that requests can be geofenced. In this way you could set things up so that the request would only be processed should the request be on site. This would be good for Air B&B setups.

It would be good to be able to implement some sort of geofencing so that for some users, the command can only be executed when at the garage.

Latest and Last Developments

As I now have a smart lock that easily allows me to add or removed access for visitors and have now moved my garage door onto my Home Assistant platform using ESPHome (as this does not support the ESP-01, I have stayed with my current hardware although if I were to build it again, I would use the Wemos D1 mini).

Below is the code that I used in the ESPHome configuration:

esphome:
  name: garage-door

esp8266:
  board: nodemcuv2

# Enable logging
logger:

# Enable Home Assistant API
api:

ota:
  password: !secret ota_password-garage_door

wifi:
  ssid: !secret wifi_ssid
  password: !secret wifi_password

  # Enable fallback hotspot (captive portal) in case wifi connection fails
  ap:
    ssid: "Garage-Door Fallback Hotspot"
    password: !secret fallback_password-garage_door

captive_portal:

switch:
      - platform: gpio
        name: "Garage Door"
        id: relay
        pin: 5
        inverted: true
        icon: "mdi:garage"
        on_turn_on:
        - delay: 150ms
        - switch.turn_off: relay