Chromecast Radio with station and player selection

Try it with brackets Dave - not sure it will make a difference tho’
{{ (states.media_player.lounge_amp.attributes.volume_level | float) - 0.05 }}

I just tried it but it makes no difference unfortunately

The + = clockwise and the - = anticlockwise in other words the cube generates a +ve number for clockwise and a -ve number for anticlockwise. So as it stands because the check is for > 0 then it’s generating a vol up for clockwise and vice versa. You may find that you need to change it to +/- 0.1 rather than 0.05, depends what the state table says, mine goes from 0 to 100% in steps of 10 but in HA it goes from 0.0 to 1 therefore I step it in 0.1 incements.

1 Like

What media platform are you using? Take a look at your entity attributes while playing audio to find out the naming and steps for the volume level.

I’m using the broadlink custom component to control the amplifier

so would there be a way I can extract the >0 / <0 data from the cube to send a volume up / volume down command, rather than an increment to the volume attribute?

Yep the component just sends a broadlink vol up/down packet and does not use an attribute, just do a vol up/down, so maybe…

  volume_level: >
    {%if trigger.event.data.action_value | float > 0 %} 
        +1
    {% else %} 
        -1
    {% endif %}

or put whatever the command is, I’ve not looked at the component yet :stuck_out_tongue: well not in any detail anyway :stuck_out_tongue:

thanks for that. I tried your code but it didnt work so I also tried the below, same deal, not working :weary:

alias: Cube - Rotate
initial_state: 'on'
trigger:
  - platform: event
    event_type: cube_action
    event_data:
      entity_id: binary_sensor.cube_158d00010fd152
      action_type: rotate
action:
  - service: media_player.volume_set
    data_template:
      entity_id: media_player.lounge_amp
      volume_level: >
        {%if trigger.event.data.action_value | float > 0 %} 
            service: switch.turn_on
              entity_id: switch.amp_volume
        {% else %} 
            service: switch.turn_off
              entity_id: switch.amp_volume
        {% endif %}

The above wouldn’t work it would be something like…

action:
  - service: switch.turn_on    
    data_template:
        {%if trigger.event.data.action_value | float > 0 %} 
              entity_id: switch.amp_volume_up
        {% else %} 
              entity_id: switch.amp_volume_down <------------ or whatever you specified in the broadlink switches
        {% endif %}

I have my doubts about this as well, I would ask the author how to go about using the volume switches from his media_player.

in the broadlink switch setup there is just switch.amp_volume which gets turned on for volume up and off for volume down… I suppose I could modify it to have two entities with only an ON command

You could just use the already setup switches, you must have defined them to put them in the .ini files to start with.

try a service_template:

action:
  - service_template: >  
        {%if trigger.event.data.action_value | float > 0 %} 
             switch.turn_on
        {% else %} 
              switch.turn_off
        {% endif %}
    entity_id: switch.amp_volume
1 Like

The broadlink component doesnt have separate volume up and volume down commands though. It works likie switches with vol up being on and vol down being off. here is my .ini file for the amp

#switch:
  - platform: broadlink
    host: 192.168.0.71
    mac: '34:ea:34:xx:xx:xx'
    friendly_name: IR Transceiver
    type: rm_mini
    switches:
      onkyo_amp:
        friendly_name: "Amp Power"
        command_on:  'JgBMAAYABD8AASiSFBEUNRQRFBEUNRQRFDYUNRU1FBEUNhQ1FBEUNhQ1FBEUERQQFDYUERQQFBEUEBQRFDYUNRQRFDYUNRU1FDYUNhQADQUAAAAAAAAAAAAAAAA='
        command_off:  'JgBIAAABKJEUERQ2FBAUERQ2FBAUNhQ2FBAUERQ2FDUUERQ2FDYUEBQ2FDYUNRQRFBEUEBQ2FBEUEBQRFBAUNhQ2FDYUEBQ2FAANBQ=='
      onkyo_amp_cd:
        friendly_name: "Amp CD Input"
        command_on:  'JgBQAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUERM2FDYUERM2FDYUERM2FBEUERM2FBEUERMRFBEUEBQ2FDYUERM2FDYUNhQ2EwAE8gABKEkTAA0FAAAAAAAAAAA='
      onkyo_amp_v1:
        friendly_name: "Amp V1 Input"
        command_on:  'JgBIAAABKJEUERM2FBEUERM2FBEUNhM2FDYUERQ1FDYUERQ2EzYUERQ2EzYUNhQ2FBETERQRExEUERQRExEUERQ1FDYUNhQ2EwANBQ=='
      onkyo_amp_volume_up:
        friendly_name: "Amp Volume"
        command_on:  'JgBIAAABKIwaERM2FBEUERM2FBEUNhM2FDYUERM2FDYUERQ1FDYUERQQFDYUERQQFBEUERMRFBEUNhMRFDYUNhM2FDYUNhQ2EwANBQ=='
        command_off:  'JgBQAAkADMILAAzsAAEqkRQRFDYUEBQRFDYUEBQ2FDYUNRQRFDYUNhMRFDYUNhQQFDYUNhQQFBEUERQQFBEUEBQRFBEUNRQ2FDYUNhQ1FDYUAA0FAAAAAAAAAAA='
      onkyo_amp_mute:
        friendly_name: "Amp Mute"
        command_on:  'JgBIAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUEBQ2FDYUERM2FDYUERQ1FBEUNhQQFBEUERMRFBEUEBQ2FBEUNRQ2FDYUNhQ1FAANBQ=='
        command_off:  'JgBIAAABKJIUEBQ2FBEUEBQ2FBETNhQ2FDYUEBQ2FDYUERM2FDYUERQ1FBEUNhQQFBEUERMRFBEUEBQ2FBEUNRQ2FDYUNhQ1FAANBQ=='

