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

Is that right? Because it is working on every standard install with Raspbian (Node Red is standard preinstalled) where I ever worked with.

Looks to me it is a HassOS related issue. Please correct me if I’m wrong.

Not fully wrong, not correct either.
There are more factors to take into account. HassOS is not one of them, since Hass.io runs everything in containers.

Raspbian is a special kinda thing… So that is not a generic solution in this case.

Another difference, the add-on is based on Alpine Linux (which uses Musl lib instead of GLibc at the core).

@Domoticon there you go, corrected :wink:

1 Like

I get it @frenck. Thanks for the correction :smile:

@frenck, I just discovered your YouTube channel, looking at your 21 if June 2019 stream and now it think I get it!

Can you tell me what Ubuntu version you use for your VM? I want to setup the thing you are talking about, using VirtualBox.
EDIT: Nevermind, I got a working setup now, just by watching what you did! Thank you!

Thank you for all your work. It’s very, very impressive. Ga zo door! :wink:

I just attempted this reading your instructions and found the same issue around the UserId.

There is a userid-bot (@userid_bot) that can be used, might be worth updating the original post?

There are several bots doing that, but I’m reluctant with that. You never know if, and, or how they are (want to) use it.

I found an other solution, when you have to get the user-id without the Telegram Node-Red functions, which looks more secure to me:

  1. Go to the web version of the Telegram messenger with your browser: https://web.telegram.org

  2. Login with your phone number. Your Telegram messenger app on your phone will sent you login-code. Use this code to log in into the Telegram web version.

  3. Select your Saved Messages account.
    FYI: In fact, that is your private Telegram cloud storage.
    If you don’t see that ‘account’ you can enable it, if I remember correctly, by selecting the 3 horizontal stripes icon (left top) in your Telegram phone messenger app and select the saved messages option from the pull down menu. Store a message and the Saved Messages account should show up.

  4. Check the web-browser URL, it will look something like:

https://web.telegram.org/#/im?p=u12345678_9101112131415161718

Your user ID is the number between the im?p=u and the _ character, in the above example 12345678.

In this way you can get all user-IDs of your contacts, by selecting them and check the URL!

P.S. When done, don’t forget to log out from the Telegram web version by selecting the top left 3 horizontal stripes (Options), select Settings, select Log out at the bottom.

1 Like

Hi @Domoticon

I’m trying to use the flows at first post, but I get a strange behaviour

This is my example

and this is how is defined the Telegram Receiver node

This is the Menu node

This is just for test.

When I send the /start command I get the menu twice and if I send the /stop command I don’t get the end mesage, but I still get the menu again.

17

What is strange is that the only debug node where I get the message is # 1 as in the first image, it seems that does not go thru the other ones.

Any suggestion?

Thanks

I am in the same boat here. No matter how i try to send the video i get the same:
“Error: EFATAL: Unsupported Buffer file-type”

EDIT: I managed to get around this issue by using the telegram bot integration into Home Assistant.
I was able to call the “telegram_bot.send_video” service to send the file to the targeted ChatID.

1 - If you use a Telegram Sender node, enable the Track and Pass Through options.

2 - Use for every command a Telegram Sender node and connect the output to all the Command node inputs (loopbacks). This is different from the example in the first posting, but I experienced the same issues/difficulties and that is how I solved it.

3 - In your example, make sure the Telegram Sender node connected, at the end of the /stop command, has disabled the Track and Pass Through options. This to make sure you can exit the Telegram tracking. Be aware if you don’t do this it can be resulting of being stuck in the Telegram tracking loop.

4 - if duplicated commands occur, you could use a trigger node between the command which is duplicated with options set to:
Send: nothing
then: wait for, 1, Seconds, extend delay if new message arrives
then send: the latest msg object
Handling: all messages
FYI, this my noob solution…

Hope this helps.

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”