Internet radio on Google mini speaker

Hello Guys.
I tried to use my google mini speaker to integrate it with HA to play my favourite radio station. And I did it last days.
I decided to create switch button with the name of radio station and two icons dependant of playing status. It was working very well.
4
above radio station turned off
5
and also turned on.

to operate with volume I used the integration from HA
6

It was working very well, so I was decided to add another buttons with another stations
1

but I didn’t predict one thing - if I “turned on” any station all button has been changed, because my script shown status of media player not a stream which is currently played.

7

I would like to change it to “turn on” icon (yellow) --> only the station that is currently playing.

Could anybody help me with that?

my codes are shown below:

scripts.yaml

radio_357:
    alias: radio 357 w salonie
    sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.mojo
        media_content_id: 'https://stream.rcs.revma.com/ye5kghkgcm0uv'
        media_content_type: audio/mp3
antyradio:
    alias: antyradio w salonie
    sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.mojo
        media_content_id: 'http://ant-waw-01.cdn.eurozet.pl:8602/;'
        media_content_type: audio/mp3
meloradio:
    alias: meloradio w salonie
    sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.mojo
        media_content_id: 'https://n-4-9.dcs.redcdn.pl/sc/o2/Eurozet/live/meloradio.livx'
        media_content_type: audio/mp3
trojka:
    alias: trojka w salonie
    sequence:
    - service: media_player.play_media
      data:
        entity_id: media_player.mojo
        media_content_id: 'http://mp3.polskieradio.pl:8904/;'
        media_content_type: audio/mp3

switches.yaml

#virtual switches
  - platform: template
    switches:
      radio357:
        friendly_name: "Radio 357 Salon"
        value_template: "{{ is_state('media_player.mojo', 'playing') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.radio_357
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.mojo
        icon_template: >-
          {% if is_state('media_player.mojo', 'playing') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}
      meloradio:
        friendly_name: "MeloRadio Salon"
        value_template: "{{ is_state('media_player.mojo', 'playing') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.meloradio
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.mojo
        icon_template: >-
          {% if is_state('media_player.mojo', 'playing') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}
      antyradio:
        friendly_name: "AntyRadio Salon"
        value_template: "{{ is_state('media_player.mojo', 'playing') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.antyradio
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.mojo
        icon_template: >-
          {% if is_state('media_player.mojo', 'playing') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}
      program3:
        friendly_name: "Program3 Salon"
        value_template: "{{ is_state('media_player.mojo', 'playing') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.trojka
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.mojo
        icon_template: >-
          {% if is_state('media_player.mojo', 'playing') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}

For 357:

          {% if is_state_attr('media_player.mojo', 'media_content_id', 'https://stream.rcs.revma.com/ye5kghkgcm0uv') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}

I assume…
And then you need to change the others the same way.

Thank you very much @Hellis81 . I can see the progress :slight_smile: about 85%

I did as you propose and I receive this:
8
we are almost there… icons are proper.

My target is to receive something like this:
9
(i did that on GIMP :slight_smile:)

I still need 15% --> could you help?

I’m not used to do customizations in switches/configuration i usually do that in customize.yaml.

I don’t know if you can do icon color template in configuration.
But that is what you need.
Icon_color: [same template as previously]
Yellow
Else
Blue
End if

this line also should be changed:

value_template: "{{ is_state('media_player.mojo', 'playing') and is_state_attr('media_player.mojo', 'media_content_id', 'https://stream.rcs.revma.com/ye5kghkgcm0uv') }}"
2 Likes

Thank you @emes30 and @Hellis81 right now is 100% finished.

11
and it works as I wish.

full code for further use (in the part for radio 357. another station could be adjusted as fallow):
switches.yaml

#virtual swiches
  - platform: template
    switches:
      radio357:
        friendly_name: "Radio 357 Salon"
        value_template: "{{ is_state('media_player.mojo', 'playing') and is_state_attr('media_player.mojo', 'media_content_id', 'https://stream.rcs.revma.com/ye5kghkgcm0uv') }}"
        turn_on:
          service: script.turn_on
          data:
            entity_id: script.radio_357
        turn_off:
          service: media_player.turn_off
          data:
            entity_id: media_player.mojo
        icon_template: >-
          {% if is_state_attr('media_player.mojo', 'media_content_id', 'https://stream.rcs.revma.com/ye5kghkgcm0uv') %}
            mdi:radio
          {% else %}
            mdi:radio-off
          {% endif %}