So I’m thinking I should change the volume to be 2 separate entities with only an ON command for each

onkyo_amp_volume_up:
        friendly_name: "Amp Volume Up"
        command_on:  'JgBIAAABKIwaERM2FBEUERM2FBEUNhM2FDYUERM2FDYUERQ1FDYUERQQFDYUERQQFBEUERMRFBEUNhMRFDYUNhM2FDYUNhQ2EwANBQ=='

onkyo_amp_volume_down:
        friendly_name: "Amp Volume Down"
        command_on: 'JgBQAAkADMILAAzsAAEqkRQRFDYUEBQRFDYUEBQ2FDYUNRQRFDYUNhMRFDYUNhQQFDYUNhQQFBEUERQQFBEUEBQRFBEUNRQ2FDYUNhQ1FDYUAA0FAAAAAAAAAAA='

action:
  - service: switch.turn_on    
    data_template: >
        {%if trigger.event.data.action_value | float > 0 %} 
              entity_id: switch.onkyo_amp_volume_up
        {% else %} 
              entity_id: switch.onkyo_amp_volume_down
        {% endif %}

I think that would work fine :slight_smile:

I just tried this and it works!!! thank you so much. you are a legend :sunglasses:

2 Likes

thats definitely another option I might try if I decide I want to separate the vol up and down commands. Cheers for the help

1 Like

I cant seem to get the radio player to work. I have put everything in a package as per below. It shows up in the frontend and seems to fire the command if I hit activate, but nothing happens. no errors in the log. any ideas?

chromecast_radio.yaml (inside packages folder)

group:
  radio:
    name: Radio
    entities:
    - input_select.radio_station
    - input_select.chromecast_radio
    - script.radio
    - input_number.volume_radio

input_select:
  radio_station:
    name: 'Select Radio Station:'
    options:
      - Hit 92-9
      - Nova 93-7
      - Mix 94-5
      - 96FM
      - 80's
      - OldSkool Hits
      - Raw FM (dance)
      - 181FM Power (Todays Hits)
      - 181FM 90's Dance
      - 181FM Star 90's
      - 181FM The Breeze
      - Heat Radio (RnB)
      - Fresh 92-7
      - DI Chill & Tropical House
      - DI Disco House
      - DI Liquid D&B
    initial: Raw FM (dance)
    icon: mdi:radio
    
  chromecast_radio:
    name: 'Select Speakers:'
    options:
      - Lounge
      - Bedroom
      - House
    initial: Lounge
    icon: mdi:speaker-wireless

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

automation:
  - alias: Listen Radio
    hide_entity: True
    trigger:
      - platform: state
        entity_id: input_select.radio_station
    action: 
      - service: script.radio
  - alias: Set Chromecast Radio Volume
    trigger:
      platform: state
      entity_id: input_number.volume_radio
    action:
      service: media_player.volume_set
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
          {% endif %}
        volume_level: '{{  states.input_number.volume_radio.state  }}'

