Telegram bot notifications and communication

Hi, I receive successfully messages to my Telegram android app with notification from HASS.

But I receive message only from one user (I called it HASS). Since I setup many notifications I receive 2-300 messages a day making it a bit less useful.

I wish to establish more users and receive messages from different users like HASS-error-messages, HASS-sensor-values, HASS-important-alarms, and so on all of course from the same Home Assistant server.

Is this possible?

I achieved this by creating multiple group chats. Iā€™m still only using a single Telegram bot but one bot can join many different groups. Since a group does require more than two participants in order to be created, I just add my bot and IDBot to the group initially. Once I get the chat id, I remove IDBot from the group. So, i currently have one regular chat with my bot for my main notification channel, and one group called Hass-system that I use for lower-priority system status notifications. But you could create as many as you want in the same fashion.

Great thanks.
Still trying to understand how to make new groups.
I go in my Telegram android app, click on + then New groupā€¦ then, if i put my name (which in settings is @ xxxxx) xxxxx its not thereā€¦?

Edit got it, when you create a group the creator is part of the group by default.

I am curious how many groups you created and which type of messages for each group you use.

I really only have one group right now. My main chat with my bot is for my main notifications that I want to see. Right now, I get notifications when our mode changes to Home or Away. I also get an actionable notification when my alarm clock goes off in the morning, tied to a lighting routine on my bedside lamp.

My group, Hass-system, is for lower priority notifications. I have the android app configured to put notifications from that group at a low priority. Right now I get notifications for when my weekly snapshot runs and backs up to Google Drive, and when files get added to a folder Iā€™m monitoring, as well as when Home Assistant updates are available.

Thatā€™s all I have for now, but I still have more in mind. For example, Iā€™m also going to have a group that includes my wife, so that the bot can remind us of daily/weekly tasks that either of us can do (feeding the dogs, getting the mail, putting the trash out). That way, whoever completes the task can use the inline keyboard to indicate this so that if my wife wakes up after me, she can already know if the dogs have been fed. Or when I get home from work, I can already know whether sheā€™s brought in the mail or not.

I am having a hard time making this work
So this is what I did

I do have my bot called @mybot

I created a group HOME ALERT MESSAGES consisting of

  1. MYBOT
  2. HOME ALERT MESSAGES
    its CHAT_ID of this group is 12345

When I do the below command, the text SAMPLE TEXT goes correctly to the group HOME ALERT MESSAGES (XXX:YYY is the api of MYBOT)

curl -X POST "https://api.telegram.org/botXXXXX:YYYYY/sendMessage" -d "chat_id=-12345&text=SAMPLE TEXT"

But when I do this from Home assistant

notify:
  - name: alerts_telegram
    platform: telegram
    chat_id: 12345

with an automation

action:
  - service: notify.alerts_telegram
    data_template:
      message: 'TEST MESSAGE'

the message does not go to the group HOME ALERT MESSAGES, but only to MYBOT

What am I missing here??

EDIT I found two problems in my installation
1 groups starts with minus: -1234567
2 the service notify.xxxxx sends the message only to my bot, in order to send messages to my groups I need to use

  - service: telegram_bot.send_message
    data_template:
      message: 'John is home'
      target: '-group_chat_id'   # the group chat id (do not forget the minus)

EDIT: Nvm, looks like you got it while I was replying. :slight_smile:

Did you also add this piece to your configuration.yaml file?

telegram_bot:
  - platform: polling
    api_key: YOUR_API_KEY
    allowed_chat_ids:
      - CHAT_ID_1
      - CHAT_ID_2
      - CHAT_ID_3

The only other thing I see is that for the chat_id, it has a dash in front of it in the cURL example, but not in your configuration.yaml file. I know 12345 is not your actual chat id, but you may want to check and confirm what you have in configuration.yaml completely matches your Telegram chat_id. I donā€™t have my config in front of me, but Iā€™m pretty sure users have a positive number for their chat_id and groups always have a negative number.

