Ouvir rádio em simultâneo nos Google home minis usando grupos

Boas malta, já cá há algumas partilhas de códigos para ouvir rádio. Mas eu senti necessidade de ter as rádios sem necessitar de estar sempre a recorrer ao frontend do HA.
Então criei estes scripts com as rádios que mais gosto de ouvir e como tenho 2 minis criei um grupo com eles onde passo a rádio a minha escolha por comandos de voz. Tenho também uma automação que inicia a rádio pela manhã e desliga quando saio de casa. Deixo a baixo então o código que estou a usar. E como tinha aqui um comando do IKEA TRADFRI E1743 também o uso para poder controlar o volumes dos meus minis. As Rádios depois de criadas rotinas na app home, consigo pedir ao google para tocar a rádio que quiser no mini da sala, cozinha ou então na sala e cozinha (grupo) que ficam em perfeita sintonia.
Então cá vai o meu código…

Para as rádios:

script:

  radio_comercial_sala:
    alias: Radio Comercial sala
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.sala
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.sala
          media_content_id: http://mcrscast1.mcr.iol.pt/comercial.mp3
          media_content_type: 'audio/mp4'

  radio_comercial_cozinha:
    alias: Radio Comercial cozinha
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.cozinha
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.cozinha
          media_content_id: http://mcrscast1.mcr.iol.pt/comercial.mp3
          media_content_type: 'audio/mp4'

  radio_comercial_ambiente:
    alias: Radio Comercial ambiente
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: group.som_ambiente
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: group.som_ambiente
          media_content_id: http://mcrscast1.mcr.iol.pt/comercial.mp3
          media_content_type: 'audio/mp4'

  rfm_sala:
    alias: RFM sala
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.sala
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.sala
          media_content_id: http://19553.live.streamtheworld.com:3690/RFM_SC
          media_content_type: 'audio/mp4'

  rfm_cozinha:
    alias: RFM cozinha
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.cozinha
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.cozinha
          media_content_id: http://19553.live.streamtheworld.com:3690/RFM_SC
          media_content_type: 'audio/mp4'

  rfm_ambiente:
    alias: RFM ambiente
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: group.som_ambiente
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: group.som_ambiente
          media_content_id: http://19553.live.streamtheworld.com:3690/RFM_SC
          media_content_type: 'audio/mp4'

  m80_sala:
    alias: M80 sala
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.sala
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.sala
          media_content_id: http://mcrscast.mcr.iol.pt/m80
          media_content_type: 'audio/mp4'

  m80_cozinha:
    alias: M80 cozinha
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.cozinha
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.cozinha
          media_content_id: http://mcrscast.mcr.iol.pt/m80
          media_content_type: 'audio/mp4'

  m80_ambiente:
    alias: M80 ambiente
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: group.som_ambiente
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: group.som_ambiente
          media_content_id: http://mcrscast.mcr.iol.pt/m80
          media_content_type: 'audio/mp4'

  vodafone_sala:
    alias: Vodafone sala
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.sala
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.sala
          media_content_id: http://195.23.102.207/vodafone
          media_content_type: 'audio/mp4'

  vodafone_cozinha:
    alias: Vodafone cozinha
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: media_player.cozinha
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: media_player.cozinha
          media_content_id: http://195.23.102.207/vodafone
          media_content_type: 'audio/mp4'

  vodafone_ambiente:
    alias: Vodafone ambiente
    sequence:
      - service: media_player.volume_set
        data:
          entity_id: group.som_ambiente
          volume_level: '0.20'
      - service: media_player.play_media
        data_template:
          entity_id: group.som_ambiente
          media_content_id: http://195.23.102.207/vodafone
          media_content_type: 'audio/mp4'

  radio_stop_sala:
    alias: Parar rádio sala
    sequence:
      - service: media_player.media_stop
        data:
          entity_id: media_player.sala

  radio_stop_cozinha:
    alias: Parar rádio cozinha
    sequence:
      - service: media_player.media_stop
        data:
          entity_id: media_player.cozinha

  radio_stop_som_ambiente:
    alias: Parar rádio ambiente
    sequence:
      - service: media_player.media_stop
        data:
          entity_id: group.som_ambiente

