Is it possible to get multiple telegram bots?


#1

Is there any way use two different bots in telegram?


#2

Sure, you can have it.


#3

Great. How?


#4

Try this:

telegram_bot: 
  - platform: polling
    api_key: 1111111111333:asdfasdfasdfasdfasdfasdfasdfsaf
    allowed_chat_ids:
      - 11111111111
      - AAAAAAAAA

  - platform: polling 
    api_key: 222222222333:asdfasdfasdfasdfasdfasdfasdfasf 
    allowed_chat_ids:
      - BBBBBBBBB
      - 2222222222

#5

Thanks for the support but once I’ve done that I’m not sure how to select the right bot from which to send the message.

For example, I have a notify component set up for my original bot:

Example configuration.yaml entry for the notifier

notify:

  • name: NOTIFIER_NAME
    platform: telegram
    chat_id: CHAT_ID_2

I want to use two different bots in the same chat (one for health reminders, the other for problems in the house/alerts).


#6

Now I understand your need. In fact I use 2 bots, but one is just for inputs (managed by node-red). It may be possible to achieve what you want with node-red, but I don’t know if you can using just HA.


#7

Unfortunately I’m using hassbian so nodered is difficult to install and use


#8

What?

You just install nodered as indicated on their website. It’s no different than installing any other applications


#9

I have two separate bots created, 1 for general info and 1 for security alerts. Funny thing is that this used to work quite a few revisions ago. I believe it worked back then because you could specify an API Key for the notifier like so

notify:
  - platform: telegram
    name: telegram_HA
    api_key: 123456AABBCCDDEEFFF
    chat_id: 123456789ZZ

This appears to be ignored now and will only deliver to the first configured Telegram Bot. Anyone have any ideas?


#10

I have the same question. Anyone know?


#11

Same here. would like a separate bot for alarm notifications and on with general info…


#12

Hi,

Same here too. I couldn’t get it working with only HA, but I got it working using the MQTTWARN. You will have another app/docker running but there’s some advantages in doing so, because you decouple the notifications from HA, which means that if you want change how/who gets a notification you can do that without restarting HA. The basic idea is that you publish to a topic what message you want to send, and on MQTTWARN you create the rules on how and to who this message should be sent. Since HA can talk directly to the MQTT instead of using a component you should create a script, like this:

homealert:
  sequence:
    - service: mqtt.publish
      data_template:
          payload: "{{ message }}"
          topic: mqttwarn/alert/msg

you may call the script like this:

- service: script.homealert
        data_template:
            message: "Danger Will Robinson"

The configuration of the mqttwarn is simple, the relevant part of mine (i.e. not including the mqtt part) looks like this:

[config:telegram]
timeout = 30
parse_mode = 'Markdown'
token = '<your_bot_token>'
targets = {
      'j01' : [ '#-33xxxxxxxx' ],
      'j02' : [ '#-2xxxxxxxxx' ]
}

[mqttwarn/info/+]
targets = telegram:j01

[mqttwarn/alert/+]
targets = telegram:j02

As you can see, you don’t need two bots! Just create different groups and include people/bots you want.


#13

I actually solved my idea in a different way than having 2 bots.
I have 1 bot but two telegram groups.
1 group for generic notifications and the other for urgent notifications.
I added the chat id’s of those 2 groups to the allowed chat ids:

telegram_bot:
  - platform: broadcast
    api_key: !secret telegram_api
    allowed_chat_ids:
      - !secret telegram_chatid
      - !secret telegram_chatid2

Then under notify I created 2 items called Bot and BotUrgent with those same chatid’s:

notify:
  - name: TelegramBot 
    platform: telegram
    chat_id: !secret telegram_chatid
  - name: TelegramBotUrgent   
    platform: telegram
    chat_id: !secret telegram_chatid2

So now in an automation I can send it to either of the 2.
If you also add (both under telegram_bot as under notify) for instance the chatid of your own telegram account (so not the groups but your private one), you can also send notifications only to yourself instead of the groups. I did that because my wife is in the groups but some notifications really only need to go to myself.


#14

Having groups you will see messages arriving from different “users” in telegram android/iphone app correct?
Will investigate how to do these different groups, and use also @clyra idea of mqtt, I like way more of doing changes without having all the time to restart HASS


#15

Also interested how many groups you guys use, and for each group which type of messages /notifications you use (for inspiration)