Telegram
The telegram
integrationIntegrations connect and integrate Home Assistant with your devices, services, and more. [Learn more] uses Telegram
Setup example
To create your first Telegram bot
- Bots are not allowed to contact users. You need to make the first contact from the user for which you want to set up the bot.
-
Tell Telegram to create a bot for you:
- In Telegram, open a chat with @BotFather and enter
/newbot
. - Follow the instructions on screen and give your bot a name.
- BotFather will give you a link to your new bot and an HTTP API token.
- Store the token somewhere safe.
- In Telegram, open a chat with @BotFather and enter
-
To get a chat ID, send any message to the GetIDs bot
. - Then, enter
/start
. - The bot will return your chat ID and the username.
- Then, enter
-
Create a Telegram bot in Home Assistant:
-
Paste this into your configuration file:
-
Replace the
api_key
and theallowed_chat_ids
with your data.
-
-
Create a notifier:
-
Paste this into your configuration file:
-
Replace the
name
and thechat_id
with your data. -
Restart Home Assistant.
-
-
From the conversation with BotFather, select the link to open a chat with your new bot.
-
In the chat with the new bot, enter
/start
. -
Test the action:
-
Paste this into the YAML file:
-
Replace the
service
and themessage
with your data. -
Select Perform action. You should now get a message.
-
You can do more with this. Check out the configuration descriptions and examples below.
Methods to retrieve a chat_id
Method 1: You can get your chat_id
by sending any message to the GetIDs bot
Method 2: To retrieve your chat_id
you can visit https://api.telegram.org/bot<YOUR_API_TOKEN>/getUpdates
or to use $ curl -X GET https://api.telegram.org/bot<YOUR_API_TOKEN>/getUpdates
after you have sent the bot a message. Replace <YOUR_API_TOKEN>
with your actual token.
The result set will include your chat ID as id
in the chat
section:
Method 3: Another way to get your chat ID directly is described below. Start your Python interpreter from the command-line:
If you want to add new chat IDs then you will need to disable the active configuration to actually see the result with the IDs, otherwise you may only get empty results array.
Method 4: You can also get the chat ID from the Home Assistant logs. If you have set up the bot already, you can send a message to your bot from an unauthorized ID and you will see an error entry in the log containing the ID.
Configuration
To enable Telegram notifications in your installation, add the following to your configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file.
After changing the configuration.yaml
The configuration.yaml file is the main configuration file for Home Assistant. It lists the integrations to be loaded and their specific configurations. In some cases, the configuration needs to be edited manually directly in the configuration.yaml file. Most integrations can be configured in the UI. [Learn more] file, restart Home Assistant to apply the changes. The integration is now shown on the integrations page under Settings > Devices & services. Its entities are listed on the integration card itself and on the Entities tab.
Refer to the platforms mentioned in the
Telegram chatbot page for
telegram_bot
configuration.
To use notifications, please see the getting started with automation page.
Text message
Photo support
Configuration Variables
A remote path to an image. Either this or the file
configuration option is required.
A local path to an image. Either this or the url
configuration option is required.
Set to false to skip the validation of the server’s SSL certificate.
Since Home Assistant version 0.48 you have to whitelist the source folder of the file you want to include in the notification.
Video support
Configuration Variables
A remote path to a video. Either this or the file
configuration option is required.
A local path to a video. Either this or the url
configuration option is required.
Set to false to skip the validation of the server’s SSL certificate.
Document support
Configuration Variables
A remote path to a document. Either this or the file
configuration option is required.
A local path to a document. Either this or the url
configuration option is required.
Set to false to skip the validation of the server’s SSL certificate.
Location support
Extra data attributes support
Configuration Variables
True/false to send the message silently. iOS users and web users will not receive a notification. Android users will receive a notification with no sound.
True/false to display a webpage preview.