Yes I had 3 problems (tweo are explained in the previous post), I also had to add the group id (with a minus in telegram_bot configuration

telegram_bot:
  - platform: polling
    api_key: !secret telegram_bot_api
    allowed_chat_ids:
      - -12345  # this is a group
      - 23456 # thjis is a user

No, I did that but was not working, I had to do the

- service: telegram_bot.send_message  # it works, 


- service: notify.xxxxx  # NOT working
1 Like

Is it possible to make Telegram ring the phone?

For important messages like: ALARM TRIGGERED, THIEVES IN THE HOUSE, CALL THE POLICE , I donā€™t think is enough receiving a simple text message, we are overwhelmed by text messages, I would prefer for important messages a ring or something

No, you canā€™t have it place a phone call, but you could do the following. Create a group for your highest priority messages. In Telegram, you can set up your notifications per conversation, so for your high priority group, you can set a particularly attention-getting notification sound.

You may also want to check out using the alert component, as it can work in tandem with your notification platform and do things like send notifications repeatedly at an interval. https://www.home-assistant.io/components/alert/

1 Like

Hey guys,

I am using the notification mentioned in the first post. I just upgraded to 0.88.2 on docker and I am getting the following error message:

Update for sensor.bins_out_offset fails
00:10 helpers/template.py (ERROR) - message first occured at 00:02 and shows up 9 times 

any idea? Did I miss something in the breacking changes of this version. I had version 0.87.x installed before and everyhting was working.

Anyone know what might be amiss? I get notifications from HA in Telegram, I get the keyboard and when I click the buttons the keyboard disappears but I never get an ā€˜OKā€™ and I donā€™t get the delayed messages?

Thanks!!

  - service: notify.telegram
    data_template:
      message: 'Black sacks waste collection tomorrow! Do you want a reminder?'
      data:
          inline_keyboard:
          - 'Yes 30 Minutes:/30m, Yes 1 Hour:/1h, Yes In the morning:/8h'
          - 'No need!:/removekeyboard'

  - id: 'telegramremoveinline'
alias: 'Telegram callback to remove keyboard'
hide_entity: true
trigger:
  platform: event
  event_type: telegram_callback
  event_data:
    data: '/removekeyboard'
action:
- service: telegram_bot.answer_callback_query
  data_template:
    callback_query_id: '{{ trigger.event.data.id }}'
    message: 'OK'
- service: telegram_bot.edit_replymarkup
  data_template:
    message_id: '{{ trigger.event.data.message.message_id }}'
    chat_id: '{{ trigger.event.data.user_id }}'
    inline_keyboard: []

  - id: 'telegramrepeat30m'
alias: 'Telegram callback to repeat message in 30 minutes'
hide_entity: true
trigger:
  platform: event
  event_type: telegram_callback
  event_data:
    data: '/30m'
action:
- service: telegram_bot.answer_callback_query
  data_template:
    callback_query_id: '{{ trigger.event.data.id }}'
    message: 'OK, reminding you in 30 minutes'
- service: telegram_bot.edit_replymarkup
  data_template:
    message_id: '{{ trigger.event.data.message.message_id }}'
    chat_id: '{{ trigger.event.data.user_id }}'
    inline_keyboard: []
- delay: '00:30:00'
- service: notify.telegram
  data_template:
    data:
      message: '{{ trigger.event.data.message.text }}'

Polite bump! :slight_smile:

To answer my own question, I got it working with this code:

  - service: telegram_bot.send_message
    data_template:
      title: 'Door Locked'
      target: 12345678
      message: 'Is the front door locked?'
      inline_keyboard:
        - "Yes:/doorlocked"
        - "No:/doornotlocked"

rather than the above. telegram_bot.send_message instead of notify.telegram

Dā€™oh! I see @Klagio had already battled this out

Now just got to try to figure out how to get the keyboard to disappear nicely. With the previous (but without working callbacks) THAT BIT did work!

I canā€™t see this in Telegram settings

Not sure about iPhone, but if you have an Android I can walk you through the Android app settings. In the specific chat you want to modify, tap the chat name in the header. Then tap Notifications on the next screen, followed by Customize. That will allow you to set up custom notification settings for that conversation.

1 Like

thanks, found!

How would I send my Alarm notifications to a group that say my wife and parents receive?

1 Like

You need to add your bot to that group and get the chat_id from said group.-

Thanks, all working