[HowTo] Setting up a Telegram Bot for all your Home Automation messages

That are Telegram Sender nodes. You can enable the smaller icon by the Label-Hide image option in the settings tab image (most right tab) of your Telegram Sender node.

The settings depends on your private Telegram-bot settings.

EDIT: Your bot configuration looks okay with me, looking at your configuration screenshot.

1 Like

@woody4165
Just a suggestion, in your Telegram-bot setting you can add the logfile option. It will write all Telegram communication to a txt file on a specified location. It can be handy to watch what is happening and it even shows all non-authorized communication.

Synthax: <path_to_logfile_location>/<name_of_logfile>

Sure.

[{"id":"e3844358.586c","type":"api-call-service","z":"a1026aeb.28b498","name":"Send Video","server":"c5be9440.e8c1a8","service_domain":"telegram_bot","service":"send_video","data":"{\"file\":\"/config/www/cam_videos/study/study.mp4\",\"caption\":\"Here you go!\",\"target\":\""TELEGRAM_CHAT_ID\"}","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":2350,"y":580,"wires":[["3dd1dd94.6c7e82"]]},{"id":"c5be9440.e8c1a8","type":"server","z":"","name":"Home Assistant"}]
2 Likes

Thank you @holymonkey101 :+1:

Okā€¦ everyone is asking great questionsā€¦

Heres the first stupid oneā€¦ does my instance of HA need to be open to the internet for this to work!
ā€¦ Hanging my head in shame while I wait for the smart people to help

I hate that the instructions on the dock page does not list dependencies and requirements!

Im gonna eat crowā€¦ sort ofā€¦
No Telegram in BROADCAST mode does not require exposureā€¦

but It wasnt mentioned here:


or on the other three component pagesā€¦ UGHā€¦
But Im still getting this error
xxxxxxxxxxx = My Chat Id
Error sending message: Forbidden: bot canā€™t initiate conversation with a user. Args: (xxxxxxxxxxx, ā€˜This is a testā€™), kwargs: {ā€˜parse_modeā€™: ā€˜Markdownā€™, ā€˜disable_notificationā€™: False, ā€˜disable_web_page_previewā€™: None, ā€˜reply_to_message_idā€™: None, ā€˜reply_markupā€™: None, ā€˜timeoutā€™: None

Did you send a first message with Telegram Messenger App to your bot for initiation of the user?
Also, did you add you, as user, to Telegram as allowed user id?

# https://www.home-assistant.io/components/telegram_bot.broadcast/
  - platform: broadcast
    api_key: 123456789:abcdefghijklmnopqrst
    allowed_chat_ids:
      - xxxxxxxxx

This is my telegram.yaml file content, which is included in configuration.yaml with

telegram_bot: !include telegram.yaml

Also I added a notify config to use the telegram_bot for notifications using notify.yaml.

# https://www.home-assistant.io/components/notify.telegram/

  - name: admin
    platform: telegram
    chat_id: xxxxxxxx

Also I included notify.yaml in the configuration.yaml:

notify: !include notify.yaml

Hope my setup examples will help you get it up and running.

Thanks for your help!!!

Did you send a first message with Telegram Messenger App to your bot for initiation of the user?
Also, did you add you, as user, to Telegram as allowed user id?
I think I didā€¦ from my phone I sent ā€œThis is an initial messageā€ and I have I have on the left hand side of the app a ā€œContactā€ called HomeAssistant"
Initial

Right now I have all my Telegram configuration in my Config yaml fileā€¦ and it looks just like yoursā€¦

telegram_bot:
  - platform: broadcast
    api_key: xxxxxxxxxx
    allowed_chat_ids:
      - xxxxx
notify:
  - name: telegram
    platform: telegram
    chat_id: xxxxxxx

Iā€™m guessing Iā€™m missing something concerning this:
Iā€™m unclear precisely what you mean

ā€œā€¦ did you add you, as user, to Telegram as allowed user idā€

I meant adding your user id to the allowed_chat_ids:

Also, you have, under notify: - name, a user called telegram. The user setting of this is the user you use to log-in to HA.

So if you donā€™t have an user in your HA setup added with the name telegram, it will not work, I guessā€¦

EDIT: FYI, I use my admin user as setup for notifying.

FYI, you can check sending a message in config --> services (developer tools):

Service:
notify.<HA_USER>
Service data:
{
ā€œmessageā€: ā€œ:warning: Test message from Home Assistant! :warning:ā€
}

I thought the ā€œ- nameā€" should be the name of the notify entity ( Iā€™ve changed it to ā€˜telegram_messagesā€™ to avoid any name space problems) so the entity now shows up as ā€˜notify.telegram_messagesā€™

My user idā€¦ which I got from Telegram by using /getid which gave me a 9 digit numberā€¦ is in the bot definition and the notify definition

So you made a new user in Home Assistant telegram_messages, if I understand it well.

Does it work now?

No I renamed the notification from telegram to telegram_messages
from the notify documentationā€¦

CONFIGURATION VARIABLES
name
(string)(Optional)Setting the optional parameter `name` allows multiple notifiers to be created. 
The notifier will bind to the service `notify.NOTIFIER_NAME`.
.
.
.

and no ā€¦ ;-( that didnā€™t make a difference

Okā€¦ successā€¦ I guess I had NOT talked to my botā€¦ I found thisā€¦

  • Bots canā€™t initiate conversations with users. A user must either add them to a group or send them a message first. People can use telegram.me/<bot_username> links or username search to find your bot.

and then sent this:
telegram.me/MyBotBname_bot and the message came thruā€¦

So this was the problem/solution, if I understand right?

Excellent! :+1:

Yesā€¦ exactly correctā€¦
I had not ā€œRTFMā€ā€¦

1 Like

:joy: Who does?

Hahahaha the longer I use HA the more I think I shouldā€¦

Its gotten personal! I will dominateā€¦ adapt and overcomeā€¦ eventuallyā€¦

But Iā€™ll settle for just getting it to work!

Again thanks for your help!

1 Like

Youā€™r very welcome!:+1:

Is there a way to send message / menu to multiple users ? I want to send my notification to myself and my wife.