Telegram_command and automation

I wanted to create a single automation using if then statement to integrate different commands.

I tried to set it up like this:

alias: Telegram
description: ""
triggers:
  - event_type: telegram_command
    trigger: event
conditions: []
actions:
  - if:
      - condition: template
        value_template: "{{ trigger.event.data.command }} == \"/ping\""
    then:
      - action: notify.notifyuser
        metadata: {}
        data:
          message: Pong
mode: single

The proble is the the value_template of the condition is always false.
First of all I do not know how to escape the /, i tryed using quotes, doublequotes, no quotes but the result is always false.
Considering I couldnā€™t find any sample I was wondering if this can work.

Regards

Mine doesnā€™t receieve the slash in the command. Just the text. I haven;t used this in a while so not sure if itā€™s changed. Hereā€™s my example: homeassistant-config/packages/integrations/messaging/telegram.yaml at aa4f4322a9d677e1ba08894c4eec4132c9c8f856 Ā· dannytsang/homeassistant-config Ā· GitHub

Thax a million, you drove me in the right direction.

Now the block looks like this:

  - if:
      - condition: template
        value_template: "{{ trigger.event.data.command == '/temp' }}"
    then:
      - action: telegram_bot.send_message
        data:
          target: "{{trigger.event.data.chat_id}}"
          message: >-
            {% set ns = namespace(sensors=[]) %}  {% for s in (states.sensor |
            selectattr('entity_id', 'in', integration_entities('zha')) ) if
            s.attributes.device_class is defined and
            s.attributes['device_class'] | lower == 'temperature' %}{{
            s.attributes.friendly_name | replace("Temperatura ","",1)}}{{':'}}
            {{ states(s.entity_id) }}
            {{s.attributes.unit_of_measurement}}{{'\n'}} {%- endfor %}

the actual test is value_template: ā€œ{{ trigger.event.data.command == ā€˜/tempā€™ }}ā€, so everything between {{ and }}.

Thx

1 Like