I have an automation that turns off my AC and sends me a Telegram notification whenever I leave my apartment.
Everything works smoothly, and my conf looks like this:
action:
- service: homeassistant.turn_off
entity_id: switch.ac
- service: notify.yeralin_bot
data:
title: "AC was turned off"
message: "Seems like you left your apartment with AC on, I gladly turned it off for you :)"
data:
inline_keyboard:
- "I'm still home:/turnOn AC"
- "All good:/dismiss"
When I receive the notification, I have 2 inline_keyboard buttons, if I press “I’m still home”, it will turn my AC back on, If I press “All good”, it will remove the inline_keyboard buttons.
What I want here is to automatically remove these inline_keyboard buttons after a minute (if there is no response).
So, I came up with following:
action:
- service: homeassistant.turn_off
entity_id: switch.ac
- service: notify.yeralin_bot
data:
title: "AC was turned off"
message: "Seems like you left your apartment with AC on, I gladly turned it off for you :)"
data:
inline_keyboard:
- "I'm still home:/turnOn AC"
- "All good:/dismiss"
- delay: 0:01
- service: telegram_bot.edit_replymarkup
data_template:
message_id: '{{ action.data.message.message_id }}'
chat_id: '{{ notify.yeralin_bot.data.user_id }}'
inline_keyboard: []
The problem here, that it cannot resolve {{action.data.message.message_id}}. I could have used {{last}}, but then I have other messages that might come from Telegram bot, and I don’t want to remove inline_keyboard buttons from them by accident.
But you can assign the same command to a variable:
sent = update.message.reply_text('Some inline menu', reply_markup=reply_markup)
Which then sends the message as usual, but also stores all the messge details as a dictionary in the sent variable, so you can get all the details from it, like message id, chat id and time sent.
I haven’t figured out yet how to use this to remove Inline keyboard after a period of time, but it certainly helps.
Hi, I know this is a year later, but I struggled with the issue to get the message_id, so i wanted to post incase others struggle and come across this post.
@daniyar94, I am not sure what is in your trigger for the above code, but the {{action.data.message.message_id}} code only works off of a event_type: telegram_callback (from my limited understanding).
I needed to create a cancel inline keyboard so that i can cancel and the massage would be deleted, below is how I achieved this: