How to automate/fix this input_select template

ok thanks very much, i will do as you suggest, and report back if issues arise… great help!

for the script, would it be like this then:

script:
  run_switch_command:
    alias: Run switch command
    sequence:
      - service: script.turn_on
        entity_id: script.{{name.lower()}}_{{command.lower()}}

Close:

script:
  run_switch_command:
    alias: Run switch command
    sequence:
      - service: script.turn_on
        data_template:
          entity_id: "script.{{name.lower()}}_{{command.lower()}}"

script:
- Invalid config for [script]: Entity ID script.{{name.lower()}}{{command.lower()}} is an invalid entity id for dictionary value @ data[‘script’][‘run_switch_command’][‘sequence’][0][‘entity_id’]. Got 'script.{{name.lower()}}{{command.lower()}}’
expected a dictionary for dictionary value @ data[‘script’][‘run_switch_command’][‘sequence’][0][‘data_template’]. Got None.

any thoughts… must be a typo?

—edit---- it was, forgot an indent… sorry

you need to make the name and command like in my previous example:

{% set name = states.input_select.switch.state | replace(’ ‘,’_’) %}

ill use this:

 {% set name = states.input_select.switch.state | replace(' ','_') %}
 {% set command = states.input_select.switch_command.state | replace(' ','_') %}
 script.{{name.lower()}}_{{command.lower()}}

thanks a million.
got an error first, but was a wrong ’ again.

working now:

now lets see if it 'll run :wink:

script.turn_on: Entity ID "script.kantoor_off" is an invalid entity id for dictionary value @ data['entity_id']. Got '"script.kantoor_off"'

maybe take out the quotes?

if i enter script.turn_on {“entity_id”:“script.kantoor_off”} in the dev-tools, it runs fine…

audio_auditorium_on:

----edit----
confirm: taking out the " " works, very simple setup doing its magic now. Thanks @petro!

because you are putting it in quotes. you don’t need quotes

“script.{{name.lower()}}_{{command.lower()}}”

to

script.{{name.lower()}}_{{command.lower()}}

ys thanks, thats what ive used now:

script:
  run_switch_command:
    alias: Run switch command
    sequence:
      - service: script.turn_on
        data_template:
          entity_id: >-
           {% set name = states.input_select.switch.state | replace(' ','_') %}
           {% set command = states.input_select.switch_command.state | replace(' ','_') %}
           script.{{name.lower()}}_{{command.lower()}}

Yamllint changes it to this:

--- 
script: 
  run_switch_command: 
    alias: "Run switch command"
    sequence: 
      - 
        data_template: 
          entity_id: "{% set name = states.input_select.switch.state | replace(' ','_') %} {% set command = states.input_select.switch_command.state | replace(' ','_') %} script.{{name.lower()}}_{{command.lower()}}"
        service: script.turn_on

I am always a bit confused by the strange order of their “preferred” code.

They do use " ", around the {% %} statements and final call. Why would the be better?

Look at the line closer. They use quotes around the entire thing, not around each statement and final call. This is done because single line requires quotes, multi line does not. That’s just the nature of yaml.

Hi Petro. I’d like to ask you a question and see if you can solve my problem.
I have created playlists in volumio media player with shell command.
In configuration.yaml ho scritto:
meda_player:

  • platform: volumio
    host: 192.168.178.64
    port: 3000

shell_command:
volumio_prova: ‘curl 192.168.178.64/api/v1/commands/?cmd=playplaylist&name=Prova’
volumio_prova1: ‘curl 192.168.178.64/api/v1/commands/?cmd=playplaylist&name=prova1’
volumio_classicfm: ‘curl 192.168.178.64/api/v1/commands/?cmd=playplaylist&name=Classic%20FM’

poi in script
volumio_playlist1:
alias: Prova
sequence:
- service: shell_command.volumio_prova

volumio_playlist2:
alias: prova1
sequence:
- service: shell_command.volumio_prova1

volumio_playlist3:
alias: Classic FM
sequence:
- service: shell_command.volumio_classicfm

I would like to create an input_select
example:
volumioplaylist:
name: Volumio Playlist
options:
- Select your favourite Radio
- script.volumio_playlist1
- script.volumio_playlist2
- script.volumio_playlist3
initial: Select your favourite Radio
icon: mdi:music

…but she don’t work.

Can you tell me how to create an input_selct to get a list to select the various playlists? Thank’s in advance!!!

you’ll need to make an automation that triggers off state changes for the input select and fires the appropriate script.