Chromecast Radio with station and player selection

@lolouk44 experienceing a hiccup here,

things go right until this:

      - condition: template
        value_template: >
          {{is_state('input_boolean.radio_paused','on')}}
      - wait_template: >
          {{states(states('sensor.intercom')) != 'playing'}}
      - service: script.play_radio
      - service: input_boolean.turn_off
        entity_id: input_boolean.radio_paused

even though both value_templates evaluate to True, the script won’t continue, and script.play_radio isn’t executed as isn’t the following input_boolean_turn_off …

could it be that some of your script or automation goes too fast?
or could it be that one or both conditions in your radio_paused_for_message pause are not true the exact time the script is called and therefore the input_boolean.radio_paused is not turned on which then stops the automation?

I am not sure, what is wrong, but replacing the wait template with delay: seconds 20 makes it all work again.

So it must be either the wait_template itself behaving unexpectedly, or other timing issues.

fact remains that when I checked both the wait_template and the condition_template were True, and the script didn’t advance… Must indicate the wait_template doesn’t release the rest of the actions…

radio_paused is turned-on correctly (I have it in my front-end and can simply check that.) It is neer turned off though ;-(

I just tried with your first url (http://icecast.omroep.nl/radio1-bb-mp3) and its also starting instantly. Any idea why the radio stations I’m using are having this delay?


http://dg-ais-eco-http-fra-eco-cdn.cast.addradio.de/ps-radiob2gold/livestream.mp3

it depends on where the streaming server is located, where you are located, and the streaming server itself. I have one streaming that sometimes takes over a minute to buffer

Thanks for your answer!
Strange thing is: If I start the stream on my Google Home via voice it starts within 1-2 seconds. The same stream (url extracted from tunein) needs around 10-15 seconds when using play.media :thinking:

not sure, but @lolouk44 is right probably :wink:

btw, if I click that link, it starts immediately. Not sure if my browser prefetches those though. could be…

yeah, if I open the sam elink from my pc it starts inmediatly, too! Thats the second weird thing.

not sure if those TuneIn streams are optimized for other use than TuneIn…

maybe have a look here http://hendrikjansen.nl/henk/streaming.html and see if the ones your looking for are there?

1 Like

Ik have the same issue with one of my “lullaby sleep automation” streams. It starts playing instantly on Chrome browser but it takes around 45 seconds to start on Google Home triggered with Hass (which is really annoying when you’re lying in bed ready to sleep :)).

1 Like

Okay, so I’ll have to accept this!

Hey Bob!,

which streams are those? Using the same streams setup still for my wakeup and sleep stations, and obviously that’s not a good idea. I forgot about that, until I tested the sleep radio last night and got an angry wife response over the intercom… was still set to Slamfm ;-))

1 Like

How would I reach the attributes?

I need to set the volume of an encapsulated media player… {{states(‘sensor.sleep_radio’)}}

would this be correct: {{state_attr(states('sensor.sleep_radio'),'volume_level')}}?

Looks about right. Why don’t you try and and report back :blush:

lol, of course that’s what I have done:

  play_wakeup_radio:
    alias: Play wakeup radio
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {{states('sensor.wakeup_radio')}}
          volume_level: '0.01'
      - service: media_player.play_media
        data_template:
          entity_id: >
            {{states('sensor.wakeup_radio')}}
          media_content_id: >
            {{states('sensor.radio_station_wake_up')}}
          media_content_type: 'audio/mp4'

no errors, but the volume doesn’t get set…

these work:

      wakeup_radio_volume:
        friendly_name: Wakeup radio volume
        value_template: >
          {{state_attr(states('sensor.wakeup_radio'),'volume_level')|float|round(2) }}

      sleep_radio_volume:
        friendly_name: Sleep radio volume
        value_template: >
          {{state_attr(states('sensor.sleep_radio'),'volume_level')|float|round(2) }}

seems the initial setting works but the loop won’t do it correctly:

  - alias: 'Increase volume loop'
    id: 'Increase volume loop'
    initial_state: 'off'
    trigger:
      platform: event
      event_type: timer.finished
      event_data:
        entity_id: timer.increase_volume_delay
    condition:
      - condition: template
        value_template: >
          {{is_state('input_boolean.snooze','on')}}
      - condition: template
        value_template: >
          {{states('sensor.wakeup_radio_volume')|float < 1 }}
    action:
      - service: script.increase_volume_delay
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {{states('sensor.wakeup_radio')}}
          volume_level: >
            {% set level = 
               states('sensor.wakeup_radio_volume')|float + 
               states('input_number.increase_volume')|float %}
            {% if level < 1 %} {{ level|round(2) }}
            {% else %} 1
            {% endif %}

