Play Radio Browser via Home Assistant

Play Radio Browser via Home Assistant

15 oktober 2022 1 Door Ivo

Radio Browser

Het zit al een tijdje in Home Assistant, maar hoe kun je deze gemakkelijk gebruiken voor je slimme speakers.
Leuk om een zender af te spelen in de browser of een andere media_player.

Maja een zender selecteren is best wat klikken, en hoe sla je het op?
Aan mijn oude radio heb ik een AudioCast gesloten en toegevoegd in Home Assistant.
Hoe ik daarom met 1 klik een zender af speel leg ik hieronder uit.

Audio-cast

 

AudioCast

De AudioCast is vrij eenvoudig in gebruik AudioCast site (daarmee stel je je wifi in, daarna kun je de app weer verwijderen :))

Ik heb daarvoor een kort artikel gemaakt, zie Audiocast

Sonos

Heb je een of meerdere Sonos speakers? Die kun je ook makkelijk aansturen met de Sonos integratie.

De Knop

Ga naar de LoveLace en maak een button aan:

type: button
name: NPO 1
show_name: true
show_icon: true
icon_height: 25px
icon: mdi:radio
tap_action:
  service: media_player.play_media
  action: call-service
  data:
    media_content_id: media-source://radio_browser/96126f56-0601-11e8-ae97-52543be04c81
    media_content_type: audio/mpeg
  target:
    entity_id: media_player.living_room

En het werkt! Maar, hoe kom je aan het media_content_id en type?
Heb je meerdere media players in huis? Onderaan de uitleg voor meerdere players.

Automation

Daarvoor had ik tijdens het testen een automation voor gemaakt.

Maak een helper aan, een schakelaar.
helper

Onderstaand de Radio Browser yaml van de automation:

alias: Radio NPO1
description: ""
trigger:
  - platform: state
    entity_id:
      - input_boolean.npo1
    from: "off"
    to: "on"
condition: []
action:
  - service: media_player.play_media
    target:
      entity_id: media_player.living_room
    data:
      media_content_id: media-source://radio_browser/96126f56-0601-11e8-ae97-52543be04c81
      media_content_type: audio/mpeg
    metadata:
      title: NPO Radio 1
      thumbnail: >-
        https://upload.wikimedia.org/wikipedia/commons/thumb/d/da/NPO_Radio_1_logo_2014.svg/640px-NPO_Radio_1_logo_2014.svg.png
      media_class: music
      children_media_class: null
      navigateIds:
        - {}
        - media_content_type: app
          media_content_id: media-source://radio_browser
        - media_content_type: music
          media_content_id: media-source://radio_browser/country/NL
mode: single

Via de Visueel editor kun je zenders selecteren en dan kijk je in de yaml voor content_id en type. De tumbnail kunnen we gebruiken voor de HACS methode.
Je kunt ook gemakkelijk eigen media selecteren om zo het juiste pad en format te krijgen.

HACS

Heb je Hacs geïnstalleerd?

zenders

Installeer de frontend button-card
Daarmee krijg je de mogelijkheid tot de type: custom:button-card

Maak knoppen met het logo van de zender. Onderstaand de code voor de Q-Music België.

name: BE
type: custom:button-card
show_entity_picture: true
entity_picture: /local/radio/Qmusic_logo.svg
tap_action:
  action: call-service
  service: media_player.play_media
  service_data:
    media_content_id: media-source://radio_browser/bbabb958-aa77-4d52-80c6-d86c9268721f
    media_content_type: audio/mpeg
    entity_id: media_player.living_room

 

Je kunt de logo’s zelf opslaan of een url oproepen
entity_picture: http://www.nporadio2.nl/apple-touch-icon.png

De url van het logo haal je ook weer uit de automation.

Onderstaand een lijstje met zenders welke ik heb gebruikt.

 

Meerdere slimme speakers

Heb je meerdere slimme speakers, dan hoef je niet voor elke speler knoppen te maken,

Input selector

Als eerste pas je de configuration.yaml aan, voeg onderstaande toe.

input_select:
  radio:
    name: Welke Radio
    options:
      - Woonkamer
      - Slaapkamer
    initial: Woonkamer
    icon: mdi:radio

Sla op, en herstart Home Assistant.

We maken de kaart aan

Onderstaand de gehele code welke ik gebruik bovenaan de selector, eronde de radio-knoppen welke kijkt naar de selector om de juiste media_player te selecteren. Dit kun je natuurlijk aanpassen en uitbreiden met al favoriete zenders en al je media_players! 📻

In de zender code heb ik de Keuken al toegevoegd, kerstcadeau voor vriendin 👧 de selector pas ik later aan.Radio Browser met meerdere media player

type: vertical-stack
cards:
  - type: entities
    entities:
      - entity: input_select.radio
  - type: horizontal-stack
    cards:
      - type: horizontal-stack
        title: Zenders
        cards:
          - type: vertical-stack
            cards:
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/Qmusic_logo.svg
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/bbabb958-aa77-4d52-80c6-d86c9268721f
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
                name: BE
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: http://radio1.nl/apple-touch-icon.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/96126f56-0601-11e8-ae97-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: http://www.nporadio2.nl/apple-touch-icon.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/96126e82-0601-11e8-ae97-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/NPO3fm.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/0c62b9d7-8de0-4693-9842-6bf9b50229d3
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
          - type: vertical-stack
            cards:
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/Qmusic_logo.svg
                icon_height: 25px
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/003d3c6f-e183-11e9-a8ba-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
                name: NL
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/sky.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/ea6de4cc-53de-4b2d-8a1b-e92d0c575dff
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: https://www.538.nl/icons/apple-icon-120x120.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/68861777-8f09-4221-ae8f-56aa658060c0
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: https://www.slam.nl/images/favicons/slam.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/962e7e22-0601-11e8-ae97-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
          - type: vertical-stack
            cards:
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/Qmusic_logo.svg
                icon_height: 25px
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/674e1f9d-4686-4bc0-8fc3-7e1517ed543a
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
                name: Dance
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: >-
                  https://www.radioveronica.nl/static/media/RadioVeronicaPlayerLogo.4511a841.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/660f5671-cf64-4c4f-8d90-26ee47b4f1bb
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: >-
                  https://static.files.bbci.co.uk/sounds/web/sounds-web/img/sounds-apple-touch-icon.ead169771d.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/fdf557ac-bcf3-4846-a701-d25c462e4f44
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
          - type: vertical-stack
            cards:
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/Qmusic_logo.svg
                icon_height: 25px
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/155b08b4-97da-11e9-a605-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
                name: Fout
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/Qmusic_logo.svg
                icon_height: 25px
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/4e9c82d5-97da-11e9-a605-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
                name: non-stop
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: https://l1.nl/static/meta/apple-touch-icon.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/c344992c-b881-11e9-acb2-52543be04c81
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]
              - show_name: true
                show_icon: true
                type: custom:button-card
                show_entity_picture: true
                entity_picture: /local/radio/L1alaaf.png
                tap_action:
                  action: call-service
                  service: media_player.play_media
                  service_data:
                    media_content_id: >-
                      media-source://radio_browser/c47360b0-70ca-49fb-bed3-19074e46fe28
                    media_content_type: audio/mpeg
                    entity_id: |
                      [[[
                        var player = states["input_select.radio"].state;
                        if ([player] == 'Woonkamer') return 'media_player.living_room';
                        if ([player] == 'Keuken') return 'media_player.slaapkamer';
                        if ([player] == 'Slaapkamer') return 'media_player.slaapkamer';
                      ]]]

 

Laat weten of het jou ook is gelukt voor jouw media_player! 🎶