This tutorial shows how to control your ESP32 or ESP8266 boards through a Telegram group. Using a Telegram group to control your boards may be useful if you want to have several people interacting with a bot on the same chat and you want all those people to get notifications from the bot.
We have other tutorials about Telegram that we recommend reading:
- Control ESP32/ESP8266 Outputs using Telegram (Arduino IDE)
- Request ESP32/ESP8266 Sensor Readings using Telegram (Arduino IDE)
- ESP32 Motion Detection with Notifications using Telegram (Arduino IDE)
- ESP8266 NodeMCU Motion Detection with Notifications (Arduino IDE)
Project Overview
- In this tutorial you’ll create a telegram bot to interact with the ESP32 or ESP8266 boards;
- You’ll create a group where you can add several people you want to have control and receive notifications from the bot;
- The bot will be added to the group so that the members can interact with it;
- As an example, we’ll show you how to send commands to control outputs and how to send responses from the bot to the group.
Introducing Telegram
Telegram Messenger is a cloud-based instant messaging and voice over IP service. You can easily install it in your smartphone (Android and iPhone) or computer (PC, Mac and Linux). It is free and without any ads. Telegram allows you to create bots that you can interact with.
“Bots are third-party applications that run inside Telegram. Users can interact with bots by sending them messages, commands and inline requests. You control your bots using HTTPS requests to Telegram Bot API“.
The ESP32/ESP8266 will interact with the Telegram bot to receive and handle the messages, and send responses to the Telegram group.
Install Telegram
Go to Google Play or App Store, download and install Telegram.
Creating a Telegram Bot
The following steps are easier to follow on your computer. Open a browser, go to the Telegram Web App and login into your account.
If you’ve followed previous projects and you already have a telegram bot, you can skip this section.
On the top left corner, search for âbotfatherâ and click the BotFather as shown below.
A new window should open and youâll be prompted to click the start button. Type /newbot and follow the instructions to create your bot. Give it a name and username.
If your bot is successfully created, youâll receive a message with a link to access the bot and the bot token. Save the bot token because youâll need it so that the ESP32/ESP8266 can interact with the bot.
Creating a Telegram Group
The next step is creating the Telegram group. On the top left corner, click on New group.
Add members to your group and give it a name.
Add the Bot to the Group
Once the group is created, click on the group name to add your bot.
Search for your bot name and add it to the group.
Get the Group ID
To interact with the Telegram group, the ESP32 needs to know the telegram group ID. In you Telegram account, open your group. The group ID should be on the URL as shown below.
Save the group ID because you’ll need it later.
Preparing Arduino IDE
Weâll program the ESP32 and ESP8266 boards using Arduino IDE, so make sure you have them installed in your Arduino IDE.
- Installing the ESP32 Board in Arduino IDE (Windows, Mac OS X, Linux)
- Installing ESP8266 Board in Arduino IDE (Windows, Mac OS X, Linux)
Universal Telegram Bot Library
To interact with the Telegram bot, we’ll use the Universal Telegram Bot Library created by Brian Lough that provides an easy interface for the Telegram Bot API.
Follow the next steps to install the latest release of the library.
- Click here to download the Universal Arduino Telegram Bot library.
- Go to Sketch > Include Library > Add.ZIP Library...
- Add the library you’ve just downloaded.
And that’s it. The library is installed.
Important: don’t install the library through the Arduino Library Manager because it might install a deprecated version.
For all the details about the library, take a look at the Universal Arduino Telegram Bot Library GitHub page.
ArduinoJson Library
You also have to install the ArduinoJson library. Follow the next steps to install the library.
- Go to Skech > Include Library > Manage Libraries.
- Search for “ArduinoJson”.
- Install the library.
We’re using ArduinoJson library version 6.15.2.
Parts Required
For this example you just need one ESP32 or an ESP8266 board.
- ESP32 board (read Best ESP32 dev boards)
- Alternative â ESP8266 board (read Best ESP8266 dev boards)
You can use the preceding links or go directly to MakerAdvisor.com/tools to find all the parts for your projects at the best price!
Control ESP32/ESP8266 using Telegram Group – Sketch
The following code allows you to control your ESP32 or ESP8266 NodeMCU GPIOs by sending messages to a group where your Telegram Bot is a member.
To make this sketch work for you, you need to insert your network credentials (SSID and password), the Telegram Bot Token and your Telegram Group ID.
/*
Rui Santos
Complete project details at https://RandomNerdTutorials.com/telegram-group-esp32-esp8266/
Project created using Brian Lough's Universal Telegram Bot Library: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
*/
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h> // Universal Telegram Bot Library written by Brian Lough: https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot
#include <ArduinoJson.h>
// Replace with your network credentials
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
// Initialize Telegram BOT
#define BOTtoken "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
// Use @myidbot to find out the chat ID of an individual or a group
// Also note that you need to click "start" on a bot before it can
// message you
#define CHAT_ID "-XXXXXXXXXX"
#ifdef ESP8266
X509List cert(TELEGRAM_CERTIFICATE_ROOT);
#endif
WiFiClientSecure client;
UniversalTelegramBot bot(BOTtoken, client);
// Checks for new messages every 1 second.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;
const int ledPin = 2;
bool ledState = LOW;
// Handle what happens when you receive new messages
void handleNewMessages(int numNewMessages) {
Serial.println("handleNewMessages");
Serial.println(String(numNewMessages));
for (int i=0; i<numNewMessages; i++) {
// Chat id of the requester
String chat_id = String(bot.messages[i].chat_id);
if (chat_id != CHAT_ID){
bot.sendMessage(chat_id, "Unauthorized user", "");
continue;
}
// Print the received message
String text = bot.messages[i].text;
Serial.println(text);
String from_name = bot.messages[i].from_name;
if (text == "/led_on") {
bot.sendMessage(chat_id, "LED state set to ON", "");
ledState = HIGH;
digitalWrite(ledPin, ledState);
}
if (text == "/led_off") {
bot.sendMessage(chat_id, "LED state set to OFF", "");
ledState = LOW;
digitalWrite(ledPin, ledState);
}
if (text == "/state") {
if (digitalRead(ledPin)){
bot.sendMessage(chat_id, "LED is ON", "");
}
else{
bot.sendMessage(chat_id, "LED is OFF", "");
}
}
}
}
void setup() {
Serial.begin(115200);
#ifdef ESP8266
configTime(0, 0, "pool.ntp.org"); // get UTC time via NTP
client.setTrustAnchors(&cert); // Add root certificate for api.telegram.org
#endif
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
// Connect to Wi-Fi
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
#ifdef ESP32
client.setCACert(TELEGRAM_CERTIFICATE_ROOT); // Add root certificate for api.telegram.org
#endif
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
// Print ESP32 Local IP Address
Serial.println(WiFi.localIP());
bot.sendMessage(CHAT_ID, "Bot Started", "");
}
void loop() {
if (millis() > lastTimeBotRan + botRequestDelay) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while(numNewMessages) {
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
lastTimeBotRan = millis();
}
}
The code is compatible with ESP32 and ESP8266 NodeMCU boards (itâs based on the Universal Arduino Telegram Bot library example). The code will load the right libraries accordingly to the selected board.
How the Code Works
Start by importing the required libraries.
#ifdef ESP32
#include <WiFi.h>
#else
#include <ESP8266WiFi.h>
#endif
#include <WiFiClientSecure.h>
#include <UniversalTelegramBot.h>
#include <ArduinoJson.h>
Network Credentials
Insert your network credentials in the following variables.
const char* ssid = "REPLACE_WITH_YOUR_SSID";
const char* password = "REPLACE_WITH_YOUR_PASSWORD";
Telegram Bot Token
Insert your Telegram Bot token you’ve got from Botfather on the BOTtoken variable.
#define BOTtoken "XXXXXXXXXX:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" // your Bot Token (Get from Botfather)
Telegram Group ID
Insert your Telegram group ID. It should start with a “-” signal.
#define CHAT_ID "-XXXXXXXXXX"
Create a new WiFi client with WiFiClientSecure.
WiFiClientSecure client;
Create a bot with the token and client defined earlier.
UniversalTelegramBot bot(BOTtoken, client);
The botRequestDelay and lastTimeBotRan are used to check for new Telegram messages every x number of seconds. In this case, the code will check for new messages every second (1000 milliseconds). You can change that delay time in the botRequestDelay variable.
int botRequestDelay = 1000;
unsigned long lastTimeBotRan;
Define Output
Set the GPIO you want to control. In our case, we’ll control GPIO 2 (built-in LED) and its state is LOW by default.
const int ledPin = 2;
bool ledState = LOW;
Note: if you’re using an ESP8266, the built-in LED works with inverted logic. So, you should send a LOW signal to turn the LED on and a HIGH signal to turn it off.
handleNewMessages()
The handleNewMessages() function handles what happens when new messages arrive.
void handleNewMessages(int numNewMessages) {
Serial.println("handleNewMessages");
Serial.println(String(numNewMessages));
It checks the available messages:
for (int i=0; i<numNewMessages; i++) {
Get the chat ID for that particular message and store it in the chat_id variable. The chat ID allows us to identify who sent the message.
String chat_id = String(bot.messages[i].chat_id);
If the chat_id is different from your chat group ID (CHAT_ID), it means that someone (that is not in the group) has sent a message to your bot. If that’s the case, ignore the message and wait for the next message.
if (chat_id != CHAT_ID) {
bot.sendMessage(chat_id, "Unauthorized user", "");
continue;
}
Otherwise, it means that the message was sent from someone in your group, so we’ll save it in the text variable and check its content.
String text = bot.messages[i].text;
Serial.println(text);
The from_name variable saves the name of the sender.
String from_name = bot.messages[i].from_name;
If it receives the /led_on message, turn the LED on and send a message confirming we’ve received the message. Also, update the ledState variable with the new state.
if (text == "/led_on") {
bot.sendMessage(chat_id, "LED state set to ON", "");
ledState = HIGH;
digitalWrite(ledPin, ledState);
}
Sending a message to the bot is very simply. You just need to use the sendMessage() method on the bot object and pass as arguments the recipient’s chat ID, the message, and the parse mode.
bool sendMessage(String chat_id, String text, String parse_mode = "")
Do something similar for the /led_off message.
if (text == "/led_off") {
bot.sendMessage(chat_id, "LED state set to OFF", "");
ledState = LOW;
digitalWrite(ledPin, ledState);
}
Note: if you’re using an ESP8266, the built-in LED works with inverted logic. So, you should send a LOW signal to turn the LED on and a HIGH signal to turn it off.
Finally, if the received message is /state, check the current GPIO state and send a message accordingly.
if (text == "/state") {
if (digitalRead(ledPin)){
bot.sendMessage(chat_id, "LED is ON", "");
}
else{
bot.sendMessage(chat_id, "LED is OFF", "");
}
}
setup()
In the setup(), initialize the Serial Monitor.
Serial.begin(115200);
If you’re using the ESP8266, you need to use the following line:
#ifdef ESP8266
client.setInsecure();
#endif
In the library examples for the ESP8266 they say: “This is the simplest way of getting this working. If you are passing sensitive information, or controlling something important, please either use certStore or at least client.setFingerPrint“.
Set the LED as an output and set it to LOW when the ESP first starts:
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, ledState);
Init Wi-Fi
Initialize Wi-Fi and connect the ESP to your local network with the SSID and password defined earlier.
WiFi.mode(WIFI_STA);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
loop()
In the loop(), check for new messages every second.
void loop() {
if (millis() > lastTimeBotRan + botRequestDelay) {
int numNewMessages = bot.getUpdates(bot.last_message_received + 1);
while(numNewMessages) {
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
lastTimeBotRan = millis();
}
}
When a new message arrives, call the handleNewMessages() function.
while(numNewMessages) {
Serial.println("got response");
handleNewMessages(numNewMessages);
numNewMessages = bot.getUpdates(bot.last_message_received + 1);
}
That’s pretty much how the code works.
Demonstration
Upload the code to your ESP32 or ESP8266 board. Don’t forget to go to Tools > Board and select the board you’re using. Go to Tools > Port and select the COM port your board is connected to.
After uploading the code, press the ESP32/ESP8266 on-board EN/RST button so that it starts running the code. Then, you can open the Serial Monitor to check what’s happening in the background.
Go to your Telegram account and open the group.
Send the following commands and see the bot responding:
- /led_on turns the LED on.
- /led_off turns the LED off.
- /state requests the current LED state.
The on-board LED should turn on and turn off accordingly (the ESP8266 on-board LED works in reverse, it’s off when you send /led_on and on when you send /led_off).
When you add your telegram bot to a group, everyone in the group can interact with the bot and receive messages from the bot. For example, in this case we can both (Sara and Rui) control the bot and see the commands that the other is sending. Additionally, in a project with notifications, we’d both be notified on the group.
You can add more people to the group, for example all family members.
On the Serial Monitor you should see that the ESP is receiving the messages.
Wrapping Up
In this tutorial you’ve learned how to get and send messages to the ESP32 or ESP8266 using a Telegram group. Using a Telegram group to control your ESP32 might be advantageous over a single chat, if you want to have several people able to control and monitor the same board.
We’ve shown you a simple example on how to control an output. The idea is to modify the project to add more commands to execute other tasks. For example, you can request sensor readings or send a telegram message when motion is detected.
The great thing about using Telegram to control your ESP boards, is that as long as you have an internet connection (and your boards too), you can control and monitor them from anywhere in the world.
We hope you’ve found this project interesting.
Learn more about the ESP32 and ESP8266 with our resources:
- Learn ESP32 with Arduino IDE (eBook + Video Course)
- Home Automation using ESP8266
- More ESP32 projects and tutorials…
- More ESP8266 projects and tutorials…
Thanks for reading.
Hello Rui, how are you? I really enjoyed this tutorial from you, congratulations. But I would like to check if there is a way to perform just one pulse, simulating a remote control.
For example I have a friend who owns a garage which he rents a box, sometimes someone forgets the control there he or the manager opens the gate via app with a pulse which activates the remote control through a transistor. Before I used Cayenne but it is discontinued by the app.
I don’t know if that would be possible. I used Amazon’s cloud but I have compatibility problems, because we found an App on Android but IOS is very complicated, this idea of ââTelegram would be a great idea, because in both operating systems we can use the same App.
Hugs,
Eliseu
Hi.
The easiest way is to set the GPIO to HIGH and then to LOW again. Add a delay between each command depending on the duration of the pulse.
For example:
digitalWrite(LED, HIGH);
delay(500);
digitalWrite(LED, LOW)
I hope this helps.
Regards,
Sara
Thanks Sara,
I’ll try it….tomorrow.
Now here it’s pillow timeđ!
Thank U very much.
P. S.
I made a telegram group of 6 ESP32-CAM with some relays and buzzers. I can interact them with single or multiple commands! (I’m so happy)
Congratulations!
That’s a great project!
Regards,
Sara
Hello Sara and Rui,
thanks for your great work: I made a Telegram group of ESP32-cam bot! They work perfectly!
I only want to ask You a little thing: I wanna attach 2 led at those (mine) ESP32-cam.
What pin can I use? I tried GPIO 1 e 3, or 16 e 2 but they don’t work.
Thanks Renzo (from farfar away Italy)
Hi.
If you’re not using SD card, you can try GPIO 13, 14 or 15.
For more information you can read this guide: https://randomnerdtutorials.com/esp32-cam-ai-thinker-pinout/
Regards,
Sara
Nice project – thank you but is there a way to allow a few chat id without using the group function so that response is directly to the person who asked and will not ping other members.eg joe and bob are valid users but dont want to be disturbed with lots of messages rudy needs to know the status every hour of the pump”led”.
Hi
You can add multiple personal IDs and check them individually.
For example:
#define CHAT_ID_1 “XXXXXXXXXX”
#define CHAT_ID_2 “XXXXXXXXXX”
Then, in the handleNewMessages() function check whether the message came from one of those users:
for (int i=0; i<numNewMessages; i++) {
// Chat id of the requester
String chat_id = String(bot.messages[i].chat_id);
if (chat_id != CHAT_ID_1 || chat_id != CHAT_ID_2){
bot.sendMessage(chat_id, “Unauthorized user”, “”);
continue;
}
…
I hope this helps.
Regards,
Sara
Hi Sara,
Thank you for this amazing project.
I think the code above should be like that “if (chat_id != CHAT_ID_1 && chat_id != CHAT_ID_2)” not if (chat_id != CHAT_ID_1 || chat_id != CHAT_ID_2)”
Hello my friend how i get ID it is only nĂșmber or names please explain it by example i have on contacts to Jorge How i do for have your ID
very thanks
Excellent and practical.
Perhaps more program lines should be added to be more specific when you do not want to share with the group each program that is executed (to add more features to the application).
When adding group members, the administrator should generate the corresponding permissions individually for each one.
I think the great solution would be for the administrator to turn esp32 into a webserver mode so that he can program the module’s exclusive use parameters on his screen and finally, since the group members are already programmed, they can no longer modify that data.
It would be a good extension of this benefit, right?
And the “icing on the cake” as we say at least in Argentina, would be to carry out this entire tutorial using the ESP32 SIM800L so that in case there is no Wi-Fi in place, you can communicate with Telegram through the SIM800.
If it is possible to do it, I think it would be very useful for all the followers of Rui and Sara.
Thank you very much
Hi Alejandro.
Yes, you can add other lines of code to check who sent the message and allow the user to execute a certain task or not.
Here, we’re just showing the simplest example so that our readers can easily modify it for their own projects.
As you mention, it can be also a good idea to establish an internet connection using a SIM800L module or any other data module so that you don’t need to connect the ESP to a router.
We have this tutorial about connecting the ESP32 to the internet using SIM800L: https://randomnerdtutorials.com/esp32-sim800l-publish-data-to-cloud/
Thanks for following our work.
Regards,
Sara
Yesterday I sent a comment about this tutorial, some suggestions of interest perhaps for the followers.
After a while where it said “in the process of moderation” or something like that, my submission disappeared.
This is the third time that has happened to me. I don’t know what mistake I’m making or is it because I sent it from Argentina, or are there character limitations or specific topics?
Should I write in “Contact” for certain topics?
Thanks for your attention.
Hi Alejandro.
Your previous comment was now approved.
We receive lots of comments everyday.
It is impossible for us to review, approve and answer all comments on the day they were published.
Sometimes, we can’t even keep up with all the comments we receive.
Thanks for your understanding.
Regards,
Sara
Hi Rui and Sara
I regret my anxiety to see that my posts were not together with others sent by their followers and I believed that I was sending incorrect information.
I have certainly always added more lines of code to your excellent tutorials.
I loved this Telegram project so much, that I did the tests for individual control, of several enabled users entering their IDBot and in a group, with selection of permissions from the administrator or owner.
I think it just lacks the addition of “automatic switching” between ESP32 wifi and the ESP32 / SIM800L module. in the absence of Wi-Fi connection with Telegram.
I have bought 2 of these devices just to do these tests.
I would only suggest if they could complete, in an additional or complementary tutorial, what is necessary to use the SIM800 mode with communication exclusively with Telegram bots for communication and reception of the information that is exchanged.
Once again I congratulate them for their work and how they have given us tools to their followers to continue learning topics with their very practical, clear and useful explanation.
Hi Alejandro.
I’m really glad that you liked this tutorial and found it useful.
Thanks for the suggestion of the SIM800L project. I’ll add it to my list of projects/tutorial ideas.
Then, let us know your results.
Regards,
Sara
Hi Rui,
I tried this group communication with ESP32. For the Android phones, it’s working perfectly, but for Apple phones it’s not working correctly. sometime only the first command works, after that no responses from the ESP32.
Kindly advise a solution.
Thanks,
How to fix this problem
Leaving…
Hard resetting via RTS pin…
After uploading code my Nord MCU resetting again and again
Please help
Same issue in every code
That’s not an error.
That’s the normal message after uploading the code.
You just need to press the board RST button to run the code.
Regards,
Sara
Hi Sara and Rui. Very usefull project, works fine, but…
Is possible to create 2 devices, and one device send commands to other?
For example one esp8266 device will be the remote control, and a second esp8266 will receive the commands and power on/off the led?
If possible, it will be very usefull to remotely open garage gates, power on or off devices, with a single click on an esp8266 button, thus eliminate the use the mobile phone, and quick execute tasks.
Thanks
Regards.
Hi Marcelo.
In that case, I think you need to create two bots.
One for each ESP board and add all boards to the same chat.
Then, each board should respond to different commands sent to the chat.
Regards,
Sara
Hi Sara, how are You?
Thanks for your reply.
I spent hours trying with two bots without success.
After reading some Telegram statements, I realized that is not possible, because Telegram donÂŽt permit a bot talk to other bot even in same group, only person to bot or bot to person talk is permited.
Thankyou, Happy new year!!!!
Thanks for letting me know.
Regards,
Sara
Have a happy new year.
HI @ll,
I made a TG Group with 10 devices ( each with a different name and icon).
I can control every device, I can see them INPUT and move them OUTPUTS.
I put inside a library can handle the hours of the sunrise/sunset, soo….some things can happend without my hands, only …. I can see all the things in my TG group with some messages.
Thank U Ruy & Sara
Renzo from farfar awayItaly
That’s great!
Regards,
Sara
Hello.
I tell you about my experience on the subject of Telegram.
I have developed using this platform and having started, thanks to the contribution of Rui and Sara, prototypes to control up to 4 relay outputs.
I used the “group” form, as explained by Rui, with its assigned token and its associated chat_id for this modality.
I have added 5 users and before each order of activation or deactivation of each output, the wifi module (ESP32), decodes the order and acts accordingly.
Both the order that is generated on a certain phone and the response to the process carried out in the wifi module, is received simultaneously by the members of the group as expected.
I have also done, using the IDBot of each of up to 5 phones as an identifier within a “private system (without using the” group “mode) and an esp32 with the same outputs as the previous case.
I have saved in the eeprom the information of each user who “connects” to the hardware control.
Once an activation or deactivation operation is detected in the esp32 from any of the telephones, a message is sent to each telephone indicating the action and who was the user who requested it.
My problem is that each notification, to each of the recipient phones, takes between 4 and 5 seconds minimum for each sequential sending in order to each one of them has been entered into the system.
Then, the user who is in the 5th place receives the notice of the action after at least 25 seconds after the action and during the time that these notifications are being sent, it is not possible to exit the sending function until completing all the sequential announcements.
If it were a group, as in case 1, all users would have found out simultaneously!
So, the specific question is, how to use ESP32 or ESP8266 in a single wifi module, which has been assigned a token in the creation of the bot, so that it works in both ways (group or selective by use of IDBot?).
To generate notifications using group mode; for programming or specific access to a certain phone, the IDBot usage mode.
If someone has had this situation, has found the solution and wants to share it, even in a private way with payment to be determined, we will maintain a private communication by email or we will provide our evidence in this regard among those interested.
I do not know if this type of request is allowed in the tutorial or I have to comment on my situation in the Facebook forum of which I am an authorized member.
If someone is interested in continuing this topic or requesting more information about this “application” and this is not the appropriate place for this type of consultation, I would appreciate if you let me know.
Thank you
Alejandro
Hi Alejandro.
It is ok to publish your issue here.
However, I also recommend that you publish on the facebook group.
Your issue can have more view there.
Regards,
Sara
A interesting project with the use of Telegram, thanks. Will look for future updates.
I could only find the ID using, youtube.com/watch?v=Mjx4OruxTwM
I have set this up so that I can use it to open and close my garage door (instructables.com/Simple-Garage-Door-Hack-V3-Using-a-Telegram-Bot/).
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.
Do you have any pointers as how I could determine either GPS info or IP details for the Telegram client making the request?
Sorted đ https://github.com/witnessmenow/Universal-Arduino-Telegram-Bot/blob/master/examples/ESP8266/Location/Location.ino
I have adapted this to control my garage door but I am seeing around a 4+ second delay between me issuing my command and the door opening. There is about a 2 second delay for Telegram to respond with the reply message but then a further 2 seconds before the relay toggles. This latter delay does not make sense to me.
Hello,
If you want to get the group ID without a PC, you can add IDbot to the member list of your group and use the command /getgroupid@myidbot.
After you can remove IDbot from members.
Thanks for sharing đ
Hello Sara, great tutorial as usual !
Does the bot need to be unique for each ESP if I want to communicate with several controllers ?
Hi.
I think you can use the same bot for multiple boards.
Regards,
Sara
Hi Sara. I read this post and https://randomnerdtutorials.com/telegram-control-esp32-esp8266-nodemcu-outputs/
The main different is that in this post we can add few member to group and give them access to both by group id
But when I look on code. In CHAT_ID I need to put my ID from /getid , or group ID from URL.
But the code is same , you make the same compare
String chat_id = String(bot.messages[i].chat_id);
if (chat_id != CHAT_ID){
bot.sendMessage(chat_id, “Unauthorized user”, “”);
continue;
}
How does the code know if I configure with /getid or by GROUP ID.
Good day, I repeated everything exactly for you, but this error is displayed:
âX509List’ does not name a ttype…
Arduino ver 1.8.12.
library ESP8266WiFi ver 1.0
library ArduinoJson ver 6.15.2.
library UniversalTelegramBot ver 1.3.0
Please tell me how to solve this situation?
how to get the particular message id and how to use it in the code pls tell me
Hi Rui and Sara,
I wanna really thank U for this project ( and all the others ), they teach me a bunch of interesting things.
I adore especially the Telegram’s projects……and……may I please ask a liiiiitle thing……
How Can I send a .txt file in a Telegram group?
Please, explane it to me, cause I made a lot of this projects around my home ( never will be the same !!!).
Thank U soooo Rui and Sara, a big hug from Italy.
Hi.
Thank you for your nice words.
Unfortunately, we don’t have any example about that subject.
Regards,
Sara
Hi and thank you for this nice project
I am trying to send a command to restart the ESP32 with ESP.restart();
But when I perform it once it keeps restarting !!
Any idea please ?
Thank you
This describes exactly my problem.
bot.closeClient() sounds good, but does unfortunately not work.
hey,
Does someone know if i can get the name of my bot with a command? For example bot.messages[i].from_name gives me the name of the user who send a message but i want to get the name of the bot (for example @my_bot).
kind regards
Recreated this project with ESP8285 and 6 LEDs – worked like a charm. Thinking about creating an RC car for my group just for fun
That’s great!
Hello there,
I programmed the WeMos d1 mini as shown and it works ok when I enter the commands in the telegram app both on my iphone and Android tablet.
My 3d option is to use VBA Excel to send a message to the telegram bot. When I do this I see the instructions appear in telegram, but the led will not switch on or off on the WeMos d1. Also I don’t see anything in the serial monitor when I use the excel macros.
Anyone any idea how to solve this?
Hola Grupo, alguien me puede ayudar como puedo agregar mĂĄs led y poder controlar con el ESP32, estuve intentando agregar, pero sĂłlo puedo controlar 1led, espero me puedan ayudar,Gracias.
Hi Sara,
here I am … again !
I made a gruop of 10 sensors, light controller, yard controller and so….
All run perfectly (thank U so much)
Now, I wanna ask U: it’s possible get a multiple command to the members of the group?
For example can I ask the temperature ( /temp ) and I’d like all the members get an answear.
Is it possible, cause i did some tests …. for nothing.
Thanks a lot Renzo from Italy