home-assistant.io/source/_components/telegram_bot.markdown
Gergely Peidl 7d9e13dc10 Fixing Telegram docs (#2637)
* Missing yaml formatter added for Telegram.

* Fixing the url of notify.telegram
2017-05-16 08:14:31 +02:00

2.1 KiB

layout, title, description, date, sidebar, comments, sharing, footer, logo, ha_release
layout title description date sidebar comments sharing footer logo ha_release
page Telegram chatbot Telegram chatbot support 2017-04-05 18:50 true false true true telegram.png 0.42

Use Telegram on your mobile device to send messages or commands to your Home Assistant.

A command looks like /thecommand

When received by hass it will fire a telegram_command event on the event bus with the following event_data:

command: "/thecommand"
args: "<any other text following the command>"
from_first: "<first name of the sender>"
from_last: "<last name of the sender>"
user_id: "<id of the sender>"

{% linkable_title Configuration samples %}

Simple ping pong example.

alias: 'telegram bot that reply pong to ping'
hide_entity: true
trigger:
  platform: event
  event_type: telegram_command
  event_data:
    command: '/ping'
action:
  - service: notify.notify
    data:
      message: 'pong'

Example that show keyboard interaction with notify.telegram

trigger:
  platform: event
  event_type: telegram_command
  event_data:
    command: '/start'
action:
  - service: notify.telegram
    data:
      message: 'commands'
      data:
        keyboard:
          - '/ping, /alarm'
          - '/siren'

and an automation to trigger a related command "/siren".

trigger:
  platform: event
  event_type: telegram_command
  event_data:
    command: '/siren'
action:
  - service: homeassistant.turn_on
    entity_id: switch.vision_zm1601eu5_battery_operated_siren_switch_9_0
  - delay: 
      seconds: 10
  - service: homeassistant.turn_off
    entity_id: switch.vision_zm1601eu5_battery_operated_siren_switch_9_0

An example to show the use of event_data in the action:

- alias: 'Kitchen Telegram Speak'
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: '/speak'
  action:
    - service: notify.kitchen_echo
      data_template:
        message: >
          Message from {% raw %}{{ trigger.event.data["from_first"] }}. {% for state in trigger.event.data["args"] %} {{ state }} {% endfor %}{% endraw %}