just one more, was a bit of a struggle, but finally it dawned on me the encapsulated volume sensor didn’t get updated. It needed the entity_ids of the individual sensors (which are all templated sensors them selves) and most of all the timer…

this seems to do the trick:

      sleep_radio_volume:
        friendly_name: Sleep radio volume
        entity_id:
          - sensor.sleep_radio
          - sensor.sleep_radio_state
          - sensor.sleep_radio_volume
          - timer.decrease_volume_delay
        value_template: >
          {{state_attr(states('sensor.sleep_radio'),'volume_level')|float|round(2) }}

and the same for the wakeup volume of course.

I included the link in my post :wink:

Really? Can’t see that, when I click the link I only see a Mediaplayer playing a scary tune…:wink:

This is realy working well, got only one little problem.

When i play the radio it just sometimes stops playing, why is this happening?
Is it a bad internet connection, or a bad mediaplayer?
When i hit play again when it stops it immediatly begins to play again…

Is it possible to automate this?
When the music stops automatic hit play again?

Hello guys,

this is my setup.

Below screenshot is from Tileboard which I am using as wall mount HA control panel.

image

Config:
4 input_booleans for station selection
media player - chromecast mini

Automation - this will turn on/off radio and switch between stations

- id: "Radio_manual"
  alias: "Radio Manual"
  initial_state: true 
  trigger:
    - platform: state
      entity_id: input_boolean.station_1, input_boolean.station_2, input_boolean.station_3, input_boolean.station_4
      to: 'on'
  condition:
    - condition: template
      value_template: '{{ states | selectattr("entity_id","in", ["input_boolean.station_1", "input_boolean.station_2", "input_boolean.station_3", "input_boolean.station_4"] ) |selectattr("state","eq","on") | list | count | int > 1}}'
  action:
    - service: input_boolean.turn_off
      data_template:
        entity_id: >
          {% for state in states.input_boolean if state.state == 'on' and 'station' in state.entity_id %}
            {% if trigger.entity_id.split('_')[2] != state.entity_id.split('_')[2] %}
              {{state.entity_id}}
            {% endif %}
          {% endfor %}   
    - service: script.turn_on
      data_template:
        entity_id: script.radio_live

- id: "Radio_manual_1"
  alias: "Radio Manual 1"
  initial_state: true 
  trigger:
    - platform: state
      entity_id: input_boolean.station_1, input_boolean.station_2, input_boolean.station_3, input_boolean.station_4
      to: 'off'
  action:
    - service: media_player.turn_off
      data_template:
        entity_id: media_player.chormecast_id 

- id: "Radio_manual_2"
  alias: "Radio Manual 2"
  initial_state: true 
  trigger:
    - platform: state
      entity_id: input_boolean.station_1, input_boolean.station_2, input_boolean.station_3, input_boolean.station_4
      to: 'on'
  condition:
    - condition: template
      value_template: '{{ states | selectattr("entity_id","in", ["input_boolean.station_1", "input_boolean.station_2", "input_boolean.station_3", "input_boolean.station_4"] ) |selectattr("state","eq","on") | list | count | int == 1}}'
  action:
    - service: script.turn_on
      data_template:
        entity_id: script.radio_live

script to turn on radio BTW, this script also takes care of suppressing start beep

 radio_live:
  alias: "Radio live"
  sequence:
    # lowers volume so you do not hear the startup sound
    -  service: media_player.volume_set
       data_template:
         entity_id: media_player.chormecast_id
         volume_level: 0.01
    # turn off Google Home - I had to do this or else I would hear the starting sound if Google Home wasn't "off" when the turn on step runs
    -  service: media_player.turn_off
       data_template:
         entity_id: media_player.chormecast_id
    # wait 1 second before turning on Google Home
    -  delay: 00:00:01
    # turn on Google Home
    -  service: media_player.turn_on
       data_template:
         entity_id: media_player.chormecast_id
    # wait 1 seconds so you don't hear the startup sound
    -  delay: 00:00:01
    # set volume to desired level
    -  service: media_player.volume_set
       data_template:
         entity_id: media_player.chormecast_id
         volume_level: 0.30
    # wait 1 second
    -  delay: 00:00:01
    -  service: media_player.play_media
       data_template:
        entity_id: media_player.chormecast_id
        media_content_id: >
          {% if is_state("input_boolean.station_1", "on") %} http://us3.internet-radio.com:8250/live
          {% elif is_state("input_boolean.station_2", "on") %} http://fmout.spicefm.in:8000/spice_b
          {% elif is_state("input_boolean.station_3", "on") %} http://51.15.208.163:8081/radio/Mirchi_love_telugu/icecast.audio
          {% elif is_state("input_boolean.station_4", "on") %} http://51.15.208.163:8081/radio/MirchiTopTucker/icecast.audio
          {% endif %}
        media_content_type: 'music'
1 Like