Radio streaming with Album Art, Artist and Track Name

I already ran this command on the 3 files … But without success.
I tried to run the file HA_Scrape.py by ssh and it gives me the following error:

pi@hassio:/usr/share/hassio/homeassistant/script $ python HA_Scrape.py
Traceback (most recent call last):
  File "HA_Scrape.py", line 4, in <module>
    from bs4 import BeautifulSoup
ImportError: No module named bs4

Bs4 is BeautifulSoup which is used by the Scrape integration, should already be installed…
You need to make sure this runs under ha, not just via ssh as indeed it won’t work as you’re outside the container…

thank you very much for your support! you did a fantastic job. In the end I customized your package that I am attaching … it is a simplified version without being able to view the artist and the track but equally functional …
I just changed the fact that when you press the Stop the boolean input goes directly off and eliminated the Scrap, then as regards the reproduction instead of audio / mp4 I had to put music otherwise some radio stations did not work me. I attach the package if could be of interest to someone else

Package Radio v1.0

#################################################################
#                                                               #
#                           Radio                               #
#                                                               #
#################################################################

homeassistant:
  customize:
    input_number.initial_volume_radio:
      icon: mdi:volume-high
    input_select.chromecast_radio_station:
      icon: mdi:radio
    sensor.radio_selected:
      icon: mdi:radio
    input_select.chromecast_radio_speakers:
      icon: mdi:speaker-wireless
    sensor.speaker_selected:
      icon: mdi:speaker-wireless
    input_text.custom_station:
      icon: mdi:link-variant

#################################################################
sensor:
  - platform: template
    sensors:
      radio_selected:
        value_template: '{{ states.input_select.chromecast_radio_station.state }}'
        friendly_name: 'Stazione selezionata'

  - platform: template
    sensors:
      speaker_selected:
        value_template: '{{ states.input_select.chromecast_radio_speakers.state }}'
        friendly_name: 'Speaker selezionato'


#################################################################
input_number:
  initial_volume_radio:
    name: Volume iniziale
    initial: 0.3
    min: 0
    max: 1
    step: 0.05
    mode: box


#################################################################
input_select:
  chromecast_radio_station:
    name: 'Select Radio Station'
    options:
      - RDS Radio
      - Radio 105
      - Virgin Radio
      - Radio freccia
      - Custom Station
      - Spenta

  chromecast_radio_speakers:
    name: 'Select Speakers'
    options:
      - Salotto
      - Bagno
      - Studio
      - Gruppo Casa


#################################################################
input_text:
  custom_station:
    name: Radio URL


