Chromecast Radio with station and player selection

Very nice indeed!

However, I’ve split my configuration.yaml so that all automations is in a separate directory, and I can’t figure out how to add this, I just get at bunch of errors no matter what I do.

I guess I would have to have one for file for each action, but even when I try to separate them and the first automation fails and throws a bunch of errors :frowning:

Any pro tips for a beginner?

What I’ve got:

In configuration.yaml:
automation: !include_dir_merge_list automation/

In the folder “automation”, I’ve got several files, one of them being “radio.yaml”:

- action:
  - service: media_player.volume_set
    data_template:
      entity_id: '{% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
        {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
        {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
        {% endif %}'
    volume_level: '{{ states.input_number.radio_volume.state | float }}'
  alias: Radio Volume
  condition: []
  id: radio_volume
  trigger:
  - entity_id: input_number.radio_volume
    platform: state

- action:
  - service: script.radio_start
  alias: Radio On
  condition: []
  id: radio_on
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'on'

- action:
  - service: script.radio_stop
  alias: Radio Off
  condition: []
  id: radio_off
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'off'

- action:
  - service: script.radio_start
  alias: Radio Channel Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_channel_change
  trigger:
  - entity_id: input_select.radio_station
    platform: state

- action:
  - service: script.radio_change_speakers
    data_template:
      previous_speakers: '{{ trigger.from_state.state }}'
  alias: Radio Speaker Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_speaker_change
  trigger:
  - entity_id: input_select.radio_speakers
    platform: state

Thanks a lot, one step in the right direction :slight_smile:

How ever, I got an error…

Invalid config for [automation]: [volume_level] is an invalid option for [automation]. Check: automation->action->0->volume_level. (See /config/configuration.yaml, line 93).

Any ideas?

You probably have an error with indentation: check your spaces and/or post the contents of your file for troubleshooting

I ran both my configuration.yaml and radio.yaml (which I copied from you), thru yamlint and they pass.

What do you want to see?

Probably the radio.yaml

Should be exactly the same…

- action:
  - service: media_player.volume_set
    data_template:
      entity_id: '{% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
        {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
        {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
        {% endif %}'
    volume_level: '{{ states.input_number.radio_volume.state | float }}'
  alias: Radio Volume
  condition: []
  id: radio_volume
  trigger:
  - entity_id: input_number.radio_volume
    platform: state

- action:
  - service: script.radio_start
  alias: Radio On
  condition: []
  id: radio_on
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'on'

- action:
  - service: script.radio_stop
  alias: Radio Off
  condition: []
  id: radio_off
  trigger:
  - entity_id: input_boolean.radio_play
    platform: state
    to: 'off'

- action:
  - service: script.radio_start
  alias: Radio Channel Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_channel_change
  trigger:
  - entity_id: input_select.radio_station
    platform: state

- action:
  - service: script.radio_change_speakers
    data_template:
      previous_speakers: '{{ trigger.from_state.state }}'
  alias: Radio Speaker Change
  condition:
  - condition: state
    entity_id: input_boolean.radio_play
    state: 'on'
  id: radio_speaker_change
  trigger:
  - entity_id: input_select.radio_speakers
    platform: state

Add 2 spaces before volume_level

- action:
  - service: media_player.volume_set
    data_template:
      entity_id: '{% if is_state("input_select.radio_speakers", "Livingroom") %} media_player.livingroom_speaker
        {% elif is_state("input_select.radio_speakers", "Kitchen") %} media_player.kitchen_speaker
        {% elif is_state("input_select.radio_speakers", "Everywhere") %} media_player.home_speakers
        {% endif %}'
      volume_level: '{{ states.input_number.radio_volume.state | float }}'
  alias: Radio Volume
  condition: []
  id: radio_volume
  trigger:
  - entity_id: input_number.radio_volume
    platform: state

Yep, indentation it was :wink:

Other Q: if I start the radio player via this system, and later I stop it via my Google Home (“Hey Google, stop my Chromecast”) the card isn’t updated and still shows as playing. Any idea to get the card updated when stopping radio via Home?

Thank you, thank you, thank you :slight_smile:

Very much appreciated!

1 Like

Try switching off the cast device instead of stopping. When stopping, it seems like it actually goes on pause (as you can press play again and it instantly resumes playing).

Could it be possible to add an option to send a notification with the title of the song played when casting to Chromecast? If yes, how?

Anybody know how to play a local playlist of mp3s? For instance, if you have 5 mp3s locally to hass, how do you stream them as a playlist?

There is a thread on this forum about using Mopidy and Icecast to play Spotify on Chromecast, from what I remember Mopidy can also play local files.

Edit: here is a good write-up https://www.vittoriomonaco.de/home-automation-part-7.html

1 Like

Very nice write up but I don’t have the music collection to justify the effort. I’m looking for a simpler method, somehow to queue local songs. Something easy like separating songs by ‘;’ or simply supporting an m3u file that points to all the songs locally?

 media_content_id: >
      {% if is_state('input_select.music_station', 'Playlist 1') %} http://song1.mp3; http://song2.mp3; http://song3.mp3

Well, the thing is that a Chromecast itself cannot play a file, only a digital stream, so you need to convert your file to a stream and then send it to the CC.

It seems as you can use the included webserver to convert the files and then cast them to the CC, check this one: Can't play local audio file to chromecast audio (link goes to solution, not question). It should at least serve as a starting point, I don’t know if it will work with an m3u file.

I just used an mp3 joiner and called it a day for now :slight_smile:

Has anybody used this successfully? media_player.media_seek to seek through an mp3? Ideally I would have an input_number as a slider. I wasn’t able to seek successfully.

    - service: media_player.media_seek
      data:
         entity_id: media_player.office_speaker
         seek_position: 50

retry code sample below

I don’t know what I’m doing wrong. I’ve been trying for 6 hours. (Thats me, a noob, new to .yaml and Hassio) I’ve never been able to get any part of this up and running. PS i have only one google chromecast.

I’ll post all codes im using below. Note: I have never been able to find a way to add the “input_slider:” part into my setup anywhere without Hassio config check failing or other errors.

###############Codes im using ##############
This part is in configuartion.yaml

    ####Selectors####
input_select: 
  radio_station: 
    name: 'Select Radio Station:' 
    options: 
      - Radio 538 
      - Q-Music 
      - 3FM 
      - 100% NL 
      - Veronica 
      - Sky Radio 
      - Arrow Classic Rock 
      - Classic FM 
      - BNR Nieuwsradio 
      - Smooth Jazz Tampa 
      - Classic Rock Florida 
      - Bob Sinclar Radio 
      - Chill Out Zone 
      - SLAM! Hardstyle 
      - Sleep Radio 
      - Ambient Sleeping Pill 
      - Radio Art - Sleep 
      - Ambi Nature Radio 
      - Calm Radio - Sleep 
      - Dinamo.FM Sleep

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

This part is in automation.yaml

  • alias: ‘Set Radio Volume’
    trigger:
    platform: state
    entity_id: input_slider.volume_radio
    action:
    service: media_player.volume_set
    data_template:
    entity_id: media_player.living_room
    volume_level: ‘{{ states.input_slider.volume_radio.state }}’

This part is in customize.yaml
script.radio538:
friendly_name: Start Playing
icon: mdi:play

This part is in groups.yaml
####Views####
media_view:
name: All Media
view: yes
entities:
- camera.logitech_usb_cam_1
- camera.win_ip_cam_1
- media_player.living_room
- group.residence_radio_group
####Groups####
residence_radio_group:
name: Internet Radio
entities:
- input_select.radio_station
- input_select.chromecast_radio
- script.radio538
- input_slider.volume_radio

This is in scripts.yaml
radio538:
alias: Play Radio on Chromecast Audio
sequence:

Have never been able to put this in anywhere…

input_slider: 
  volume_radio:
name: Volume
icon: mdi:volume-high
min: 0
max: 1
step: 0.05 

I have many other things configured and working
Below is complete configuration.yaml with secrets redacted.
#############Complete configuration.yaml###########
homeassistant:

Name of the location where Home Assistant is running

name: Home

Location required to calculate the time the sun rises and sets

latitude: -xx.xxxx
longitude: -xx.xxxx

Impacts weather/sunrise data (altitude above sea level in meters)

elevation: x

metric for Metric, imperial for Imperial

unit_system: imperial

Pick yours from here: http://en.wikipedia.org/wiki/List_of_tz_database_time_zones

time_zone: America/New_York

Customization file

customize: !include customize.yaml

Show links to resources in log and frontend (unComment the line below to show introduction)

introduction:

Enables the frontend

frontend:
themes: !include theme.yaml

Enables configuration UI

config:

http:

Secrets are defined in the file secrets.yaml

Uncomment this if you are using SSL/TLS, running in Docker container, etc.

base_url: https://xxxxx.xxxxxxx.xxx.xx.x.x.x.xxx.:xxxx
ssl_certificate: /ssl/fullchain.pem
ssl_key: /ssl/privkey.pem
api_password: !secret api_password

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:

Enables a map showing the location of tracked devices

map:

Track the sun

sun:

Platform systemmonitor displays CPU and Memory Usage Data , Platform darksky displays weather infromation.

sensor:

  • platform: systemmonitor
    resources:
    • type: disk_use_percent
      arg: /home
    • type: memory_free
    • type: load_1m
    • type: network_in
      arg: wlan0
    • type: network_out
      arg: wlan0
    • type: processor_use
    • type: since_last_boot
    • type: last_boot
  • platform: darksky #
    api_key: XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
    monitored_conditions:
    • summary
    • icon
    • nearest_storm_distance
    • daily_summary
    • precip_type
    • precip_intensity
    • precip_intensity_max
    • precip_probability
    • temperature
    • temperature_max
    • temperature_min
    • apparent_temperature
    • apparent_temperature_max
    • apparent_temperature_min
    • dew_point
    • wind_speed
    • wind_bearing
    • cloud_cover
    • humidity
    • pressure
    • visibility
    • minutely_summary
    • hourly_summary
    • uv_index
      update_interval: ‘00:30’

Text to speech

tts:

  • platform: google

Cloud

cloud:

Group

group: !include groups.yaml

Automation

automation: !include automations.yaml

Script

script: !include scripts.yaml

All Custom Component Add-ons & Codes Belong Below /THIS LINE/

Start of Custom Component Add-ons & Codes

Device Tracker via NMAP

device_tracker:

  • platform: nmap_tracker
    hosts:
    • xx.xx.x.xxx-199
    • xx.xx.x.xxx-170
      home_interval: 10
      exclude:
    • xx.xx.x.xxx-xxx

panel_iframe: !include panels.yaml

ifttt:
key: xxxxxxxxxxxxxxxxxxxxxxxxxx

camera:

  • platform: local_file
    name: logitech USB Cam 1
    file_path: /share/motion/lastsnap.jpg
  • platform: mjpeg
    name: Win IP Cam 1
    mjpeg_url: http://xx.xx.x.xxx:xxxx/mjpeg
    username: !secret winipcam1_username
    password: !secret winipcam1_password

switch:

  • platform: wake_on_lan
    mac_address: “xx-xx-xx-xx-xx-xx”

####Selectors####
input_select:
radio_station:
name: ‘Select Radio Station:’
options:
- Radio 538
- Q-Music
- 3FM
- 100% NL
- Veronica
- Sky Radio
- Arrow Classic Rock
- Classic FM
- BNR Nieuwsradio
- Smooth Jazz Tampa
- Classic Rock Florida
- Bob Sinclar Radio
- Chill Out Zone
- SLAM! Hardstyle
- Sleep Radio
- Ambient Sleeping Pill
- Radio Art - Sleep
- Ambi Nature Radio
- Calm Radio - Sleep
- Dinamo.FM Sleep

chromecast_radio:
name: ‘Select Speakers:’
options:
- Living_room
- Everywhere
initial: Living_room
icon: mdi:speaker-wireless