In today's connected world, physical security doesn't have to be static. One simple, affordable enhancement to your property is receiving a message on your phone the moment someone opens a door or gate. This project demonstrates how to send smart alerts via Telegram when a door opens—using a basic sensor and microcontroller.
We'll also explore how companies in the fencing industry can integrate these systems to offer smarter services.
Why Use Telegram for Smart Alerts?
Telegram bots provide an accessible, fast, and cost-effective method for real-time messaging. Compared to traditional SMS or expensive proprietary apps, Telegram offers:
- Free encrypted cloud messaging
- Easy bot creation
- Excellent microcontroller compatibility
- Support for multimedia, buttons, GPS, and more
Perfect for DIYers and professionals alike.
Integrating smart sensors into property access points adds security and modern appeal. For instance, Vinyl Fence Company Chicago might enhance vinyl gate installations with this system, offering customers a seamless way to monitor access in real-time.
Hardware You’ll Need
This setup uses common, affordable components:
- ESP32 (or Raspberry Pi)
- Magnetic reed switch (door sensor)
- Jumper wires
- Breadboard or connectors
- Wi-Fi network
- Telegram bot & chat ID
Setting Up Your Telegram Bot
- Search for
@BotFather
in Telegram. - Type
/newbot
and follow the prompts. - Save the API token it gives you.
- Start a chat with the bot.
- Use this URL to find your chat ID:
https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates
Replace <YOUR_TOKEN>
with your bot’s token. Look for "chat":{"id":123456789}
.
ESP32: MicroPython Code
This MicroPython code connects to Wi-Fi, reads a door sensor, and sends a Telegram message:
import network
import urequests
import machine
import time
ssid = 'YOUR_WIFI_SSID'
password = 'YOUR_WIFI_PASSWORD'
bot_token = 'YOUR_BOT_TOKEN'
chat_id = 'YOUR_CHAT_ID'
sensor_pin = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_UP)
def connect_wifi():
wlan = network.WLAN(network.STA_IF)
wlan.active(True)
wlan.connect(ssid, password)
while not wlan.isconnected():
time.sleep(1)
def send_telegram(msg):
url = f'https://api.telegram.org/bot{bot_token}/sendMessage'
urequests.post(url, json={'chat_id': chat_id, 'text': msg})
connect_wifi()
print("WiFi connected!")
state = 1
while True:
if sensor_pin.value() == 0 and state == 1:
send_telegram("🚪 Alert: Door opened!")
state = 0
elif sensor_pin.value() == 1 and state == 0:
state = 1
time.sleep(0.5)
This type of real-time notification is a strong value proposition for any fence company in Chicago looking to differentiate itself through technology.
Raspberry Pi: Python Script
Using a Raspberry Pi with the GPIO library is equally straightforward:
from gpiozero import Button
import requests
import time
TOKEN = 'YOUR_TELEGRAM_BOT_TOKEN'
CHAT_ID = 'YOUR_CHAT_ID'
URL = f'https://api.telegram.org/bot{TOKEN}/sendMessage'
def send_alert():
requests.post(URL, data={'chat_id': CHAT_ID, 'text': "🚪 Gate opened!"})
sensor = Button(17)
while True:
sensor.wait_for_press()
send_alert()
time.sleep(1)
Use this for metal gates, garage doors, or access points—anywhere you'd mount a magnetic switch.
Commercial clients or those upgrading their gated entries—such as those who choose Iron Fence Chicago for elegant and durable fencing—can benefit from these smart integrations, improving the functionality of already secure installations.
Send a Photo on Door Open
With an ESP32-CAM or camera module on Raspberry Pi, you can send a snapshot along with your alert.
import requests
def send_photo(photo_path):
url = f"https://api.telegram.org/bot{TOKEN}/sendPhoto"
files = {'photo': open(photo_path, 'rb')}
data = {'chat_id': CHAT_ID}
requests.post(url, files=files, data=data)
This gives users visual confirmation of who or what triggered the door alert.
More Ideas for Expansion
- Add a web dashboard to log access times
- Set different alerts for different zones or gates
- Combine with NFC or keypad access
- Integrate with smart locks or alarms
Smart alerts are more than a novelty—they are practical and can be used for home security, property management, or by security-conscious businesses.
Conclusion
We’ve shown how to build a Telegram-based smart door alert system using basic hardware and free tools. This solution is practical for homeowners and scalable for professional installations.
Fencing professionals—whether offering vinyl, wood, or iron options—can use this system to stay ahead of the curve, offering not just security barriers, but intelligent access monitoring systems.
From backyard gates to warehouse entrances, smart alerts bring peace of mind.
Let’s make fences smarter—one gate at a time.
Top comments (0)