Where Do I Put An Entity Picture Template Home Assistant Entity Picture Template
Are you the type of person who would love to have a butler or servant to practise all of your bidding?
Sure y'all can turn your lights on in the Home Assistant user interface, only it is far more than fulfilling when you need that your very own ServantBot-3000 does it for you lot!
Then in one case you have your own digital butler setup in Telegram, why not invite it to a group chat so your friends tin demand things besides!
- Prerequisite
- Create a new Telegram bot
- Visit the BotFather
- Get an access token
- Setup webhooks
- Setup DNS
- Port forwarding
- Setting setWebhook
- Getting chat & user IDs
- Adding the bot
- Setup Home Assistant
- Add the Telegram integration
- Create control automation instance
- Create text automation example
- Conclusion
Prerequisite
Y'all should have Home Banana installed and running and a bones understanding of YAML including how to editconfiguration.yaml. You should too understand how to use aservice andentity within Dwelling house Assistant.
If you are new to Home Assistant or you are non however familiar with editing YAML files then yous should definitely check out my beginners tutorial on YAML first. I would likewise recommend taking a await at my other tutorials on automation and scripts.
You will too demand an account with Telegram, yous tin fix ane upwardly using whatsoever of their apps. You can besides use Telegram in a browser if you lot do not want to install an app.
Create a new Telegram bot
Home Banana has a very powerful Telegram integration that provides united states with the power to host a fully functioning bot.
The bot tin can reply to texts and commands, triggering any services in Dwelling Banana. It can too answer to messages, send pictures, videos and much more than!
Your bot can deed as alternative to the companion app for sending notifications whilst allowing you and your friends and family unit to control your smart home gadgets. Awesome!
Visit the BotFather
In order to create your own Telegram bot you demand to visit the BotFather, a bot whose sole purpose is to create new bots. You can either visit the BotFather page or only add @botfather.
Once yous accept added @botfather in Telegram, send the message /offset and you will be presented with the available commands. Get alee and transport the message "/newbot" and follow the instructions to create a new bot.
Go an admission token
Once you take created your new bot, you will be given an access token. Alternatively you can type the /token control to show the token.
Once you have your token, temporarily copy and paste it into a text document equally we will demand it after for setting up webhooks and Home Assistant.
Setup webhooks
Using webhooks is the prefered mode to connect Telegram to Home Assistant. It likewise allows two way advice between the bot and Abode Assistant, meaning the bot tin can respond to commands and likewise respond with messages.
Setup DNS
In lodge for this to piece of work your Home Assistant setup must exist exposed to the cyberspace. You can follow my easy setup guide for DuckDNS if you don't however have a public address for your Home Assistant server.
Port forwarding
We will also need to create a port forwarding rule to forward traffic from port 80 to port 8123 of the Home Banana server. This is due to a port restriction enforced by Telegram when using webhooks. It is not possible to send data from the bot to port 8123.
If you already take port forwarding gear up, y'all tin either change the external port from 8123 to fourscore in your existing rule (leave the internal port set as 8123) or just create another rule that points port fourscore to port 8123.
The mode in which you lot create a port forwarding rule differs depending on your router. For more than information, run into the port forwarding section of my DuckDNS tutorial.
Setting setWebhook
A webhook is a method of communicating over the internet, which two software applications can use. Information technology makes use of the HTTP or HTTPS protocol so it is usually easy to implement on any machine with net access.
Home Assistant has build-in support for sending and receiving webhooks but we need to tell our Telegram bot to utilize our Domicile Assistant server address. Your webhook URL will be as follows, just replace <your-URL> with your own domain name.
Notation that y'all should either use HTTP or HTTPS depending on whether or not you accept set your Dwelling house Assistant up for SSL connection. See this mail service for further information.
https://<your-URL>/api/telegram_webhooks
To ready the webhook URL we need to employ the Telegram bot API. I know that when someone commonly says 'API' it means that there is some super-circuitous code involved. Nevertheless no demand to fearfulness! For this purpose it is really quite easy.
All we need to do to apply the Telegram bot API is blazon 1 URL into the address bar of our browser. You need to replace <YOUR-BOT-TOKEN> with the token that yous obtained before, and also supercede <YOUR-WEBHOOK-URL> with your webhook URL from above.
https://api.telegram.org/bot<YOUR-BOT-TOKEN>/setWebhook?url=<YOUR-WEBHOOK-URL>
If y'all typed everything correctly, you will be shown the webhook was set confirmation bulletin.
Note that if yous desire to modify your webhook address, you must first delete it. Yous can exercise this past sending the command with no URL.
Getting chat & user IDs
The concluding information that we need for our setup Habitation Assistant is the chat_id and group_id for whatsoever people or groups that we want to allow our bot to communicate with. Note that if you are using groups, you should even so add the private user IDs to the list likewise.
To get the ID of a user or group, you lot can use the @getIDs bot. Simply add the bot and result the /start command to get your user ID. You need to become the user ID for any other user you wish to include in your Home Banana setup, just ask them to also add the GetIDs bot and send you lot their ID.
You can too add the @GetIDs bot to a group in club to get the group ID, but note that the bot will only respond if there is at least ane other person in the group.
Besides note that a grouping ID begins with a negative (-) symbol, it is important to include this when adding a group ID to Home Assistant.
Adding the bot
The last thing we need to do earlier we setup Dwelling Assistant is to add our bot to Telegram. This is important as the integration will non work until we initiate the outset chat with the bot.
Only search for your bot in Telegram and open upwards a conversation with information technology. Then just event the /start control. Remember that although the bot can be found publically, only users and groups that nosotros authorise in Home Assistant will be able to communicate with it.
Setup Home Banana
At this stage you should take your very own Telegram bot fix upward, the token for the bot and a list of user IDs and group IDs that you wish to include in your Habitation Assistant integration.
You lot should also have an external URL set upwards for your Dwelling house Assistant server and a port forwarding rule that forrad traffic from the external port 80 to the Home Banana port (8123 past default).
Add the Telegram integration
Beginning we need to open upward configuration.yaml and add the Abode Banana integration. We will also specify the platform as webhooks.
telegram_bot: - platform: webhooks So we volition add together the external URL for our Abode Banana server, don't forget that we must specify port eighty and not the default port 8123.
We will too add the Telegram bot token that we obtained earlier. Supercede <YOUR-API-Primal> with the key you obtained earlier.
telegram_bot: - platform: webhooks api_key: <YOUR-API-KEY> Finally nosotros need to specify the user and grouping IDs that we wish to authorise. All of these fall under the same attribute allowed_chat_ids.
telegram_bot: - platform: webhooks api_key: <YOUR-API-Central> url: https://<your-URL>:80 allowed_chat_ids: - 123456789 # this is a user - -123456789 # this is a grouping (with the "-" symbol) Create command automation example
At present that we have fix the Telegram integration, we can write some automations that volition give functionality to our bot.
When y'all issue a command to the bot, it fires an event in Home Assistant called telegram_command. Nosotros can write an automation to handle this command and generate a desired response.
First we need to create a new automation under the automations integration. We will add together a trigger using the platform issue which responds to the event type telegram_command.
- alias: 'Telegram bot turn on lamp' trigger: platform: issue event_type: telegram_command event_data: command: '/lamp-on' Now we can add a standard activity, this can exist any you like. For example nosotros can turn on a lamp.
Nosotros can employ the service light.turn_on to switch on the calorie-free entity light.treelamp. Of course you should utilize your ain entity for entity_id.
- alias: 'Telegram bot turn on lamp' trigger: platform: event event_type: telegram_command event_data: command: '/lamp-on' action: service: light.turn_on entity_id: calorie-free.treelamp Awesome! Now when we consequence the control /lamp-on command, our Telegram bot will turn on the lamp!
Create text automation example
Let'due south look at some other example, this time using text every bit the trigger. This automation will trigger when the bot reads the specified text in a chat or grouping.
We will get the bot to boil the kettle and besides acknowledge the request in the chat or group where the message was received. We will create an automation as before just this fourth dimension using the telegram_text issue.
- alias: 'Telegram bot boil kettle' trigger: platform: event event_type: telegram_text event_data: text: 'boil the kettle' This time we will create a response from the bot using the telegram_bot.send_message service in the activity department of our automation.
We volition apply data_template to specify the target of the message to be the chat_id. This ways the bot will reply to the group or chat where it received the text.
Nosotros can also include a data template in the message aspect which inserts the name of the person from the chat or grouping who made the request. This is optional equally you tin can just specify a generic message here if you prefer.
- alias: 'Telegram bot eddy kettle' trigger: platform: event event_type: telegram_text event_data: text: 'eddy the kettle' action: - service: telegram_bot.send_message data_template: target: '{{ trigger.event.data.chat_id }}' message: 'Ok {{ trigger.result.information["from_first"] }}, boiling the kettle!' Finally we can add a second activeness to the automation that will plough on the switch for the kettle. This is a standard switch.turn_on service that specifies the desired entity_id.
- alias: 'Telegram bot boil kettle' trigger: platform: event event_type: telegram_text event_data: text: 'boil the kettle' action: - service: telegram_bot.send_message data_template: target: '{{ trigger.event.data.chat_id }}' bulletin: 'Ok {{ trigger.event.data["from_first"] }}, boiling the kettle!' - service: switch.turn_on entity_id: switch.kettle Awesome! Now when nosotros send the message "boil the kettle" to a grouping or chat with the bot, information technology volition plough on the kettle and respond with a message confirming the action.
Conclusion
The Telegram bot is really awesome! We can use this integration to create an entirely Telegram-based system to control an unabridged smarthome. Furthermore the control tin can exist extended to friends and family over the telegram platform.
Why non go ahead and cheque out some of my other Home Banana tutorials to get some ideas for the kind of things you could link to your new Telegram bot!
Where Do I Put An Entity Picture Template Home Assistant Entity Picture Template,
Source: https://siytek.com/home-assistant-telegram-bot/
Posted by: browningfroppres.blogspot.com

0 Response to "Where Do I Put An Entity Picture Template Home Assistant Entity Picture Template"
Post a Comment