If you want to control your home automation system remotely, you might want to consider using the Home Assistant Telegram integration.
Telegram is a messaging app that allows you to send messages, photos, videos, and other types of files over the internet. With Telegram, you can create a chatbot that will interact with Home Assistant, a popular home automation platform that enables you to automate your home.
In this article, I will guide you on how to set up and use Telegram with Home Assistant and provide some common troubleshooting tips.
Introduction
Home Assistant is a powerful home automation platform that allows you to control various devices and services in your home. With Home Assistant, you can create automations, set up schedules, and even integrate with third-party services.
Telegram is a messaging app that enables you to send messages, photos, videos, and other types of files over the internet. By integrating Telegram with Home Assistant, you can control your home automation system remotely using a chatbot.
Prerequisites
Before we start, make sure that you have the following:
A working Home Assistant installation
A Telegram account
A Telegram client installed on your device (iOS, Android, Windows, MacOS or Linux)
Setting up Telegram
Creating a Telegram account
If you don't have a Telegram account yet, you can create one by following these steps:
Download the Telegram app from the App Store or Google Play Store.
Open the Telegram app and tap "Start Messaging".
Enter your phone number and tap "Next".
Enter the verification code that you received via SMS.
Enter your name and upload a profile picture (optional).
Creating a Telegram bot
To create a Telegram bot, you need to follow these steps:
Open the Telegram app and search for "BotFather".
Tap on "BotFather" and then tap "Start".
Type "/newbot" and follow the instructions to create a new bot.
Once you have created the bot, BotFather will give you an HTTP API token. Keep this token safe, as you will need it in the next section of steps.
Setting up Home Assistant with Telegram
Installing Telegram bot integration
To use Telegram with Home Assistant, you need to install the Telegram bot integration by following these steps:
Open your Home Assistant configuration.yaml file and add the following YAML code then save the file. Replace YOUR_API_KEY_HERE with your own API key that you acquired in the previous steps above.
telegram_bot:
- platform: polling
api_key: YOUR_API_KEY_HERE
allowed_chat_ids:
- YOUR_CHAT_ID
You will also need your own unique chat ID to replace with YOUR_CHAT_ID seen above.
The easiest way I have found to find a chat ID is to send your bot a message then immediately open your web browser and go to https://api.telegram.org/bot<YOUR_API_TOKEN>/getUpdates then look for the "id" attribute after the "chat" section (see the highlighted chat ID in my example below).
Using Telegram with Home Assistant
Receiving notifications from Home Assistant
To receive notifications from Home Assistant using Telegram, you need to modify your configuration.yaml file again by adding the notification settings.
Open your configuration.yaml file and add the following code under the existing notify: section. If you don't have a notify section then include the notify: line.
notify:
- platform: telegram
name: 'Telegram Bot'
chat_id: YOUR_CHAT_ID
Now you can use Telegram notifications in any of your automations.
Before you update or create an automation it would be wise to test if your Telegram bot can receive messages correctly.
Testing your Home Assistant Telegram Bot
From inside Home Assistant browse to Developer Tools then Services and search for your Telegram Bot notification service. In my example, the service is called notify.telegram_bot
After entering a custom message in the message box and clicking the Call Service button you should instantly receive a message from your bot in the Telegram app.
The Telegram Home Assistant integration is capable of much more including attaching videos and photos, sending documents, and location information. These options go beyond the scope of this beginner's guide. If you would like to make your Telegram bot more powerful you should check out the official documentation from Home Assistant for Telegram.
Troubleshooting
If you are experiencing issues with Telegram and Home Assistant integration, you can try the following troubleshooting steps:
Make sure that you have installed the latest version of Home Assistant and Telegram.
Check if your Telegram bot is authorized to send messages to Home Assistant.
Double-check if you have entered the correct API token and chat ID in the Telegram integration settings.
Restart Home Assistant and Telegram to refresh the connection.
Conclusion
By integrating Telegram with Home Assistant, you can control your home automation system remotely using a chatbot. With Telegram, you can send commands to Home Assistant and receive notifications from it. Follow the steps outlined in this guide to set up and use Telegram with Home Assistant.