Telegram messaging questions

I can send a Telegram command called /status where it will return statuses of certain devices (lock, certain lights, etc.). I have a few questions:

  1. How can I include the device’s name along with the status?
  2. Is there a way to format the Telegram message so that each device’s name and status is returned on a separate line?

Here’s my automation:

- id: telegramstatusinquiry
  alias: Telegram - Status inquiry
  trigger:
  - event_data:
      command: /status
    event_type: telegram_command
    platform: event
  condition: []
  action:
  - service: telegram_bot.send_message
    data_template:
      message: >
        {{ states.lock.schlage_be468_touchscreen_deadbolt_locked.state }}, 
        {{ states.group.family.state }}

Here’s what the automation is currently returning in Telegram: https://imgur.com/kZ4OtVm

Maybe try something like this:

  - service: telegram_bot.send_message
    data_template:
      message: |
        {%- set lock = states.lock.schlage_be468_touchscreen_deadbolt_locked -%}
        {%- set group = states.group.family -%}
        {{ lock.name}} {{ lock.state }}, 
        {{ group.name }} {{ group.state }}

That pretty much did the trick. Can you display the friendly name instead of the entity id? I tried {{ lock.friendly_name }} but that didn’t work.

Scratch that. Name is the friendly name. I changed the name in HA and Telegram is now returning what I was expecting. Thanks!

Just an FYI, name is either the friendly_name (e.g., lock.attributes.friendly_name), if the entity has one, or the entity_id if it does not. See State Objects.

1 Like