Streams controlled by Alexa

you need to use the spacebar and not use the tab button for all of the coding you do in home assistant

I recommend simplifying first, that case you can expand your script piece by piece and find out were it goes wrong.
If I understand correctly, you only have 1 Chromecast device? If yes, you can lose the if statement on the entity_id part.

Start with this:

script:
  radio538:
    alias: Play Radio on Chromecast Audio
    sequence:
      -  service: media_player.play_media
         data_template:
           entity_id: media_player.codis_chromecast
           media_content_id: >
             {% if is_state("input_select.radio_station", "Rock FM") %} http://80.86.106.143:9128/rockfm.aacp
             {% elif is_state("input_select.radio_station", "Radio ZU") %} http://77.81.25.2:9123/radiozu.aacp
             {% endif %}
           media_content_type: 'audio/mp4'

You did setup your input_select.radio_station correctly?

How do you execute your script? Manual through the frontend?

1 Like

Hi, many thanks for your help. Currently, I want to execute the script manually through the frontend, but I will want to create an automation to open the chromecast and start the stream.

Here is my setup for input_select:

input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
      - Rock FM
      - Radio ZU

chromecast_radio:
  name: 'Select Speakers:'
  options:
    - Livingroom
  initial: Everywhere
  icon: mdi:speaker-wireless

I used your code. Now using http://www.yamllint.com/ my configuration.yaml is valid. But the HASS dashboard still not works.

*My automation.yaml and groups.yaml are empty… maybe I am missing something. Should I add something in automation.yaml or groups.yaml?

Here’s my code:

homeassistant:
  # Name of the location where Home Assistant is running
  name: Home
  # Location required to calculate the time the sun rises and sets
  latitude: 45.6333
  longitude: 25.5833
  # Impacts weather/sunrise data (altitude above sea level in meters)
  elevation: 643
  # metric for Metric, imperial for Imperial
  unit_system: metric
  # Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
  time_zone: Europe/Bucharest
  customize:
    script.radio538:
      friendly_name: Start Playing
      icon: mdi:play

# Show links to resources in log and frontend
# introduction:

# Enables the frontend
frontend:

# Enables configuration UI
config:

http:
  # Uncomment this to add a password (recommended!)
  api_password: !secret
  # Uncomment this if you are using SSL or running in Docker etc
  base_url: !secret

# Checks for available updates
# Note: This component will send some information about your system to
# the developers to assist with development of Home Assistant.
# For more information, please see:
# https://home-assistant.io/blog/2016/10/25/explaining-the-updater/
updater:
  # Optional, allows Home Assistant developers to focus on popular components.
  # include_used_components: true

# Discover some devices automatically
discovery:

# Allows you to issue voice commands from the frontend in enabled browsers
conversation:

# Enables support for tracking state changes over time.
history:

# View all events in a logbook
logbook:

# Track the sun
sun:

#Groups#
group:
  Rock Radio:
    name: Rock Radio
    entities:
      - input_select.radio_station
      - input_select.chromecast_radio
      - script.radio538

# Weather Prediction
sensor:
  platform: yr

# Text to speech
tts:
  platform: google

#Media players  
media_player:
  - platform: spotify
    client_id: !secret
    client_secret: !secret
  - platform: kodi
    name: Kodi Media Player
    host: !secret
    username: !secret
    password: !secret
  - platform: plex
  - platform: cast

input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
      - Rock FM
      - Radio ZU

chromecast_radio:
  name: 'Select Speakers:'
  options:
    - Livingroom
  initial: Everywhere
  icon: mdi:speaker-wireless

script:
  radio538:
    alias: Play Radio on Chromecast Audio
    sequence:
      -  service: media_player.play_media
         data_template:
           entity_id: media_player.codis_chromecast
           media_content_id: >
             {% if is_state("input_select.radio_station", "Rock FM") %} http://80.86.106.143:9128/rockfm.aacp
             {% elif is_state("input_select.radio_station", "Radio ZU") %} http://77.81.25.2:9123/radiozu.aacp
             {% endif %}
           media_content_type: 'audio/mp4'

group: !include groups.yaml
automation: !include automations.yaml

Now is working, there was some mistakes in my code.

Is there any possiblity to create an automation when I turn on the chromecast to automatically start a default Radio Station? Currently is working only when I click on ‘Activate’ button.

1 Like

Hi Bob, sorry but I have a strange request :slight_smile:
I so Radio ZU in you source… do you have a working url of that radio please ?
Or can you tell me how to find it ?
Thanks a lot
Denis

That’s not a station from my original script, looks like @claudiul93 added it so perhaps he can help you with that.

What do you mean with “turning on the Chromecast”? If you have to turn it on anyway, what’s the difference between that and pressing the activate button?

Hi Clau :slight_smile:
do you have please the Radio ZU url… or maybe can you give me a link that
have it please ?
Thanks in advance