Streams controlled by Alexa

are you planning on using 1 Alexa device to control all of them or are you trying to use 1 alexa device as the main “music hub”. This is how I did it. Just so you know the only real downfall is that there is about a 3-6 second lag depending on how you have it setup.

With either way you are going to need access to a media server:

  • If you are using a DOT you are going to use the line out function. I would get a splitter and have a small speaker there for regular use. One line will need to go to your media server “ICECAST2” You would essentially pipe the line out audio to ICECAST2 and it will turn it into a stream via .ogg or .mp3 and you can send this stream to any of your chromecast audio devices.

If you are going to control the Spotify playlist from your phone of from Logitech media server then all you will need is a streaming URL with an MP3 or OGG section.

so just to recap, to use home assistant with chromecast audio you NEED some type of streaming URL that is in an audio format (MP3 ,OGG, etc…) and then there are multiple ways to execute, but first see how you want to implement the url.

This is what I ended up with
https://community.home-assistant.io/t/need-help-chromecast-audio-media-center-plex-kodi/12361

or

https://community.home-assistant.io/t/different-way-to-get-chromecast-audio-cca-working-with-alexa-echo-and-ha/10652

1 Like

I don’t use Spotify, but this thread is possibly relevant…

What are you using instead Spotify? Maybe I can adapt it somehow… :slight_smile:

Radio stations and local mp3’s.

Can you give me please an example of configuration for 2 streams (localstreams)? I’am interested specifically in how I cast the stream to Chromecast…

I don’t understand what you mean by local streams, but my configuration is all on my GitHub. The package for the chromecast radio is probably the best example,which was adapted from this thread…

I tried different settings to setup a radio stream (http://80.86.106.143:9128/rockfm.aacp) for 1 chromecast but the HomeAssistant is crashing. Can you please help me with the configuration for this radio stream?

My chromecast entity_id is codis_chromecast and I want to create a stream called ‘Rock Stream’.

This is my configuration.yaml, and the HASS is down… it can’t be accessed anymore.

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:

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
      - Bedroom
      - Everywhere
    initial: Everywhere
    icon: mdi:speaker-wireless

script:
        radio538:
        alias: Play Radio on Chromecast Audio
        sequence:
          - service: media_player.volume_set
                data:
                  entity_id: media_player.codis_chromecast
                  volume_level: '0.35'
          -  service: media_player.play_media
                 data_template:
                   entity_id: >
                        {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.codis_chromecast
                        {% endif %}
                   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

Thanks!

I think your spacing is off.

1 Like

^ what he said, spacing on the script is way out.

Plus you need to ensure that you have the relevant automations in your automations.yaml file.

Hope this helps.

What should I have in automation.yaml? Now is empty… just ‘[]’.

You need an automation that triggers when the input_select is selected, that fires the script.

You may also need one that changes volume, depending on how you’re setting up your player.

Thanks for your reply. I have intended properly the code in this section. But I still have an error:

Error : A YAML file cannot contain tabs as indentation.
Line : 106 sequence:

script:
  radio538:
    alias: Play Radio on Chromecast Audio
	sequence:
	  - service: media_player.volume_set
		  data:
		    entity_id: media_player.codis_chromecast
			volume_level: '0.35'
	  -  service: media_player.play_media
		   data_template:
		     entity_id: >
			  {% if is_state("input_select.chromecast_radio", "Livingroom") %} media_player.codis_chromecast
			  {% endif %}
			 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 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?