#passing variable from input sentence into the action

1 messages · Page 1 of 1 (latest)

lost ice
#

So i have a http listener on my pc running waiting to receive start program firefox as an example. This works with the following automation:

alias: Start firefox
description: ""
triggers:
  - command:
      - firefox
    trigger: conversation
conditions: []
actions:
  - data:
      program_name: firefox
    action: shell_command.start_program
mode: single

I want to expand this to whatever programs are defined in my script on my pc without having to "hard code" this into home assistant

this is what i have but when i trace it the program_name is empty in the action part i think

alias: Start any program
description: ""
triggers:
  - command:
      - open {program_name}
    trigger: conversation
conditions: []
actions:
  - data:
      program_name: "{{ program_name }}"
    action: shell_command.start_program
mode: single

this shell command it calls is:

rest_command:
  open_program:
    url: 'http://ip:port/start/'
    method: POST
    content_type: 'application/json'
    payload: '{"command": "{{ program_name }}" }'
meager karma
#

Need to define program_name as a wild card slot i think

#

Oh wait nm, thought this was for a voice command at first. Not sure how a trigger works with a slot like that

#

So is it a sentence trigger on an automation with a wild card slot?

lost ice
#

yes I think is it since if you look at it from the gui automation it says when the sentence 'open {program_name}' is said. And i can say firefox into my atom echo and that will open firefox on my pc

meager karma
#

Not sure if slots work in sentence triggers from automations, I've only ever used them in intent scripts

#

Think in the past at least you couldn't use slots from the automation trigger sentence, not sure if that's changed

lost ice
#

but if I create an intent script i could possibly pass the program_name lets say notepad into the variable for the automation which will then pass it into the rest_command open_program?

meager karma
#

Hmm they may when now actually

#

Seems it is in trigger.slots

#

Or trigger.details

#

Looks like you may need to use

{{ trigger.slots.program_name }}
lost ice
#

oh you absolute legend, this did indeed fix it. Thank you so much!