Input Select triggering automation/shell command

I am trying to setup a stereo receiver to run my whole home stereo system and would like to use the FM source, but have the users select the station from a drop-down list.

I have the input select added to my configuration.yaml file as well as created a “shell_commands.yaml” file and included it into the configuration file.

I can send the shell commands manually from the console, so I know they’re functioning. if I create a button on the lovelace UI and set it to call service and point it to any of the shell commands, I can make the receiver change to AM/FM/station of choice etc. But when I change the input select drop down menu, it doesn’t execute the shell_command. I see the state change and automation trigger show up in the logbook… but the receiver doesn’t respond, so the shell command clearly didn’t execute. What am I missing? I have been trying to google and follow other snippets, and I thought I had it working the other day but only had one entry in the input_select. now that there is a bunch, i can’t get it to work again.
The pic below shows the card i’ve creatd. the FM and AM buttons both work by calling for a shell command.

fmradio

configration.yaml

input_select:
  radio_station:  #used to select whole home stereo's radio station
    name: Radio Station
    options:
      - ""
      - "94.5 Virgin Radio"
      - "95.3 Z95.3"
      - "96.9 JackFM"
      - "97.7 Ici Radio-Canada Première"
      - "99.3 The FOX"
      - "101.1 Rock 101"
      - "102.7 The Peak FM"
      - "103.5 Move"
      - "105.7 CBC"
    icon: mdi:radio
    initial: ""

shell_command: !include shell_commands.yaml

shell_commands.yaml

#shell commands for assisting automations and other functions

  z2radio_off: onkyo --host 192.168.0.24 ZPW00
  z2radio_945: onkyo --host 192.168.0.24 TUZ09450
  z2radio_953: onkyo --host 192.168.0.24 TUZ09530
  z2radio_969: onkyo --host 192.168.0.24 TUZ09690
  z2radio_977: onkyo --host 192.168.0.24 TUZ09770
  z2radio_993: onkyo --host 192.168.0.24 TUZ09930
  z2radio_1011: onkyo --host 192.168.0.24 TUZ10110
  z2radio_1027: onkyo --host 192.168.0.24 TUZ10270
  z2radio_1035: onkyo --host 192.168.0.24 TUZ10350
  z2radio_1057: onkyo --host 192.168.0.24 TUZ10570

  z2radio_source_fm: onkyo --host 192.168.0.24 SLZ24
  z2radio_source_am: onkyo --host 192.168.0.24 SLZ25
  z2radio_source_bluetooth: onkyo --host 192.168.0.24 SLZ2E
  z2radio_power_on: onkyo --host 192.168.0.24 ZPW01
  z2radio_power_off: onkyo --host 192.168.0.24 ZPW00

and my automations.yaml entry

- id: '44545'
  alias: Change Radio Station
  description: Change radio station based on dropdown menu selection
  trigger:
    platform: state
    entity_id: input_select.radio_station
  action:
    service: >
      {% if is_state("input_select.radio_station", "94.5 Virgin Radio") %}
        shell_command: z2radio_945
      {% elif is_state("input_select.radio_station", "95.3 Z95.3") %}
        shell_command: z2radio_953
      {% elif is_state("input_select.radio_station", "96.9 JackFM") %}
        shell_command: z2radio_969
      {% elif is_state("input_select.radio_station", "97.7 Ici Radio-Canada Première") %}
        shell_command: z2radio_977
      {% elif is_state("input_select.radio_station", "99.3 The FOX") %}
        shell_command: z2radio_993
      {% elif is_state("input_select.radio_station", "101.1 Rock 101") %}
        shell_command: z2radio_1011
      {% elif is_state("input_select.radio_station", "102.7 The Peak FM") %}
        shell_command: z2radio_1027
      {% elif is_state("input_select.radio_station", "103.5 Move") %}
        shell_command: z2radio_1035
      {% elif is_state("input_select.radio_station", "105.7 CBC Music") %}
        shell_command: z2radio_1057
      {% endif %}

Any help is appreciated.

Ignore my first post if it’s still showing, I used the wrong syntax…

- id: '44545'
  alias: Change Radio Station
  description: Change radio station based on dropdown menu selection
  trigger:
    platform: state
    entity_id: input_select.radio_station
  action:
    service: >
      {% if is_state("input_select.radio_station", "94.5 Virgin Radio") %} shell_command.z2radio_945
      {% elif is_state("input_select.radio_station", "95.3 Z95.3") %} shell_command.z2radio_953
      {% elif is_state("input_select.radio_station", "96.9 JackFM") %} shell_command.z2radio_969
      {% elif is_state("input_select.radio_station", "97.7 Ici Radio-Canada Première") %} shell_command.z2radio_977
      {% elif is_state("input_select.radio_station", "99.3 The FOX") %} shell_command.z2radio_993
      {% elif is_state("input_select.radio_station", "101.1 Rock 101") %} shell_command.z2radio_1011
      {% elif is_state("input_select.radio_station", "102.7 The Peak FM") %} shell_command.z2radio_1027
      {% elif is_state("input_select.radio_station", "103.5 Move") %} shell_command.z2radio_1035
      {% elif is_state("input_select.radio_station", "105.7 CBC Music") %} shell_command.z2radio_1057
      {% endif %}

You needed a dot, but you had a colon and a space.

1 Like

Thank you! That’s working.

I had actually caught the “:” vs “.” thing on my own after posting, but for some reason it still seemed be to not working.

I notice you condensed the entries into single lines, instead of the way I had it laid out like:

{% if %}
  shell_command
{% elif %}

Is there a reason that format wouldn’t work (assuming i had the actual syntax correct)?? I do like your method better (looks cleaner) but would like to know for personal growth.

Thank you again! I had lost several hours on this already.

1 Like

No, it should have worked having them on a separate line, it’s just a matter of personal taste.

The reason I prefer to have them on one line for the the template and it’s output (in a case like this) is because then I can look at each line and immediately spot an error if something looks out of place because if all the lines should look almost identical, and one is a clear odd one out, then that’s probably where the error is. Like if you’d misspelled the entity_id of the input_select on one line, it would stand out like a sore thumb sandwiched between the correct spellings my way, but your way there’s a gap between each one and it wouldn’t jump out at me.

By the same reasoning if I have a really long template with loads of ands and ors in it I will probably put each part on its own line with the and/or on the end of the line, just makes it easier to pick out which part of the template is relevant to each operator.

Anyway, in summary, your layout should have been fine, I changed it to my layout just to make it easier for me to error-check as I went through it :slightly_smiling_face:

I think I’ll go with your method going forward. Already tried it with another automation and like it better.

Thanks again!

1 Like