I’m here to share a template to put in automations.yaml for Telegram inline Keyboard.
I hope it can help some people.
####################################################
# #
# Telegram #
# Keyboard #
####################################################
### Start Keyboard ###
- id: telegram-start
alias: 'Telegram Start Command'
initial_state: 'on'
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/start'
action:
- service: notify.notify
data:
message: >
{{ [
"Hi",
"Hello",
"Yes Sir!",
"it's a pleasure to see you again"
] | random }}
data:
keyboard:
- '/start, /cp'
####################################################
# #
# Telegram #
# Inline Keyboard #
####################################################
#############################
### Start Inline Keyboard ###
#############################
- id: telegram-control-pannel-start
alias: 'Telegram Control Pannel Command'
initial_state: 'on'
trigger:
platform: event
event_type: telegram_command
event_data:
command: '/cp'
action:
- service: notify.notify
data:
message: >
{{ [
"Home Assistant Status",
"Control Panel",
"Yes Sir!",
"Home Assistant Control Panel",
"Pannello di controllo"
] | random }}
data:
inline_keyboard:
- 'Lights:/lights, Status:/status, Security:/security'
- 'System:/system, Help:/help, Ping:/ping'
- "Addons:/addons"
- "Gimme Pizza:/gimmepizza, No thanks:/nopizza"
####################
### IK Ping Pong ###
####################
- id: telegram-ik-ping-pong
alias: 'telegram ping pong'
hide_entity: true
trigger:
- platform: event
event_type: telegram_callback
event_data:
data: '/ping'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: >-
Callback received from {{ trigger.event.data.from_first }}.
Message id: {{ trigger.event.data.message.message_id }}.
Data: {{ trigger.event.data.data }}
{{now().strftime("%H:%M:%S %Y-%m-%d")}} Pong, Message from {{ trigger.event.data["user_id"] }}.
show_alert: true
#########################
### IK Security Alarm ###
#########################
- id: telegram-ik-security-alarm
alias: 'Telegram Alarm'
hide_entity: true
trigger:
- platform: event
event_type: telegram_callback
event_data:
data: '/security'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Alarm control'
- service: telegram_bot.edit_message
data_template:
message_id: 'last'
chat_id: '{{ trigger.event.data.user_id }}'
message: >
{% if is_state("input_boolean.burglar_alarm_door", "off") %}Alarm is OFF. {% else %}Alarm is ON. {% endif %}
{% if is_state("input_boolean.away_scene", "off") %}Presence simulation is OFF. {% else %}Presence simulation is ON. {% endif %}
inline_keyboard:
- 'Away ON:/away_on, Away OFF:/away_off'
- 'Alarm ON:/alarm_on, Alarm OFF:/alarm_off, Cancel:/cancel'
#####################
### IK Pizza Time ###
#####################
- alias: 'Want pizza?'
hide_entity: true
trigger:
platform: time
at: '18:30:00'
condition:
- condition: state
entity_id: device_tracker.iphonemarie
state: 'home'
- condition: state
entity_id: device_tracker.nico_nico
state: 'not_home'
action:
- service: telegram_bot.send_message
data_template:
title: 'Want pizza?'
target: telegram ID
message: 'You look like you are home alone. Should I order you a pizza?'
inline_keyboard:
- "Gimme Pizza:/gimmepizza"
- "No thanks:/nopizza"
- alias: 'No pizza'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/nopizza'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Ok, no pizza then'
- alias: 'gimme pizza'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/gimmepizza'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'PIZZA TIME'
- service: dominos.order
data:
order_entity_id: dominos.medium_pan
#################
### IK Lights ###
#################
- alias: 'Lights Actions'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/lights'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'What you want to do with Lights?'
- service: telegram_bot.send_message
data_template:
title: 'Lights ON or OFF?'
target: telegram ID
message: 'Look like you want to turn on or off your lights. What you want to do?'
inline_keyboard:
- "ALL ON:/lighton, Living ON:/Living_on, Bedroom ON:/bedroom_on"
- "ALL OFF:/lightoff, Living OFF :/Living_off, Bedroom OFF:/bedroom_off"
- "Kitchen ON:/kitchen_on, BathRoom ON:/bath_on"
- "Kitchen OFF:/kitchen_off, BathRoom OFF:/bath_off"
### All ligths
- alias: 'IK - Telegram - Light On'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/lighton'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Lights ON'
- service: light.turn_on
data:
entity_id: group.all_lights
brightness: 255
- alias: 'IK - Telegram - Light Off'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/lightoff'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Lights OFF'
- service: light.turn_off
data:
entity_id: group.all_lights
brightness: 0
### Living ###
- alias: 'IK - Telegram - Living Light On'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/Living_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Living Lights ON'
- service: light.turn_on
data:
entity_id: group.living_lights
brightness: 255
- alias: 'IK - Telegram - Living Light OFF'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/Living_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Living Lights OFF'
- service: light.turn_on
data:
entity_id: group.living_lights
brightness: 0
### Kitchen
- alias: 'IK - Telegram - Kitchen Light On'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/kitchen_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Kitchen Lights ON'
- service: light.turn_on
data:
entity_id: group.kitchen_lights
brightness: 255
- alias: 'IK - Telegram - Kitchen Light OFF'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/kitchen_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Kitchen Lights OFF'
- service: light.turn_on
data:
entity_id: group.kitchen_lights
brightness: 0
### Bed Room
- alias: 'IK - Telegram - BedRoom Light On'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/bedroom_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'BedRoom Lights ON'
- service: light.turn_on
data:
entity_id: group.bedroom_lights
brightness: 255
- alias: 'IK - Telegram - BedRoom Light OFF'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/bedroom_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'BedRoom Lights OFF'
- service: light.turn_on
data:
entity_id: group.bedroom_lights
brightness: 0
### Bath Room
- alias: 'IK - Telegram - BathRoom Light On'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/bath_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'BathRoom Lights ON'
- service: light.turn_on
data:
entity_id: group.bathroom_lights
brightness: 255
- alias: 'IK - Telegram - BathRoom Light OFF'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/bath_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'BathRoom Lights OFF'
- service: light.turn_on
data:
entity_id: group.bath_lights
brightness: 0
#################
### IK System ###
#################
- alias: 'HA System Actions'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/system'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'What actions you want to do on HA?'
- service: telegram_bot.send_message
data_template:
title: 'HA System Actions'
target: telegram ID
message: 'Look like you want to do something about your Home Assistant istance.. What you want to do?'
inline_keyboard:
- "Check Config:/config, Automation Reload:/automreload"
- "SSL certificate:/ssl, SSL Renew:/sslrenew"
- "HA Restart:/harestart, Host Reboot:/hassioreboot"
### Automation reload
- alias: 'IK - Telegram - Automation reload'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/automreload'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Automation Reload'
- service: script.reload_automations
- service: notify.notify
data:
message: 'Automation - Reload - Triggered'
### HA Restart
- alias: 'IK - Telegram - HA Restart'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/harestart'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'HA restart'
- service: script.restart_ha
- service: notify.notify
data:
message: 'HA - Restart - Triggered'
### SSL Renew
- alias: 'IK - Telegram - SSL Renew'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/sslrenew'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'SSL Renew'
- service: script.letsencrypt_renew
- service: notify.notify
data:
message: 'SSL - Renew - Triggered'
### Host Reboot
- alias: 'IK - Telegram - Host Reboot'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/hassioreboot'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Host Reboot'
- service: hassio.host_reboot
- service: notify.notify
data:
message: 'Host - Reboot - Triggered'
#################
### IK Addons ###
#################
- alias: 'Addons Actions'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/addons'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'What you want to do with these addons?'
- service: telegram_bot.send_message
data_template:
title: 'Addons'
target: telegram ID
message: 'Look like you want to turn on or off your Addons. What you want to do?'
inline_keyboard:
- "Web SSH ON:/webssh_on, Pi-Hole ON:/pihole_on"
- "Web SSH OFF:/webssh_off, Pi-Hole OFF:/pihole_off"
- "IDE ON:/ide_on, LogViewer ON:/logview_on"
- "IDE OFF:/ide_off, LogViewer OFF:/logview_off"
### Web SSH ###
### Addon SSH Web Start
- alias: 'IK - Telegram - Addon SSH Web Start'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/webssh_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon SSH Web Start - Triggered'
- service: hassio.addon_start
data:
addon: "aaaaaaaaa_ssh"
- service: notify.notify
data:
message: 'SSH Enabled... Web SSH is available at Http://x.x.x.x:7681'
### Addon SSH Web Stop
- alias: 'IK - Telegram - Addon SSH Web Stop'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/webssh_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon SSH Web Stop - Triggered'
- service: hassio.addon_stop
data:
addon: "aaaaaaaaa_ssh"
- service: notify.notify
data:
message: 'Addon SSH Web Stopped'
### Addon Log Viewer Start
- alias: 'IK - Telegram - Addon Log Viewer Start'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/logview_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon Log Viewer Start - Triggered'
- service: hassio.addon_start
data:
addon: "aaaaaaaaa_logviewer"
- service: notify.notify
data:
message: ' Log Viewer... Log Viewer is available at Http://x.x.x.x:4277'
### Addon Log Viewer Stop
- alias: 'IK - Telegram - Addon Log Viewer Stop'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/logview_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon Log Viewer Stop - Triggered'
- service: hassio.addon_stop
data:
addon: "aaaaaaaaa_logviewer"
- service: notify.notify
data:
message: 'Addon Log ViewerStopped'
### Addon Pi-Hole Start
- alias: 'IK - Telegram - Addon Pi-Hole Start'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/logview_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon Pi-Hole Start - Triggered'
- service: hassio.addon_start
data:
addon: "aaaaaaaaa_pi-hole"
- service: notify.notify
data:
message: 'Pi-Hole is available at Http://x.x.x.x:4277'
### Addon Pi-Hole Stop
- alias: 'IK - Telegram - Addon Pi-Hole Stop'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/logview_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon Pi-Hole Stop - Triggered'
- service: hassio.addon_stop
data:
addon: "aaaaaaaaa_pi-hole"
- service: notify.notify
data:
message: 'Addon Pi-Hole Stopped'
### Addon IDE Start
- alias: 'IK - Telegram - Addon IDE Start'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/ide_on'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon IDE Start - Triggered'
- service: hassio.addon_start
data:
addon: "aaaaaaaaa_ide"
- service: notify.notify
data:
message: 'IDE is available at Http://x.x.x.x:4277'
### Addon IDE Stop
- alias: 'IK - Telegram - Addon IDE Stop'
hide_entity: true
trigger:
platform: event
event_type: telegram_callback
event_data:
data: '/ide_off'
action:
- service: telegram_bot.answer_callback_query
data_template:
callback_query_id: '{{ trigger.event.data.id }}'
message: 'Addon IDE Stop - Triggered'
- service: hassio.addon_stop
data:
addon: "aaaaaaaaa_ide"
- service: notify.notify
data:
message: 'Addon IDE Stopped'
full automations.yaml can be found here