How to turn off a switch via Telegram chat window?

i get notifications via Telegram. can i set up actions in HA by simply typing a command?
for example, i would like to type “SIREN OFF” or “SIREN_OFF” to turn off the siren manually.
in my automation i have this and it does absolutely nothing:

alias: 'telegram listener SIREN OFF '
trigger:
  - platform: event
    event_type: telegram_notification_action
    event_data:
      action: SIREN OFF
action:
  - service: switch.turn_off
    entity_id: switch.elexa_consumer_products_inc_dome_siren_switch
  - service: notify.telegram
    data:
      message: siren now off
mode: single

This should help you get started:

yes, i saw that. but it looks like HA has to initiate the conversion and provide buttons for me to press, correct? i want to initiate the conversation so i wont have buttons.
for instance, if i want to check if my doors are locks, i would like to ask Telegram “door status” and HA will auto respond if my doors are on or off.

No, you can just type a command to the bot and have it do something when it get’s a specific message.
Look at the event-triggering section of the docs.

For example if I text my bot the command “/ip” it will reply with the current external IP of my HA server.

- id: 'telegramipcallback'
  alias: 'Telegram callback for IP'
  trigger:
    platform: event
    event_type: telegram_command
    event_data:
      command: '/ip'
  action:
  - service: notify.tg_notification_chat
    data_template:
      title: "From Home-Assistant:"
      message: "Your External IP is {{states('sensor.external_ip')}}"

your code works!!! thank you so much for the sample.
by the way, how did you get sensor.external_ip?
i dont have that anywhere in hassio

1 Like

There are a few different ways to get that information, including a built-in integration, however I’m using a rest sensor for this purpose.

# Alternative source: http://diagnostic.opendns.com/myip
- platform: rest
  resource: https://api.ipify.org?format=json
  name: External IP
  value_template: '{{ value_json.ip }}'
  scan_interval: 14400

I wonder to get this working using Nabu Casa instead of exposing HA by opening port?