In order to monitor my doorbell – an old mechanical one that is loud but only hearable in one room – I needed a solution. I wanted to use the least amount of third party code. Secondly, because passwords are involved and privacy is important to me, I needed a solution to hook into an existing system that does not need to have my data stored in an IFTTT like website. But the setup and maintenance effort should be minimal. I wanted to have a local, anonymized solution. It also had to be non intrusive as I did not want to open the doorbell or hook into it physically.
This contraption is positioned close to a doorbell and will send a Telegram message once the doorbell rings.
The device is an external addition thus does not interfere with the doorbell circuit making this an easy add on for any situation where the doorbell hardware must not be altered. It is also a good beginners Arduino electronics project as the device is encapsulated in a box that only works with low voltages. Being battery powered it can be activated on demand. To make the most out of the 1400 mAh battery the device goes into deep sleep after one hour and can be easily reactivated via the push button.
- D1 mini NodeMcu
- Battery shield
- Lithium polymer battery
- Sound sensor
- Rocker switch
- Push button
- USB panel mount cable
- Junction box
Have a look at the wiring diagram first.
- Strategically mount the
rocker switch
and thepush button
in thejunction box
. Use a cutter to cut openings in the box and pressfit both devices. - Strategically route the
USB panel mount cable
to the surface of thejunction box
(used to charge the system without opening the box). The linked model is secured with screws. - Strategically mount the
battery
in thejunction box
(VHB tape works well). - Desolder the female JST connector on the
battery shield
and solder extension cables between the female JST connector leads and thebattery shield
terminals. This is a good point to check polarity of the JST connectors and the battery: some batteries have the JST connector soldered on the other way! - Wire the
rocker switch
in between the positive lead going from the female JST connector to the positive terminal of the battery shield (ensure enough wire for routing). - Wire the
push button
in betweenRST
andGND
of the microcontroller (ensure enough wire for routing). - Strategically wire the
sound sensor
toA0
,3V3
andGND
of the microcontroller (ensure enough wire for routing). - Drill small holes to the back of the
junction box
and hot glue thesound sensor
to that position with the microphone facing the backside of the box. - Mount the
battery shield
on theD1 mini NodeMcu
. - Connect the
USB panel mount cable
to thebattery shield
. - Connect the battery to the female JST connector.
- Tidy up all cables and ensure correct spacing when closing the box.
You're done setting up the hardware.
The setup follows these instructions. For simplicity I tried to compress it even more in the following step by step list:
-
Create a Telegram bot using @botfather (FAQ).
- Username:
@<NAME>Bot
- Disable
Allow Groups?
- Turn on
Group Privacy
The bot
Token
will be available once the bot is created. Write it down, you'll need it in a later step. - Username:
-
Create a private group.
- Group name:
MyPrivateGroup
- Group Type:
private
Warning: Do not edit special permissions for users as this will convert the group into a supergroup which does not work with this code.
- Group name:
-
Temporarily enable
Allow Groups?
on the bot. -
Add the bot to the group.
-
Immediately deactivate
Allow Groups?
on the bot after adding it to the group. -
Post a test message into the group via the app or the browser (required to get the next step running). Start message with
/
in order for the bot to be able to read it (Group Privacy
is turned on by default). -
Retrieve group
chat_id
by visitinghttps://api.telegram.org/bot<BOT_TOKEN>/getUpdates
in the browser. -
Let the bot send a test message via visiting
https://api.telegram.org/bot<BOT_TOKEN>/sendMessage?chat_id=<GROUP_CHAT_ID>&text=Test
in the browser.
The message should appear in the group chat.
You're done setting up the Telegram infrastructure.
- Either rename passwords_template.h to
passwords.h
or copy its content to a new file namedpasswords.h
in the same folder. - Enter your WiFi and Telegram credentials in
password.h
.
The system can be fine tuned according to your needs by adjusting the properties in settings.h.
If true
prints verbose debug statements via serial connection. Useful for finding issues with e.g. the WiFi connection.
Default false
.
If true
sends a Telegram message after RUNTIME_BEFORE_UPCOMING_DEEP_SLEEP_NOTIFICATION_IN_MILLISECONDS
announcing the upcoming deep sleep in RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
.
Default true
.
If true
sends a Telegram message after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
announcing the immediate deep sleep.
Default true
.
If true
sends the PROJECT_STARTUP_MESSAGE
silently. Users will receive a notification with no sound.
Default true
.
If true
sends the DOORBELL_RINGING_MESSAGE
silently. Users will receive a notification with no sound.
Default false
.
If true
sends the UPCOMING_DEEP_SLEEP_MESSAGE
silently. Users will receive a notification with no sound.
Default false
.
If true
sends the DEEP_SLEEP_MESSAGE
silently. Users will receive a notification with no sound.
Default false
.
The system is going to announce deep sleep after this amount of time. It will remain functional until RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
is reached. Must be smaller than RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
.
Default 55 minutes
.
The system will go to deep sleep after this time.
Default 1 hour
.
The system will not send a Telegram message but raise the notification importance level during this lock period. This is so that we stay within the api limits.
Default 1 minute
.
Number of attempts to connect to the Telegram server.
Default 3
.
50 ms being 20 Hz.
Default 50
.
If this value is exceeded we assume that the doorbell rings. You might want to test different settings while performing typical sounds in the area you setup this device such as talking loudly or letting a phone ring.
Default 973
.
The message being sent via the Telegram bot when the project is ready.
Default 👂
.
The message being sent via the Telegram bot when the doorbell rings.
Default Knock Knock
.
The message being sent via the Telegram bot notifying that deep sleep starts in RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
- RUNTIME_BEFORE_UPCOMING_DEEP_SLEEP_NOTIFICATION_IN_MILLISECONDS
.
Default 😴
.
The message being sent via the Telegram bot when the project is going into deep sleep after RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
.
Default 💤
.
- Download and install the latest release of Arduino IDE.
- Download the latest release of knock-knock-arduino-doorbell-telegram-notifier.
- Open
Arduino/knock_knock/knock_knock.ino
. - In the Tools menu select the board
LOLIN(WEMOS) D1 R2 & mini
for flashing. There is a tutorial on how to install ESP8266 boards in Arduino IDE. - Set
Upload Speed: 921600
andCPU Frequency: 80 MHz
. - Connect to the board via USB (not to the battery shield USB that is routed to the outside of the enclosure!).
- Choose the correct USB
Port
for uploading. - Hit
Upload
in the Arduino IDE and wait for the process to successfully finish. - Unplug the USB cable and close the box making sure that all cables are spaced correctly.
The bot (@<NAME>Bot
) can be found by any Telegram user. It exposes no methods to the public so there is no interaction with other users. By using the bot Token
we can send messages to certain channels in the name of the bot. Again, this data will never be shared with other users.
To anonymize the bot output even further – and increase the cuteness factor – we use emojis.
👂 emoji.
Knock Knock
appended by 0-3 exclamation marks (aka notification importance level).
Knock Knock
– Doorbell rang onceKnock Knock!
– Doorbell rang once, subsequently twice within the last minuteKnock Knock!!
– Doorbell rang once, subsequently three times within the last minuteKnock Knock!!!
– Doorbell rang once, subsequently four times within the last minute
😴 emoji.
💤 emoji.
- Activate rocker switch.
- System boots and broadcasts readiness via Telegram.
- Code runs.
- It reports a ringing doorbell via Telegram.
- It reports the upcoming shutdown after
RUNTIME_BEFORE_UPCOMING_DEEP_SLEEP_NOTIFICATION_IN_MILLISECONDS
of runtime via Telegram. - It reports going to deep sleep after
RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
of runtime via Telegram.- It goes into deep sleep after
RUNTIME_BEFORE_DEEP_SLEEP_IN_MILLISECONDS
of runtime.
- It goes into deep sleep after
- It can be woken up from deep sleep via the push button (code starts again at #2).
- The power is cut via deactivation of the rocker switch.
Thanks Alex Sarafian for providing great instructions on how to Creating a private Telegram chatbot .
Thanks zenmanenergy for the URL encoding sketch.
And also a great thanks to all people that posted and discussed on various webpages about coding, esp8266 and so on. Wouldn't have made it without you.