Can I pass the script name / entity name as variable?

as always, when working on one thing, the second one pops up as an idea BTW, that “just can’t wait”…

this time I thought that something like “a script console” in Telegram could be usefull/fun while debugging and testing, so my plan is to make an automation that is triggered by TG command, it takes the first argument and uses it as script name that should be run next, but - as you probably already guessed - I’m stuck :wink:

here’s what I’ve got:

automation:

trigger:
  platform: event
  event_type: telegram_command
  event_data:
    command: '/runscript'
action:
  - service: template
    value_template: script.{{ trigger.event.data.args[0] }}
    data_template:
      var_message: "testing the *{{ trigger.event.data.args[0] }}* script"

script:

sequence:
- service: notify.my_telegram_bot
  data_template:
    message: "OUTPUT: {{ var_message }}"

so as you can see, I want to have an option, that I write to my bot:

/runscript here_is_the_name_of_script

and then hass.io runs the script.here_is_the_name_of_script

while checking the configuration in dashboard - it fails hard (I can’t even give you the error message, as the whole configuration is printed out as the error output :wink: - it is way too long (that’s what she said :joy: ))

I’m guessing, that my service: template (and the whole construction after that) isn’t something that is correct, but here’s the place for my question:
is there any actual way to use variable as the script- [or even entity-] name?

Start a bit smaller…

trigger:
  platform: event
  event_type: telegram_command
  event_data:
    command: '/runscript'
action:
  - service_template: "script.{{ trigger.event.data.args[0] }}" 

And then see if it runs a script that you put in the arg 0 ?

we’ve got the winner! :blush:

again, and again, and again… I’m always messing up the *_template parameters…
of course instead mine service: & value_template: below, it should be as you wrote: service_template :slight_smile:
and that fixes everything, my script works!

thank you!

1 Like