###############################################################################
#                                                                             #
#                       I N P U T _ B O O L E A N                             #
#                                                                             #
############################################################################### 
input_boolean:
  ligar_radio:
    name: Rádio Status

###############################################################################
#                                                                             #
#                     I N P U T _ D A T E T I M E                             #
#                                                                             #
############################################################################### 
input_datetime:
  radio_on:
    name: "Ligar rádio às"
    has_date: false
    has_time: true

###############################################################################
#                                                                             #
#                           A U T O M A Ç Õ E S                               #
#                                                                             #
###############################################################################   
automation:

  - alias: Ligar rádio
    initial_state: true
    trigger:
      - platform: template
        value_template: "{{ states('sensor.time') == (states.input_datetime.radio_on.attributes.timestamp | int | timestamp_custom('%H:%M', False)) }}"
    condition:
      condition: and
      conditions:
      - condition: state
        entity_id: input_boolean.ligar_radio
        state: 'on'
      - condition: state
        entity_id: device_tracker.bruno_melo
        state: home
      - condition: state
        entity_id: 'binary_sensor.workday_sensor'
        state: 'on'
    action:
      - service: media_player.volume_set
        data:
          entity_id: group.som_ambiente
          volume_level: '0.20'
      -  service: media_player.play_media
         data_template:
          entity_id: group.som_ambiente
          media_content_id: http://mcrscast1.mcr.iol.pt/comercial.mp3
          media_content_type: 'audio/mp4'


  - alias: Desligar rádio na ausencia
    initial_state: true
    trigger:
      - platform: state
        entity_id: device_tracker.bruno_melo
        from: home
        to: not_home
    action:
      - service: script.turn_on
        entity_id: 
          - script.radio_stop_sala
          - script.radio_stop_cozinha

###############################################################################
#                                                                             #
#                         G R O U P S                                         #
#                                                                             #
###############################################################################      
group:

  som_ambiente:
    control: hidden
    entities:
      - media_player.cozinha
      - media_player.sala

E para controlar o volume…

  - alias: Diminuir som sala
    initial_state: true
    trigger: 
      platform: state
      entity_id: sensor.0x000d6ffffebcd992_click
      to: 'off'
    action:
      - service: media_player.volume_set
        entity_id: media_player.sala
        data_template:
          volume_level: '{{ states.media_player.sala.attributes.volume_level - 0.10 }}'

  - alias: Aumentar som sala
    initial_state: true
    trigger: 
      platform: state
      entity_id: sensor.0x000d6ffffebcd992_click
      to: 'on'
    action:
      - service: media_player.volume_set
        entity_id: media_player.sala
        data_template:
          volume_level: '{{ states.media_player.sala.attributes.volume_level + 0.10 }}'


  - alias: Diminuir som cozinha
    initial_state: true
    trigger: 
      platform: state
      entity_id: sensor.0x000d6ffffebcd992_click
      to: 'off'
    action:
      - service: media_player.volume_set
        entity_id: media_player.cozinha
        data_template:
          volume_level: '{{ states.media_player.cozinha.attributes.volume_level - 0.10 }}'

  - alias: Aumentar som cozinha
    initial_state: true
    trigger: 
      platform: state
      entity_id: sensor.0x000d6ffffebcd992_click
      to: 'on'
    action:
      - service: media_player.volume_set
        entity_id: media_player.cozinha
        data_template:
          volume_level: '{{ states.media_player.cozinha.attributes.volume_level + 0.10 }}'

Espero que seja util para alguém, aceito também alguma sugestão.

8 Curtiram

Novo endereço para a Rádio Comercial: https://stream-icy.bauermedia.pt/comercial.aac

Novo endereço para a M80: https://stream-icy.bauermedia.pt/m80.aac


Copyright © 2017-2021. Todos os direitos reservados
CPHA.pt - info@cpha.pt


FAQ | Termos de Serviço/Regras | Política de Privacidade