Hi,
i was looking for a solution to allow my neighbour control of some garden lights (“Dr. Zzs Holiday Lights”) which are visible from both our gardens.
Allowing him direct access to my HA was no option.
The following topics allowed me to set up my solution, thanks for sharing guys!
Did you say you had this working for groups? I tried to set inline commands last year when I first set up telegram. Was there anything special you did? Or has the telegram component been updated so it works out of the box?
Hi,
it was my first attempt, so i don’t know if something has been changed.
I had to add the chat id of the group and the id’s of the users to “allowed_chat_ids”, after that it was up and running.
Hope this helps!
I can see how that might be helpful in some cases but I don’t want to get the messages every time someone is using the bot. Instead, replies should only go to the user who triggered the bot (unless of course it’s in a group chat, then its different).
Big thanks goes to @Ciquattro for sharing his template for the inline keyboard for telegram. I find it really interesting with the randomised responses, which makes this more fun
So the trick is using '{{ trigger.event.data.id }}'. That way the bot only replies to the user that used the command. In case anyone is interested I’ve included a preview from my automations and also here you can find @Ciquattro’s automations.yaml from his GitHub page.
#Starting command with randomised reply and inline keyboard with what to do next
- id: telegram-start
alias: Telegram Start Command
initial_state: 'on'
trigger:
platform: event
event_type: telegram_command
event_data:
command: /start
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: "{{ [ \"Hello!\", \"Welcome Back!\", \"Yes Sir!\", \"There you are\
\ Again!\" ] | random }} \n"
keyboard:
- /start, /settings
#Automation for settings menu
- id: telegram-settings
alias: Telegram - Settings
initial_state: 'on'
trigger:
platform: event
event_type: telegram_command
event_data:
command: /settings
action:
- service: telegram_bot.send_message
data_template:
target: '{{ trigger.event.data.user_id }}'
message: "{{ [ \"Control Panel\", \"Settings\", \"Here's your options\", \"\
What would you want me to do?\", \"Here you go\" ] | random }} \
\ \n"
inline_keyboard:
- Dehumidifier ON:/dehumi_on, Dehumidifier OFF:/dehumi_off
- All lights OFF:/all_lights_off, All lights ON:/all_lights_on
- Who is home? :/home_status
#One of the options that show up in the settings menu
- alias: Telegram - All Lights OFF
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: /all_lights_off
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: All lights are now OFF
- service: homeassistant.turn_off
data:
entity_id: group.all_lights
- service: switch.turn_off
data:
entity_id: switch.tp_link