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

Can you share an example how you did that?

Thanks @Domoticon

Trying to replicate your flow.
What is the grey node with right arrow? It seems a subflow or what?

The yellow right arrow is a telegram sender node, right? What are the parameters?

03

Thanks

That are Link input and output nodes. I use this to keep the flow ‘shows’ as clean as possible, otherwise it will show all loop-back lines. If you click on it, it will show the connections, if you don’t click it if will not show the connection lines.

You don’t have to use those, it’s just a personal solution I use.

1 Like

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?