Input select Troubleshoot

Trying to configure an input_select that will change an FM radio station preset on my Onkyo.

Here is my configuration.yaml

input_select:
  radio_station:
    name: FM radio
    options:
      - Välj radio
      - RixFM
      - Radio Nova
    initial: Välj radio
    icon: mdi:radio

Here is my script.yaml

'1':
  alias: FM_radio_RixFM
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: fm
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.1'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service: shell_command.radio_rixfm

'2':
  alias: FM_radio_Nova
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: fm
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.1'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service: shell_command.radio_nova

Here is my shell_commands.yaml

radio_rixfm: onkyo -t 192.168.0.116 preset=1
radio_nova: onkyo -t 192.168.0.116 preset=3

Here is my automations.yaml

- id: '11'
  alias: FM Radio
  trigger:
  - platform: state
    entity_id: input_select.select_option
    from: Välj Radio
  action:
  - service: script.turn_on
    data_template:
      entity_id: >
        {% if is_state("input_select.radio_station", "RixFM") %}
          script.1
        {%-elif is_state("input_select.radio_station", "Radio Nova") %}
          script.2
        {% endif %}

What works:
The input_select dropdown show all my values
I can call my script.1 and script.2 from the services using script.turn_on meaning the shell_commands do work!

What don’t work:
When I select anything from the the input_select dropdown, nothing happens…

What am I doing wrong here?
No errors are present!

That automation will only trigger if the previous state of the input_select was Valj Radio. Remove the from line.

Also, it’s triggering from an input_select called select_option, that’s not what your input_select is called.

1 Like

Why not have 1 script only to make things easier to read / maintain?
Your script would first do all the bits that are not radio station dependant:

'radio_script':
  alias: Set_Radio_on_Onkyo
  sequence:
  - data:
      entity_id: media_player.onkyo_nrtx646
    service: media_player.turn_on
  - data:
      entity_id: media_player.onkyo_nrtx646
      source: fm
    service: media_player.select_source
  - data:
      entity_id: media_player.onkyo_nrtx646
      volume_level: '0.1'
    service: media_player.volume_set
  - alias: ''
    data: {}
    service_template: >
      shell_command.{% if is_state("input_select.radio_station", "RixFM") %}radio_rixfm
      {% elif is_state("input_select.radio_station", "Radio Nova") %}radio_nova
      {% endif %}

Then just set your automation to trigger the script based on state change of the input_select:

- id: '11'
  alias: FM Radio
  trigger:
  - platform: state
    entity_id: input_select.select_option
  action:
  - service: script.turn_on
    data:
      entity_id: script.radio_script

Quick question, why do you have an extra alias: '' before calling your shell commands in your original code?

By the way, based on the above you could even take the script out of the equation altogether and just stick with 1 single automation…

1 Like

Thanks, that did solve the problem!

Thanks, I really like that solution. Makes the code more clean!
This was my first attempt on making a script, still learning.

Removed the alias: '' that was something the script editor added. I used it in the beginning to start creating my script. Then I use an editor to make adjustments.

In the automations.yaml you wrote entity_id: input_select.select_option that should be entity_id: input_select.radio_station. And in the scripts.yaml I had to add an extra - before the elif so that line of code reads
{%-elif is_state("input_select.radio_station", "Radio Nova") %}radio_nova instead.

1 Like

One thing I noticed is that even if the script works just fine, when I look in the script editor it doesn’t like the

  - data: {}
service_template: >
  shell_command.{% if is_state("input_select.radio_station", "RixFM") %}radio_rixfm
  {%-elif is_state("input_select.radio_station", "Radio Nova") %}radio_nova
  {% endif %}

The text box in the editor says

Unsupported action
{
  "data": {},
  "service_template": "shell_command.{% if is_state(\"input_select.radio_station\", \"RixFM\") %}radio_rixfm {%-elif is_state(\"input_select.radio_station\", \"Radio Nova\") %}radio_nova {% endif %}\n"
}

Is this a common problem? Maybe the edit is still in a pre-mature state?

The script editor is still limited. Once you get the hang of it you probably won’t use it anymore.
Have fun :slight_smile: