Automation with Input Select and Scripts

Hi there,

i´m new to HA and i installed HASS.IO on my Pi3.

Unfortunately i´m not a gifted Guy when it comes to coding, but at least i try :slight_smile:

I want to setup an Input select für my Radio. Its a second Pi with RuneAudio on it and i want to control it with HTTP.

So i setup the Shell commands in my configuration.yaml

  play: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=play"
  stop: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=stop"
  lauter: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=volume +2"
  leiser: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=volume -2"
  clear: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=clear"
  abay: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=load AntenneBayern"
  rocka: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=load RockAntenne"
  bay1: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=load Bayern1"
  bay3: curl --silent -k "http://runeaudio.hoff.lan/command/?cmd=load Bayern3"

Each command is tested and it works.

Later i started to create the scripts in the scripts.yaml:

 play:
    sequence:
      - service: shell_command.play
      
  stop:
    sequence:
      - service: shell_command.stop

And so on…

I tested the script in the “services” with

Service: script.turn_on
{"entity_id":"script.play"}

And this is my automation.yaml

   - action:
      - service: script.turn_on
        data:
          entity_id: >
           {% if is_state("input_select.radio", "Antenne Bayern") %}
                  script.abay
                {%-elif is_state("input_select.radio", "Rock Antenne") %}
                  script.rocka
                {%-elif is_state("input_select.radio", "Bayern 1") %}
                  script.bay1
                {%-elif is_state("input_select.radio", "Bayern 3") %}
                  script.bay3
                {%-elif is_state("input_select.radio", "Radio ausschalten") %}
                  script.stop
                {%-elif is_state("input_select.radio", "Reboot") %}
                  script.reboot
                {% else %}
                  none
                {% endif %}
      - service: input_select.select_option
        entity_id : input_select.radio
        data:
          option: Wähle einen Radiosender
      alias: Radiosender
      hide_entity: true
      trigger:
      - entity_id: input_select.radio
        platform: state
        from : Wähle einen Radiosender

The Input select should load the playlist at Runeaudio at first. After this is successful i will add the “play” in the sequence.

The Config Check will say there is an Error but there is no hint whats the problem. The YAML Check is also fine. But when i hit the input this entry will appear in my Log:

ERROR (MainThread) [homeassistant.core] Invalid service data for script.turn_on: Entity ID {% if is_state("input_select.radio" is an invalid entity id for dictionary value @ data['entity_id']. Got '{% if is_state("input_select.radio", "Antenne Bayern") %}\n script.abay\n {%-elif is_state("input_select.radio", "Rock Antenne") %}\n script.rocka\n {%-elif is_state("input_select.radio", "Bayern 1") %}\n script.bay1\n {%-elif is_state("input_select.radio", "Bayern 3") %}\n script.bay3\n {%-elif is_state("input_select.radio", "Radio ausschalten") %}\n script.stop\n {%-elif is_state("input_select.radio", "Reboot") %}\n script.reboot\n

Best regards and greetings from Germany

Here is my Input Select if thats important

input_select.yaml

  radio:
    name: Webradio
    options:
     - Wähle einen Radiosender
     - Antenne Bayern
     - Rock Antenne
     - Bayern 1
     - Bayern 3
     - Radio ausschalten
    initial: Wähle einen Radiosender
    icon: mdi:radio

You cannot declare an entity id, and then proceed to use a template.

As simple as that :smiley: Thank you so much.

- action:
  - service: script.turn_on
    data_template:
      entity_id: >
       {% if is_state("input_select.radio", "Antenne Bayern") %}
              script.abay