Telegram entity_id templating

It’s possible to use template with entity_id in automation? like something of the following…

  action:
   - service: switch.turn_on
     data:
       entity_id: >-
         'switch.myreef_relay_'{{ trigger.event.data.args }} 

Obviously the config above will not work, but I needed something like this?
If it’s possible I don’t want to create a single Telegram command for every entity id, but I prefer to accodate a text to the telegram command like /switch_on *relaynumber*

The other problem is that the content of {{ trigger.event.data.args }} is ['sometext'] and not the simple string sometext … so how I can remove the unwanted [' ']?

Yes it is possible.

You need to use data_template: instead of data:

To remove unwanted characters use | replace( "something , "" ) This will replace something with nothing.

Te replace ' (single quote) is a bit messy. You have to escape the ' with another ' like this:

{{ 'your_string' | replace("''", "") }}

This will remove all 's from a string.

2 Likes
 action:
   - service: switch.turn_on
     data_template:
       entity_id: "switch.myreef_relay_{{ trigger.event.data.args[0] }}"
2 Likes

Thanks guys! I really appreciated it!