#################################################################
script:
  play_chromecast_radio:
    alias: Cast Selected Radio on Chromecast Speakers
    sequence:
      - service: media_player.volume_set
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
            {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
            {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
            {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
            {% endif %}
          volume_level: '{{  states("input_number.initial_volume_radio")  }}' 
      - service: media_player.play_media
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
            {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
            {% elif is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
            {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
            {% endif %}
          media_content_id: >
            {% if is_state("input_select.chromecast_radio_station", "RDS Radio") %} https://icstream.rds.radio/rds
            {% elif is_state("input_select.chromecast_radio_station", "Radio 105") %} http://icecast.unitedradio.it/Radio105.mp3
            {% elif is_state("input_select.chromecast_radio_station", "Virgin Radio") %} http://icecast.unitedradio.it/Virgin.mp3
            {% elif is_state("input_select.chromecast_radio_station", "Radio freccia") %} https://streamingv2.shoutcast.com/radiofreccia
            {% elif is_state("input_select.chromecast_radio_station", "Custom Station") %} {{states("input_text.custom_station")}}
            {% endif %}
          media_content_type: music

  stop_chromecast_radio:
    alias: Stop Playing Radio on ChomeCast 
    sequence:
      - service: media_player.turn_off
        data_template:
          entity_id: >
            {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
            {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
            {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
            {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
            {% endif %}
      - service: input_select.select_option
        data:
          entity_id: input_select.chromecast_radio_station
          option: Spenta


#################################################################
switch:
  - platform: template
    switches:
      chromecast_radio_mute:
        icon_template: '{% if states("switch.chromecast_radio_mute") %}mdi:volume-off{% else %}mdi:volume-high{% endif %}'
        value_template: >
          {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} {% if state_attr("media_player.googlehome3627","is_volume_muted") %}on{% else %}off{% endif %}
          {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} {% if state_attr("media_player.googlehome5227","is_volume_muted") %}on{% else %}off{% endif %}
          {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} {% if state_attr("media_player.gruppo_casa_3","is_volume_muted") %}on{% else %}off{% endif %}
          {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} {% if state_attr("media_player.bagno","is_volume_muted") %}on{% else %}off{% endif %}
          {% else %}off
          {% endif %}
        turn_on:
          service: media_player.volume_mute
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}
            is_volume_muted: true
        turn_off:
          service: media_player.volume_mute
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}
            is_volume_muted: false

      chromecast_radio_vol_up:
        icon_template: 'mdi:volume-plus'
        value_template: 'on'
        turn_on:
          service: media_player.volume_up
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}
        turn_off:
          service: media_player.volume_up
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}

      chromecast_radio_vol_down:
        icon_template: 'mdi:volume-minus'
        value_template: 'on'
        turn_on:
          service: media_player.volume_down
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}
        turn_off:
          service: media_player.volume_down
          data_template:
            entity_id: >
              {% if is_state("input_select.chromecast_radio_speakers", "Salotto") %} media_player.googlehome3627
              {% elif is_state("input_select.chromecast_radio_speakers", "Studio") %} media_player.googlehome5227
              {% elif is_state("input_select.chromecast_radio_speakers", "Gruppo Casa") %} media_player.gruppo_casa_3
              {% elif is_state("input_select.chromecast_radio_speakers", "Bagno") %} media_player.bagno
              {% endif %}

      chromecast_radio_play:
        icon_template: 'mdi:play'
        value_template: 'on'
        turn_on:
          service: script.turn_on
          entity_id: script.play_chromecast_radio
        turn_off:
          service: script.turn_on
          entity_id: script.play_chromecast_radio

      chromecast_radio_stop:
        icon_template: 'mdi:stop'
        value_template: 'on'
        turn_on:
          service: script.turn_on
          entity_id: script.stop_chromecast_radio
        turn_off:
          service: script.turn_on
          entity_id: script.stop_chromecast_radio

Lovelace UI

cards:
  - entities:
      - entity: input_select.chromecast_radio_station
      - entity: input_text.custom_station
      - entity: input_select.chromecast_radio_speakers
      - entity: switch.chromecast_radio_vol_down
      - entity: switch.chromecast_radio_mute
      - entity: switch.chromecast_radio_vol_up
      - entity: switch.chromecast_radio_stop
      - entity: switch.chromecast_radio_play
    entity: input_select.chromecast_radio_station
    state_image:
      Custom Station: /local/immagini/radio/customstation.jpg
      RDS Radio: /local/immagini/radio/rds.jpg
      Radio 105: /local/immagini/radio/105.jpg
      Radio freccia: /local/immagini/radio/freccia.jpg
      Spenta: /local/immagini/radio/spenta.jpg
      Virgin Radio: /local/immagini/radio/virgin.jpg
    type: picture-glance
  - entities:
      - entity: sensor.radio_selected
      - entity: sensor.speaker_selected
      - entity: input_number.initial_volume_radio
    show_header_toggle: false
    type: entities
type: vertical-stack
2 Likes

the only thing that I couldn’t manage was the custom radio station … when I insert the link like this: http://icecast.unitedradio.it/Virgin.mp3 and I want to try some others but nothing starts. … Can you please check if it works for you? Thanks

1 Like

@lolouk44 Good morning, could you help me with this integration? I don’t understand much and I’m not getting the information about the album and the artist, although on the website that information appears there. Thanks in advance for the help you can give me …

The website is…
https://m.radiocomercial.iol.pt/player/emissaofm

I have tried all the codes shared here but have not been able to. Thank you very much for the help you can give.

Hi @maxcalavera

I moved away from the above code because it kept failing
You really need to find out if your radio provides json data. Scraping is bound to fail as at some stage they will change the interface and your sensor will fail.
I have an updated code if that helps you, check this post:

3 posts above I’ve also shared my lovelace card

Hi, I would like to use this solution. I installed HA on a VM so the install is ‘Home Assistant OS’. Should I be able to get it up and running or is it only for the experts in HA container or HA supervised?

It is not only for the experts in HA container or HA supervisor, so follow the several guides posted in the previous comments and it should help you get started, but depending on your skills and what you want, it may be a bit of a learning curve…

Thanks, will start and build my experience :wink:

help me to scrape this src link on this site, please: Image of the Day

image

Please note this is not related to this thread.
In addition there are various guides on this community on how to scrape data.

Ok, no problem. I just solve that.