Perform Actions Based on Input Select


This example uses an input_select element to pick which mp3 file to play on a Chromecast.

# Define our dropdown list
input_select:
  lullaby:
    name: Lullaby
    options:
      - Rain
      - Babbling Brook
      - None
    initial: None
    icon: mdi:weather-rainy

# Define our media player
media_player:
    - platform: cast
      host: chromecast-nursery
      name: Nursery

automation:
  # If you select "Rain", play the "rain.mp3" file
  - alias: Play Rain Lullaby

    trigger:
      platform: state
      entity_id: input_select.lullaby
      to: "Rain"

    action:
      service: media_player.play_media
      data:
        entity_id: media_player.nursery
        media_id: http://fileserver/rain.mp3
        media_type: audio/mp4


  # If you select "Babbling Brook", play the "babbling_brook.mp3" file
  - alias: Play Babbling Brook Lullaby

    trigger:
      platform: state
      entity_id: input_select.lullaby
      to: "Babbling Brook"

    action:
      service: media_player.play_media
      data:
        entity_id: media_player.nursery
        media_id: http://fileserver/babbling_brook.mp3
        media_type: audio/mp4

  # If you select "None, turn the Chromecast off
  - alias: Stop the Lullaby

    trigger:
      platform: state
      entity_id: input_select.lullaby
      to: "None"

    action:
      service: media_player.turn_off
      data:
        entity_id: media_player.nursery