#ScriptsAutomation - Play music on device

3 messages · Page 1 of 1 (latest)

tired bloom
#

I have a HA Scription which looks at a "device" item and a "station" item and tells them to play.

service: media_player.play_media
data:
  entity_id: |-
    {% if is_state("input_select.cast_radio", "JBL") %} 
      media_player.jbl 
    {% elif is_state("input_select.cast_radio", "Office") %} 
      media_player.jbl_link_portable_42f7
    {% elif is_state("input_select.cast_radio", "Clock") %} 
      media_player.clock 
    {% elif is_state("input_select.cast_radio", "Dining Room") %}
      media_player.dining_room_speaker 
    {% elif is_state("input_select.cast_radio","Playroom") %} 
      media_player.playroom 
    {% elif is_state("input_select.cast_radio", "Garage") %}
      media_player.dining_room_speaker 
    {% elif is_state("input_select.cast_radio",    "Alle Speakers") %} 
      media_player.media_group {% endif %}
  media_content_id: >-
    {% if is_state("input_select.radio_station", "ZM") %}
    https://i.mjh.nz/radio-ih-6190 {% elif
    is_state("input_select.radio_station", "Punk") %}
    spotify:playlist:2SK4Xyo9tEDwmE8IEUIU8H?si=c801b5a0a98c4ff7 {% elif
    is_state("input_select.radio_station", "The Breeze") %}
     http://tunein-icecast.mediaworks.nz/breeze_wellington_128kbps
    {% endif %}
  media_content_type: music
  extra:
    title: "{% if is_state(\"input_select.radio_station\", \"ZM\") %} ZM {% endif %}"

But it seems inelegant to have it in this format. Is there some sort of file, or dictionary type item that I could create a map of :

  • device, name for the devices (although I should be able to get the device and internal names for these.
  • the station "name" and it's urls. Where a url could be a streaming url or a spotify url
#

Actually, Ideally whatever "mapping" thing can be uses, would be able to populate the helpers for devices and stations

wind ore
#

Sure, just use a dictionary.

{% set media_players = {'Office': 'media_player.jbl_link_portable_42f7', 'JBL': 'media_player.jbl', ...} %}
{% set radio_stations = {'ZM;: 'https://...', 'Punk': 'spotify:...', ...} %}