Using my telegram bot to reset a problem in HA

I have just managed to setup a Telegram bot and configure my entities to trigger a notification. Very useful system. For simplicity is it possible to send a reply to my bot which then resets an entity state for me?

I have searched here in the forum and not found any help so far with that?

I will revisit the documentation and report back if I find a solution.

Cheers!

I’m not sure what you mean by “resets an entity state”, but if you can do it in an HA automation, it can be triggered by a telegram message.

In my own setup, I have the telegram bot send me an inline keyboard with a few buttons to click to reply with, then use event_type: telegram_callback to respond.

I believe this is the original thread that got me started with the basics:

Thanks very much @Silicon_Avatar! That should put me on the right path I think. Yes I can do that in an automation.

What I am trying to do is be able to reset a tripped process in my water treatment system.
Telegram message:
HA_alert_bot
Grey Water Run Count is Tripped

I’ll post again with my solution.
Cheers again!

One more question for you (if I may) @Silicon_Avatar?
Is it possible to have the initial message the bot sends (in response to the trip condition) to me include the inline keyboard? Or do I need to communicate back to the bot first?
Can you perhaps detail how you set that up please?
Cheers again!

If you read the link @Silicon_Avatar posted you will see that it progresses like this:

  1. Something happens to trigger an automation in HA (e.g. Grey Water Run Count is Tripped)
  2. The automation sends an alert via the bot to Telegram with the keyboard
  3. User interaction with the keyboard generates an event
  4. The event fires further automations in HA (actions can include editing original message sent by bot)

Though having said that I have yet to be able to make the keyboard disappear or even send back an acknowledgement with this:

- id: telegram_action_disarm
  alias: 'Telegram Action Disarm'
  hide_entity: true
  initial_state: true
  trigger:
    platform: event
    event_type: telegram_callback
    event_data:
      data: '/disarm'
  action:
  - service: telegram_bot.answer_callback_query
    data_template:
      callback_query_id: '{{ trigger.event.data.id }}'
      message: 'OK, disarming alarm.'
  - service: telegram_bot.edit_replymarkup
    data_template:
      message_id: '{{ trigger.event.data.message.message_id }}'
      chat_id: '{{ trigger.event.data.user_id }}'
      inline_keyboard: []
  - service: script.alarm_disarm

Though it does disarm my alarm.

Thanks @tom_l!
I will try to get up to speed on all this before posting my solution.
Cheers!

Before I had access via VPN or ZeroTier I used Telegram extensively to communicate with my HA (without having to open a port).

I have a generic call back automation to ‘end a conversation’ and remove the keyboard and I am pretty sure it always worked. Which is surprising as it looks identical in principle to what you are doing.

I leave it here in case I missed something…

#====================
#=== Remove keyboard
#====================
automation:
  - alias: 'Telegram callback to remove keyboard'
    initial_state: on
    trigger:
      - platform: event
        event_type: telegram_callback
        event_data:
          data: '/remove_keyboard'

    action:
      - service: telegram_bot.answer_callback_query
        data_template:
          callback_query_id: '{{ trigger.event.data.id }}'
          message: 'OK, Goodbye for now!'

      - service: telegram_bot.edit_replymarkup
        data_template:
          message_id: '{{ trigger.event.data.message.message_id }}'
          chat_id: '{{ trigger.event.data.user_id }}'
          inline_keyboard: []

      - service: telegram_bot.send_message
        data_template:
          target: "{{ trigger.event.data.user_id }}"
          message: "Type */menu* to begin"

I think it might be because my actions ( script.alarm_disarm ) also includes a Telegram notification and I’m confusing the bot. I’m not really fussed. I commented it out. Now I get a reply from the script and the keyboard eventually disappears into the chat history spaz.