script:
  radio:
    alias: Play Radio on Chromecast Audio
    sequence:
    - service: media_player.volume_set
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
          {% endif %}
        volume_level: '{{  states.input_number.volume_radio.state  }}' 
    - service: media_player.play_media
      data_template:
        entity_id: >
          {% if is_state("input_select.chromecast_radio", "Lounge") %} media_player.lounge
          {% elif is_state("input_select.chromecast_radio", "Bedroom") %} media_player.bedroom
          {% elif is_state("input_select.chromecast_radio", "House") %} media_player.house_group
          {% endif %}
        media_content_id: >
          {% if is_state("input_select.radio_station", "Hit 92-9") %} http://sc01.scahw.com.au/6ppm_32
          {% elif is_state("input_select.radio_station", "Nova 93-7") %} http://streaming.novaentertainment.com.au/nova937
          {% elif is_state("input_select.radio_station", "Mix 94-5") %} http://sc01.scahw.com.au/6mix_32
          {% elif is_state("input_select.radio_station", "96FM") %} https://icy.ihrcast.arn.com.au/au_012_icy
          {% elif is_state("input_select.radio_station", "80's") %} http://streaming.the80s.com.au/;stream/1
          {% elif is_state("input_select.radio_station", "OldSkool Hits") %} http://sc01.scahw.com.au/loveland_32
          {% elif is_state("input_select.radio_station", "Raw FM (dance)") %} http://stream.rawfm.com.au:8000/;stream.nsv
          {% elif is_state("input_select.radio_station", "181FM Power (Todays Hits)") %} http://listen.181fm.com/181-power_128k.mp3?
          {% elif is_state("input_select.radio_station", "181FM 90's Dance") %} http://listen.181fm.com/181-90sdance_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM Star 90's") %} http://listen.181fm.com/181-star90s_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM The Breeze") %} http://listen.181fm.com/181-breeze_128k.mp3
          {% elif is_state("input_select.radio_station", "Heat Radio (RnB)") %} http://174.37.159.206:8106/stream
          {% elif is_state("input_select.radio_station", "Fresh 92-7") %} http://live.fresh927.com.au/freshmp3
          {% elif is_state("input_select.radio_station", "DI Chill & Tropical House") %} http://pub1.diforfree.org:8000/di_chillntropicalhouse_hi
          {% elif is_state("input_select.radio_station", "DI Disco House") %} http://pub1.diforfree.org:8000/di_discohouse_hi
          {% elif is_state("input_select.radio_station", "DI Liquid D&B") %} http://pub1.diforfree.org:8000/di_liquiddnb_hi
          {% endif %}
        media_content_type: 'audio/mp4'

image

Did you try all stations?
These stations have a bad link and will not work:

          {% if is_state("input_select.radio_station", "Hit 92-9") %} http://sc01.scahw.com.au/6ppm_32
          {% elif is_state("input_select.radio_station", "Nova 93-7") %} http://streaming.novaentertainment.com.au/nova937
          {% elif is_state("input_select.radio_station", "Mix 94-5") %} http://sc01.scahw.com.au/6mix_32
          {% elif is_state("input_select.radio_station", "96FM") %} https://icy.ihrcast.arn.com.au/au_012_icy
          {% elif is_state("input_select.radio_station", "80's") %} http://streaming.the80s.com.au/;stream/1
          {% elif is_state("input_select.radio_station", "OldSkool Hits") %} http://sc01.scahw.com.au/loveland_32
          {% elif is_state("input_select.radio_station", "Raw FM (dance)") %} http://stream.rawfm.com.au:8000/;stream.nsv

These seem fine:

          {% elif is_state("input_select.radio_station", "181FM Power (Todays Hits)") %} http://listen.181fm.com/181-power_128k.mp3?
          {% elif is_state("input_select.radio_station", "181FM 90's Dance") %} http://listen.181fm.com/181-90sdance_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM Star 90's") %} http://listen.181fm.com/181-star90s_128k.mp3
          {% elif is_state("input_select.radio_station", "181FM The Breeze") %} http://listen.181fm.com/181-breeze_128k.mp3
          {% elif is_state("input_select.radio_station", "Heat Radio (RnB)") %} http://174.37.159.206:8106/stream
          {% elif is_state("input_select.radio_station", "Fresh 92-7") %} http://live.fresh927.com.au/freshmp3
          {% elif is_state("input_select.radio_station", "DI Chill & Tropical House") %} http://pub1.diforfree.org:8000/di_chillntropicalhouse_hi
          {% elif is_state("input_select.radio_station", "DI Disco House") %} http://pub1.diforfree.org:8000/di_discohouse_hi
          {% elif is_state("input_select.radio_station", "DI Liquid D&B") %} http://pub1.diforfree.org:8000/di_liquiddnb_hi

You can check if you are using the right link by opening it in your browser, it should start playing immediately without having to press a play button.

I’ve tried a lot of them, not all. But I just tried some of the ones that you mentioned have good links, still no joy

What kind of media platform are you using?