Streams controlled by Alexa

Hello,

I want to integrate somehow Alexa with Chromecast Audio through HomeAssistant.

I have 2 Chromecast Audio and my idea is to create 2 separate streams for each Chromecast (local stream or Spotify if is possible). And get them controlled by Alexa (commands like ‘Alexa, turn on X stream’, ‘Alexa, turn off Y stream’).

Can you please tell me if there is any possibility to do this and how?

Thank you,
Claudiu L.

The best way I know of to send commands to HA from Alexa is to use IFTTT and webhooks. I hope that someone else knows of a better way because I use this method and I don’t like having to rely upon a third party service (beyond Alexa in this case).

As for controlling streams on Chromecast through HA, I don’t know much about that unfortunately but I’m also interested to learn as I have two Chromecasts at home.

Edit: I’ll also add that sending commands to HA through IFTT on Alexa requires the use of the word “trigger” in addition to your command. For instance: “Alexa, trigger TV on.”

Hello @patosullivan,

Thank you for your reply. I do not know how IFTTT works for HA and Alexa. But from what I searched on Internet, there is a tutorial who explains how to create a sort of skill for Alexa to integrate with HomeAssistant:

I did not create this skill yet, but I plan to. Until this I’m trying to find out if it is possible and how to create separate streams for each Chromecast Audio.

Thank you!
Claudiu

I think it is all going to depend on your original source for your stream. Are you going to use something external like Logitech Media server or are you trying to use the Built in Alexa Spotify?

Either can work But they both have advantages/disadvantages

Here’s an easier way:

There is an existing Alexa service on IFTTT that you can use as your “If this”. Just select “Say a specific phrase”. You must have the IFTTT skill enabled on your Alexa for this to work.

You can then use the Webhooks service to trigger whatever it is you want to do in HA. You just pass it through a URL.

Here’s some more documentation on this: https://home-assistant.io/components/ifttt/

It’s a bit outdated (maybe I can figure out how to edit it and update it sometime this week). Just know that the “maker” service no longer exists, it’s now split into two different services, one of which is Webhooks.

Edit: I should also note that you need to be able to securely access your HA server remotely for this to work.

My first choice is Built in Alexa Spotify… but there is no possibility, I can choose local stream, Logitech Media Server or Plex… I also read something about PiMusicBox (Mopidy).

How can I do this? Do you have any idea?

I’m totally knackered so I may have totally misunderstood what you’re asking, so I won’t be offended if you tell me to shut up…

8 steps of happiness :

  • Create an input_boolean called ‘stream X’
  • Create an input_boolean called ‘stream Y’
  • Create an automation that triggers when stream X is switched on, action to play the stream on the CC
  • Create an automation that triggers when stream Y is switched on, action to play the stream on the CC
  • Create an automation that triggers when stream X is switched off, action to stop the stream
  • Create an automation that triggers when stream Y is switched off, action to stop the stream
  • Expose input booleans to emulated hue.
  • Profit

Yes. That’s what I wanted but how I can stream Spotify on CC? Can you help me with a script example or something?

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'