Rádio Home Assistante - *byjaps

***** Nova versão, mais optimizada, ver comentário 4 para o package ( Rádio Home Assistante - *byjaps ) e comentário 6 para o card ( Rádio Home Assistante - *byjaps )


Olá a todos.
Venho aqui partilhar o rádio que fiz juntando varias ideias encontradas pela net…

Sem%20T%C3%ADtulo

É necessário estes parâmetros em /config/configuration.yaml

media_extractor:

customizer:
  custom_ui: local
  
homeassistant:
  customize: !include customize.yaml
  packages: !include_dir_named packages

media_player:

Para que tudo funcione é preciso o Custom UI instalado (para mudança de icons/cor) e o Button Card para o Rádio no Lovelace ficar igual a imagem em cima.

Este é o ficheiro radio.yaml onde esta toda a configuração do mesmo:

/config/packages/radio.yaml

##############################################################################
#####                            CUSTOMIZE                               #####
##############################################################################

homeassistant:
  customize:
    script.player:
      action_name: Play
      icon: mdi:play
      icon_color: green
    script.radio_pause:
      action_name: Pause
      icon: mdi:pause
      icon_color: yellow
    script.radio_stop:
      action_name: Stop
      icon: mdi:stop
      icon_color: red
    
    
    input_number.radio_volume:
      templates:
        icon: >
          if (state == 0) return 'mdi:volume-off';
          if (state <= 15) return 'mdi:volume-low';
          if (state < 50) return 'mdi:volume-medium';
          if (state <= 100) return 'mdi:volume-high';
        icon_color: >
          if (state == 0) return 'rgb(0,0,0)';
          if (state <= 25) return 'rgb(0,255,0)';
          if (state <= 50) return 'rgb(128,255,0)';
          if (state <= 75) return 'rgb(255,128,0)';
          if (state <= 100) return 'rgb(255,0,0)';

##############################################################################
#####                              GROUP                                 #####
##############################################################################

group:
  radio:
    name: Radio
    control: hidden
    entities:
    - input_select.radio_station
    - input_select.media_player
    - input_number.radio_volume
    - input_text.youtube_url
    - input_text.radio_url
    - script.player
    - script.radio_pause
    - script.radio_stop

##############################################################################
#####                           INPUT SELECT                             #####
##############################################################################
input_select:
    radio_station:
        name: 'Escoher Rádio:'
        options:
             - Nova Era
             - Cidade FM
             - Comercial
             - Noite.fm
             - Oceano Pacifico RFM
             - YouTube URL
             - Rádio URL
        initial: Noite.fm
        icon: mdi:radio-fm


    media_player:
        name: 'Escolher Coluna:'
        options:
          - Sala
          - Cozinha
          - Casa de Banho
          - Quarto
          - Grupo Casa
        initial: Casa de Banho
        icon: mdi:speaker-wireless

##############################################################################
#####                           INPUT NUMBER                             #####
##############################################################################

input_number: 
  radio_volume:
    name: Volume
    icon: mdi:volume-high
    initial: 30
    min: 0
    max: 100
    step: 5
    unit_of_measurement: '%'

##############################################################################
#####                             INPUT TEXT                             #####
##############################################################################

input_text:
  youtube_url:
    name: YouTube URL
    icon: mdi:youtube

  radio_url:
    name: Rádio URL
    icon: mdi:link-variant

##############################################################################
#####                            AUTOMATION                              #####
##############################################################################

automation:
    - alias: Play Radio
      hide_entity: True
      trigger:
        - platform: state
          entity_id: input_select.media_player
        - platform: state
          entity_id: input_select.radio_station
      action:
        - service: media_player.media_pause
          data:
            entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
        - delay: 00:00:01
        - service: media_player.volume_set
          data:
            entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
            volume_level: 0.80      
        - service: media_player.turn_off
          data:
            entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
        - service: script.player

    - alias: Rádio Volume
      hide_entity: True
      trigger:
        platform: state
        entity_id: input_number.radio_volume
      action:
        service: media_player.volume_set
        data_template:
          entity_id: >
            {% if is_state("input_select.media_player", "Sala") %} media_player.google_mini_sala
            {% elif is_state("input_select.media_player", "Cozinha") %} media_player.google_mini_cozinha
            {% elif is_state("input_select.media_player", "Casa de Banho") %} media_player.google_mini_wc
            {% elif is_state("input_select.media_player", "Quarto") %} media_player.google_mini_quarto_1
            {% elif is_state("input_select.media_player", "Grupo Casa") %} media_player.grupo_casa
            {% endif %}
          volume_level: "{{  states('input_number.radio_volume')|float / 100 }}"

##############################################################################
#####                              SCRIPT                                #####
##############################################################################

script:
    player:
        alias: Player
        sequence:
           - service: media_player.volume_set
             data_template:
              entity_id: >
                {% if is_state("input_select.media_player", "Sala") %} media_player.google_mini_sala
                {% elif is_state("input_select.media_player", "Cozinha") %} media_player.google_mini_cozinha
                {% elif is_state("input_select.media_player", "Casa de Banho") %} media_player.google_mini_wc
                {% elif is_state("input_select.media_player", "Quarto") %} media_player.google_mini_quarto_1
                {% elif is_state("input_select.media_player", "Grupo Casa") %} media_player.grupo_casa
                {% endif %}
              volume_level: "{{  states('input_number.radio_volume')|float / 100 }}"
           - service_template: >
              {% if states.input_select.radio_station.state != "YouTube URL" %} script.radio_play
              {% elif states.input_select.radio_station.state == "YouTube URL" %} script.youtube_play
              {% endif %} 




    radio_play:
        alias: Play - Rádio
        sequence:
          - service: media_player.play_media
            data_template:
              entity_id: >
                  {% if is_state("input_select.media_player", "Sala") %} media_player.google_mini_sala
                  {% elif is_state("input_select.media_player", "Cozinha") %} media_player.google_mini_cozinha
                  {% elif is_state("input_select.media_player", "Casa de Banho") %} media_player.google_mini_wc
                  {% elif is_state("input_select.media_player", "Quarto") %} media_player.google_mini_quarto_1
                  {% elif is_state("input_select.media_player", "Grupo Casa") %} media_player.grupo_casa
                  {% endif %}
              media_content_id: >
                 {% if is_state("input_select.radio_station", "Nova Era") %} http://centova.radios.pt:9478/stream
                 {% elif is_state("input_select.radio_station", "Cidade FM") %} http://mcrscast.mcr.iol.pt/cidadefm
                 {% elif is_state("input_select.radio_station", "Comercial") %} http://mcrscast1.mcr.iol.pt/comercial.mp3
                 {% elif is_state("input_select.radio_station", "Noite.fm") %} http://live.noite.pt:8080/;
                 {% elif is_state("input_select.radio_station", "Oceano Pacifico RFM") %}https://21283.live.streamtheworld.com/OCEANPACIFICAAC_SC
                 {% elif is_state("input_select.radio_station", "Rádio URL") %} {{states.input_text.radio_url.state}}
                 {% endif %}
              media_content_type: 'music'

    youtube_play:
        alias: Play - YouTube
        sequence:
          - service: media_extractor.play_media
            data_template:
              entity_id: >
                  {% if is_state("input_select.media_player", "Sala") %} media_player.google_mini_sala
                  {% elif is_state("input_select.media_player", "Cozinha") %} media_player.google_mini_cozinha
                  {% elif is_state("input_select.media_player", "Casa de Banho") %} media_player.google_mini_wc
                  {% elif is_state("input_select.media_player", "Quarto") %} media_player.google_mini_quarto_1
                  {% elif is_state("input_select.media_player", "Grupo Casa") %} media_player.grupo_casa
                  {% endif %}
              media_content_id: "{{ states.input_text.youtube_url.state }}"
              media_content_type: 'music'

    radio_pause:
        alias: Pausa - Rádio
        sequence:
          service: media_player.media_play_pause
          data_template:
               entity_id: >
                {% if is_state("input_select.media_player", "Sala") %} media_player.google_mini_sala
                {% elif is_state("input_select.media_player", "Cozinha") %} media_player.google_mini_cozinha
                {% elif is_state("input_select.media_player", "Casa de Banho") %} media_player.google_mini_wc
                {% elif is_state("input_select.media_player", "Quarto") %} media_player.google_mini_quarto_1
                {% elif is_state("input_select.media_player", "Grupo Casa") %} media_player.grupo_casa
                {% endif %}

    radio_stop:
        alias: Stop - Rádio
        sequence:
          - service: media_player.media_pause
            data:
              entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
          - service: media_player.volume_set
            data:
              entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
              volume_level: 0.80      
          - service: media_player.turn_off
            data:
              entity_id: media_player.google_mini_cozinha, media_player.google_mini_quarto_1, media_player.google_mini_sala, media_player.google_mini_wc
          - service: automation.turn_off
            entity_id: automation.play_radio
          - service: input_select.select_option
            data:
              entity_id: input_select.radio_station
              option: Noite.fm
          - service: input_number.set_value
            data:
              entity_id: input_number.radio_volume
              value: 30
          - service: input_select.select_option
            data:
              entity_id: input_select.media_player
              option: Casa de Banho
          - service: automation.turn_on
            entity_id: automation.play_radio
           

E este é o custom card:

cards:
  - entities:
      - entity: input_select.radio_station
      - entity: input_select.media_player
    icon: 'mdi:radio'
    show_header_toggle: false
    title: Rádio
    type: entities
  - card:
      entities:
        - input_text.radio_url
      type: entities
    conditions:
      - entity: input_select.radio_station
        state: Rádio URL
    type: conditional
  - card:
      entities:
        - input_text.youtube_url
      type: entities
    conditions:
      - entity: input_select.radio_station
        state: YouTube URL
    type: conditional
  - entities:
      - entity: input_number.radio_volume
    type: entities
  - cards:
      - type: 'custom:button-card'
        color_type: icon
        color: green
        icon: 'mdi:play'
        tap_action:
          action: call-service
          service: script.player
      - type: 'custom:button-card'
        color_type: icon
        color: yellow
        icon: 'mdi:pause'
        tap_action:
          action: call-service
          service: script.radio_pause
      - type: 'custom:button-card'
        color_type: icon
        color: red
        icon: 'mdi:stop'
        tap_action:
          action: call-service
          service: script.radio_stop
    type: horizontal-stack
type: vertical-stack

Neste Rádio é possível colocar links de rádios manualmente e também links de vídeos do youtube (usando o media_extractor para isso).

Ainda quero colocar mais emissoras de rádios e mudar algumas coisas, mas a parte mais complicada já esta feita…

Espero que esta minha partilha vos seja útil.

Qualquer duvida ou sugestão são bem-vindas.

10 Curtiram

obrigado pela partilha contudo o groups já não necessário usar podes usar o card entities para substituir isso.

1 Curtiu

Boa tarde.

@byjaps fiz a configuração do radio que aqui colocaste e está tudo funcionar mas o grupo casa, ou seja, tocar em mais que um mini ao mesmo tempo não está a funcionar, tenho que fazer alguma alteração?

Obrigado

Eu alterei bastante o meu rádio.
No novo posso escolher que coluna ou colunas quero que toquem rádio assim como tocar rádios diferentes.
O volume se alterado nos Google’s minis também e alterado no HA e visse versa…
As radios são editadas através do Card (não e necessário ir ao editor de yaml).
Entre outras coisas…

Aqui fica o novo código…

##############################################################################
#####                            CUSTOMIZE                               #####
##############################################################################
homeassistant:

  customize:

    input_boolean.radio_mini_sala:
      templates:
        icon_color: >
          if (state == 'on') return 'rgb(0,255,0)';

    input_boolean.radio_mini_cozinha:
      templates:
        icon_color: >
          if (state == 'on') return 'rgb(0,255,0)';

    input_boolean.radio_mini_wc:
      templates:
        icon_color: >
          if (state == 'on') return 'rgb(0,255,0)';

    input_boolean.radio_mini_quarto:
      templates:
        icon_color: >
          if (state == 'on') return 'rgb(0,255,0)';


    sensor.radio_sala:
      icon_color: rgb(0,255,0)

    sensor.radio_cozinha:
      icon_color: rgb(0,255,0)

    sensor.radio_wc:
      icon_color: rgb(0,255,0)

    sensor.radio_quarto:
      icon_color: rgb(0,255,0)


    input_number.radio_volume_mini_sala:
      templates:
        icon: >
          if (state == 0) return 'mdi:volume-off';
          if (state <= 15) return 'mdi:volume-low';
          if (state < 50) return 'mdi:volume-medium';
          if (state <= 100) return 'mdi:volume-high';
        icon_color: >
          if (state == 0) return 'rgb(0,0,0)';
          if (state <= 25) return 'rgb(0,255,0)';
          if (state <= 50) return 'rgb(128,255,0)';
          if (state <= 75) return 'rgb(255,128,0)';
          if (state <= 100) return 'rgb(255,0,0)';

    input_number.radio_volume_mini_cozinha:
      templates:
        icon: >
          if (state == 0) return 'mdi:volume-off';
          if (state <= 15) return 'mdi:volume-low';
          if (state < 50) return 'mdi:volume-medium';
          if (state <= 100) return 'mdi:volume-high';
        icon_color: >
          if (state == 0) return 'rgb(0,0,0)';
          if (state <= 25) return 'rgb(0,255,0)';
          if (state <= 50) return 'rgb(128,255,0)';
          if (state <= 75) return 'rgb(255,128,0)';
          if (state <= 100) return 'rgb(255,0,0)';

    input_number.radio_volume_mini_wc:
      templates:
        icon: >
          if (state == 0) return 'mdi:volume-off';
          if (state <= 15) return 'mdi:volume-low';
          if (state < 50) return 'mdi:volume-medium';
          if (state <= 100) return 'mdi:volume-high';
        icon_color: >
          if (state == 0) return 'rgb(0,0,0)';
          if (state <= 25) return 'rgb(0,255,0)';
          if (state <= 50) return 'rgb(128,255,0)';
          if (state <= 75) return 'rgb(255,128,0)';
          if (state <= 100) return 'rgb(255,0,0)';


    input_number.radio_volume_mini_quarto:
      templates:
        icon: >
          if (state == 0) return 'mdi:volume-off';
          if (state <= 15) return 'mdi:volume-low';
          if (state < 50) return 'mdi:volume-medium';
          if (state <= 100) return 'mdi:volume-high';
        icon_color: >
          if (state == 0) return 'rgb(0,0,0)';
          if (state <= 25) return 'rgb(0,255,0)';
          if (state <= 50) return 'rgb(128,255,0)';
          if (state <= 75) return 'rgb(255,128,0)';
          if (state <= 100) return 'rgb(255,0,0)';

##############################################################################
#####                            SENSORES                                #####
##############################################################################
sensor:

  platform: template
  sensors:

    radio_sala:
      value_template: >
        {% if states.media_player.google_mini_sala.attributes.media_content_id == states.input_text.radio_url_1.state %} {{ states.input_text.radio_1.state }}
        {% elif states.media_player.google_mini_sala.attributes.media_content_id == states.input_text.radio_url_2.state %} {{ states.input_text.radio_2.state }}
        {% elif states.media_player.google_mini_sala.attributes.media_content_id == states.input_text.radio_url_3.state %} {{ states.input_text.radio_3.state }}
        {% elif states.media_player.google_mini_sala.attributes.media_content_id == states.input_text.radio_url_4.state %} {{ states.input_text.radio_4.state }}
        {% elif states.media_player.google_mini_sala.attributes.media_content_id == states.input_text.radio_url_5.state %} {{ states.input_text.radio_5.state }}
        {% else %} - - -
        {% endif %}
      friendly_name: 𝙎𝙖𝙡𝙖
      icon_template: mdi:play

    radio_cozinha:
      value_template: >
        {% if states.media_player.google_mini_cozinha.attributes.media_content_id == states.input_text.radio_url_1.state %} {{ states.input_text.radio_1.state }}
        {% elif states.media_player.google_mini_cozinha.attributes.media_content_id == states.input_text.radio_url_2.state %} {{ states.input_text.radio_2.state }}
        {% elif states.media_player.google_mini_cozinha.attributes.media_content_id == states.input_text.radio_url_3.state %} {{ states.input_text.radio_3.state }}
        {% elif states.media_player.google_mini_cozinha.attributes.media_content_id == states.input_text.radio_url_4.state %} {{ states.input_text.radio_4.state }}
        {% elif states.media_player.google_mini_cozinha.attributes.media_content_id == states.input_text.radio_url_5.state %} {{ states.input_text.radio_5.state }}
        {% else %} - - -
        {% endif %}
      friendly_name: 𝘾𝙤𝙯𝙞𝙣𝙝𝙖
      icon_template: mdi:play

    radio_wc:
      value_template: >
        {% if states.media_player.google_mini_wc.attributes.media_content_id == states.input_text.radio_url_1.state %} {{ states.input_text.radio_1.state }}
        {% elif states.media_player.google_mini_wc.attributes.media_content_id == states.input_text.radio_url_2.state %} {{ states.input_text.radio_2.state }}
        {% elif states.media_player.google_mini_wc.attributes.media_content_id == states.input_text.radio_url_3.state %} {{ states.input_text.radio_3.state }}
        {% elif states.media_player.google_mini_wc.attributes.media_content_id == states.input_text.radio_url_4.state %} {{ states.input_text.radio_4.state }}
        {% elif states.media_player.google_mini_wc.attributes.media_content_id == states.input_text.radio_url_5.state %} {{ states.input_text.radio_5.state }}
        {% else %} - - -
        {% endif %}
      friendly_name: 𝙒𝘾
      icon_template: mdi:play

    radio_quarto:
      value_template: >
        {% if states.media_player.google_mini_quarto.attributes.media_content_id == states.input_text.radio_url_1.state %} {{ states.input_text.radio_1.state }}
        {% elif states.media_player.google_mini_quarto.attributes.media_content_id == states.input_text.radio_url_2.state %} {{ states.input_text.radio_2.state }}
        {% elif states.media_player.google_mini_quarto.attributes.media_content_id == states.input_text.radio_url_3.state %} {{ states.input_text.radio_3.state }}
        {% elif states.media_player.google_mini_quarto.attributes.media_content_id == states.input_text.radio_url_4.state %} {{ states.input_text.radio_4.state }}
        {% elif states.media_player.google_mini_quarto.attributes.media_content_id == states.input_text.radio_url_5.state %} {{ states.input_text.radio_5.state }}
        {% else %} - - -
        {% endif %}
      friendly_name: 𝙌𝙪𝙖𝙧𝙩𝙤
      icon_template: mdi:play




##############################################################################
#####                         INPUT BOOTLEAN                             #####
##############################################################################
input_boolean:

  radio_mini_sala:
    name: Sala
    icon: mdi:google-home

  radio_mini_cozinha:
    name: Cozinha
    icon: mdi:google-home

  radio_mini_wc:
    name: WC
    icon: mdi:google-home

  radio_mini_quarto:
    name: Quarto
    icon: mdi:google-home

##############################################################################
#####                           INPUT SELECT                             #####
##############################################################################
input_select:

    radio_estacao_sala:
        name: 'Escoher Rádio:'
        options: 
          - '[[ Editar Rádios ]]'
        icon: mdi:radio-fm

    radio_estacao_cozinha:
        name: 'Escoher Rádio:'
        options: 
          - '[[ Editar Rádios ]]'
        icon: mdi:radio-fm

    radio_estacao_wc:
        name: 'Escoher Rádio:'
        options: 
          - '[[ Editar Rádios ]]'
        icon: mdi:radio-fm

    radio_estacao_quarto:
        name: 'Escoher Rádio:'
        options: 
          - '[[ Editar Rádios ]]'
        icon: mdi:radio-fm

##############################################################################
#####                           INPUT NUMBER                             #####
##############################################################################
input_number:

  radio_volume_mini_sala:
    name: Volume
    icon: mdi:volume-high
    initial: 75
    min: 0
    max: 100
    step: 5
    unit_of_measurement: '%'

  radio_volume_mini_cozinha:
    name: Volume
    icon: mdi:volume-high
    initial: 75
    min: 0
    max: 100
    step: 5
    unit_of_measurement: '%'

  radio_volume_mini_wc:
    name: Volume
    icon: mdi:volume-high
    initial: 75
    min: 0
    max: 100
    step: 5
    unit_of_measurement: '%'

  radio_volume_mini_quarto:
    name: Volume
    icon: mdi:volume-high
    initial: 75
    min: 0
    max: 100
    step: 5
    unit_of_measurement: '%'

##############################################################################
#####                             INPUT TEXT                             #####
##############################################################################
input_text:

  radio_url_1:
    name: 1 URL

  radio_1:
    name: 1 Nome
    icon: mdi:radio-fm

  radio_url_2:
    name: 2 URL

  radio_2:
    name: 2 Nome
    icon: mdi:radio-fm

  radio_url_3:
    name: 3 URL

  radio_3:
    name: 3 Nome
    icon: mdi:radio-fm

  radio_url_4:
    name: 4 URL

  radio_4:
    name: 4 Nome
    icon: mdi:radio-fm

  radio_url_5:
    name: 5 URL

  radio_5:
    name: 5 Nome
    icon: mdi:radio-fm

##############################################################################
#####                            AUTOMATION                              #####
##############################################################################
automation:

    - alias: Rádio - Play
      trigger:
        - platform: state
          entity_id: input_boolean.radio_mini_sala,  input_boolean.radio_mini_cozinha,  input_boolean.radio_mini_wc,  input_boolean.radio_mini_quarto
          to: 'on'
      action:
        - service: media_player.volume_set
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} media_player.google_mini_quarto
              {% endif %}
            volume_level: >
              {% if '09:00' <= states.sensor.time.state < '10:00' | timestamp_custom('%H:%M') %}
                0.35
              {% elif '10:00' <= states.sensor.time.state < '22:00' | timestamp_custom('%H:%M') %}
                0.40
              {% elif '22:00' <= states.sensor.time.state <= '23:59' | timestamp_custom('%H:%M') %}
                0.30
              {% else %}
                0.25
              {% endif %} 
        - service_template: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} script.radio_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} script.radio_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} script.radio_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} script.radio_quarto
              {% endif %}
        - service: automation.turn_on
          entity_id:
            - automation.radio_volume_input
            - automation.radio_volume_minis

    - alias: Rádio - Mudar
      trigger:
        - platform: state
          entity_id: input_select.radio_estacao_sala,  input_select.radio_estacao_cozinha,  input_select.radio_estacao_wc,  input_select.radio_estacao_quarto
      condition:
        condition: not
        conditions:
          - condition: state
            entity_id: input_select.radio_estacao_sala
            state: '[[ Editar Rádios ]]'
          - condition: state
            entity_id: input_select.radio_estacao_cozinha
            state: '[[ Editar Rádios ]]'
          - condition: state
            entity_id: input_select.radio_estacao_wc
            state: '[[ Editar Rádios ]]'
          - condition: state
            entity_id: input_select.radio_estacao_quarto
            state: '[[ Editar Rádios ]]'
          - condition: template
            value_template: >
              {% if trigger.from_state.entity_id == "input_select.radio_estacao_sala" %} {{ states.sensor.radio_sala.state == states.input_select.radio_estacao_sala.state }}
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_cozinha" %} {{ states.sensor.radio_cozinha.state == states.input_select.radio_estacao_cozinha.state }}
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_wc" %} {{ states.sensor.radio_wc.state == states.input_select.radio_estacao_wc.state }}
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_quarto" %} {{ states.sensor.radio_quarto.state == states.input_select.radio_estacao_quarto.state }}
              {% endif %}
      action:
        - service_template: >
              {% if trigger.from_state.entity_id == "input_select.radio_estacao_sala" %} script.radio_sala
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_cozinha" %} script.radio_cozinha
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_wc" %} script.radio_wc
              {% elif trigger.from_state.entity_id == "input_select.radio_estacao_quarto" %} script.radio_quarto
              {% endif %}


    - alias: Rádio - STOP
      trigger:
        - platform: state
          entity_id: input_boolean.radio_mini_sala,  input_boolean.radio_mini_cozinha,  input_boolean.radio_mini_wc,  input_boolean.radio_mini_quarto
          to: 'off'
        - platform: state
          entity_id: media_player.google_mini_sala, media_player.google_mini_cozinha, media_player.google_mini_wc, media_player.google_mini_quarto
          to: 'paused'
          for:
            minutes: 10
      action:
        - service: automation.turn_off
          entity_id: automation.radio_volume_input
        - service: automation.turn_off
          entity_id: automation.radio_volume_minis
        - service: media_player.media_stop
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} media_player.google_mini_quarto
              {% elif trigger.from_state.entity_id == "media_player.google_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} media_player.google_mini_quarto
              {% endif %}
        - delay: 00:00:02
        - service: media_player.volume_set
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} media_player.google_mini_quarto
              {% elif trigger.from_state.entity_id == "media_player.google_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} media_player.google_mini_quarto
              {% endif %}
            volume_level: 0.75
        - service: media_player.turn_off
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} media_player.google_mini_quarto
              {% elif trigger.from_state.entity_id == "media_player.google_mini_sala" %} media_player.google_mini_sala
              {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} media_player.google_mini_cozinha
              {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} media_player.google_mini_wc
              {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} media_player.google_mini_quarto
              {% endif %}
        - service: input_boolean.turn_off
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} input_boolean.radio_mini_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} input_boolean.radio_mini_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} input_boolean.radio_mini_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} input_boolean.radio_mini_quarto
              {% elif trigger.from_state.entity_id == "media_player.google_mini_sala" %} input_boolean.radio_mini_sala
              {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} input_boolean.radio_mini_cozinha
              {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} input_boolean.radio_mini_wc
              {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} input_boolean.radio_mini_quarto
              {% endif %}
        - service: input_select.select_option
          data_template:
            entity_id: >
              {% if trigger.from_state.entity_id == "input_boolean.radio_mini_sala" %} input_select.radio_estacao_sala
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_cozinha" %} input_select.radio_estacao_cozinha
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_wc" %} input_select.radio_estacao_wc
              {% elif trigger.from_state.entity_id == "input_boolean.radio_mini_quarto" %} input_select.radio_estacao_quarto
              {% elif trigger.from_state.entity_id == "media_player.google_mini_sala" %} input_select.radio_estacao_sala
              {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} input_select.radio_estacao_cozinha
              {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} input_select.radio_estacao_wc
              {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} input_select.radio_estacao_quarto
              {% endif %}
            option: "{{ states.input_text.radio_1.state }}"


    - alias: Rádio - Volume Input
      trigger:
        platform: state
        entity_id: input_number.radio_volume_mini_sala,input_number.radio_volume_mini_cozinha, input_number.radio_volume_mini_wc, input_number.radio_volume_mini_quarto
      action:
        service: media_player.volume_set
        data_template:
          entity_id: >
            {% if trigger.from_state.entity_id == "input_number.radio_volume_mini_sala" %} media_player.google_mini_sala
            {% elif trigger.from_state.entity_id == "input_number.radio_volume_mini_cozinha" %} media_player.google_mini_cozinha
            {% elif trigger.from_state.entity_id == "input_number.radio_volume_mini_wc" %} media_player.google_mini_wc
            {% elif trigger.from_state.entity_id == "input_number.radio_volume_mini_quarto" %} media_player.google_mini_quarto
            {% endif %}
          volume_level: "{{ states(trigger.entity_id)|float / 100 }}"

    - alias: Rádio - Volume Minis
      trigger:
        - platform: state
          entity_id: media_player.google_mini_sala, media_player.google_mini_cozinha, media_player.google_mini_wc, media_player.google_mini_quarto
      action:
        service: input_number.set_value
        data_template:
          entity_id: >
            {% if trigger.from_state.entity_id == "media_player.google_mini_sala" %} input_number.radio_volume_mini_sala
            {% elif trigger.from_state.entity_id == "media_player.google_mini_cozinha" %} input_number.radio_volume_mini_cozinha
            {% elif trigger.from_state.entity_id == "media_player.google_mini_wc" %} input_number.radio_volume_mini_wc
            {% elif trigger.from_state.entity_id == "media_player.google_mini_quarto" %} input_number.radio_volume_mini_quarto
            {% endif %}
          value: "{{state_attr(trigger.entity_id, 'volume_level') | multiply (100) | int}}"

 
    - alias: Rádio - Update
      trigger:
        - platform: homeassistant
          event: start
        - platform: state
          entity_id: input_text.radio_url_1, input_text.radio_url_2, input_text.radio_url_3, input_text.radio_url_4, input_text.radio_url_5
      action:
        - service: automation.turn_off
          entity_id: automation.radio_mudar
        - service: input_select.set_options
          data_template:
            entity_id:
              - input_select.radio_estacao_sala
              - input_select.radio_estacao_cozinha
              - input_select.radio_estacao_wc
              - input_select.radio_estacao_quarto
            options: ["{{states.input_text.radio_1.state}}", "{{states.input_text.radio_2.state}}", "{{states.input_text.radio_3.state}}", "{{states.input_text.radio_4.state}}", "{{states.input_text.radio_5.state}}", "[[ Editar Rádios ]]"]
        - delay: 00:00:10
        - service: automation.turn_on
          entity_id: automation.radio_mudar



##############################################################################
#####                              SCRIPT                                #####
##############################################################################
script:

    radio_sala:
        alias: Rádio - Sala
        sequence:
        - service: media_player.play_media
          data_template:
            entity_id: media_player.google_mini_sala
            media_content_id: >
              {% if states.input_select.radio_estacao_sala.state == states.input_text.radio_1.state %} {{states.input_text.radio_url_1.state}}
              {% elif states.input_select.radio_estacao_sala.state == states.input_text.radio_2.state %} {{states.input_text.radio_url_2.state}}
              {% elif states.input_select.radio_estacao_sala.state == states.input_text.radio_3.state %} {{states.input_text.radio_url_3.state}}
              {% elif states.input_select.radio_estacao_sala.state == states.input_text.radio_4.state %} {{states.input_text.radio_url_4.state}}
              {% elif states.input_select.radio_estacao_sala.state == states.input_text.radio_5.state %} {{states.input_text.radio_url_5.state}}
              {% endif %}
            media_content_type: 'music'

    radio_cozinha:
        alias: Rádio - Cozinha
        sequence:
        - service: media_player.play_media
          data_template:
            entity_id: media_player.google_mini_cozinha
            media_content_id: >
              {% if states.input_select.radio_estacao_cozinha.state == states.input_text.radio_1.state %} {{states.input_text.radio_url_1.state}}
              {% elif states.input_select.radio_estacao_cozinha.state == states.input_text.radio_2.state %} {{states.input_text.radio_url_2.state}}
              {% elif states.input_select.radio_estacao_cozinha.state == states.input_text.radio_3.state %} {{states.input_text.radio_url_3.state}}
              {% elif states.input_select.radio_estacao_cozinha.state == states.input_text.radio_4.state %} {{states.input_text.radio_url_4.state}}
              {% elif states.input_select.radio_estacao_cozinha.state == states.input_text.radio_5.state %} {{states.input_text.radio_url_5.state}}
              {% endif %}
            media_content_type: 'music'

    radio_wc:
        alias: Rádio - WC
        sequence:
        - service: media_player.play_media
          data_template:
            entity_id: media_player.google_mini_wc
            media_content_id: >
              {% if states.input_select.radio_estacao_wc.state == states.input_text.radio_1.state %} {{states.input_text.radio_url_1.state}}
              {% elif states.input_select.radio_estacao_wc.state == states.input_text.radio_2.state %} {{states.input_text.radio_url_2.state}}
              {% elif states.input_select.radio_estacao_wc.state == states.input_text.radio_3.state %} {{states.input_text.radio_url_3.state}}
              {% elif states.input_select.radio_estacao_wc.state == states.input_text.radio_4.state %} {{states.input_text.radio_url_4.state}}
              {% elif states.input_select.radio_estacao_wc.state == states.input_text.radio_5.state %} {{states.input_text.radio_url_5.state}}
              {% endif %}
            media_content_type: 'music'

    radio_quarto:
        alias: Rádio -  Quarto
        sequence:
        - service: media_player.play_media
          data_template:
            entity_id: media_player.google_mini_quarto
            media_content_id: >
              {% if states.input_select.radio_estacao_quarto.state == states.input_text.radio_1.state %} {{states.input_text.radio_url_1.state}}
              {% elif states.input_select.radio_estacao_quarto.state == states.input_text.radio_2.state %} {{states.input_text.radio_url_2.state}}
              {% elif states.input_select.radio_estacao_quarto.state == states.input_text.radio_3.state %} {{states.input_text.radio_url_3.state}}
              {% elif states.input_select.radio_estacao_quarto.state == states.input_text.radio_4.state %} {{states.input_text.radio_url_4.state}}
              {% elif states.input_select.radio_estacao_quarto.state == states.input_text.radio_5.state %} {{states.input_text.radio_url_5.state}}
              {% endif %}
            media_content_type: 'music'
    
    radio_reset:
       alias: Rádio - Reset
       sequence:
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_1
           value: Noite FM
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_url_1
           value: http://live.noite.pt:8080/;
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_2
           value: Nova Era
       - service: input_text.set_value
         data:
           entity_id: inputa_text.radio_url_2
           value: http://centova.radios.pt:9478/stream
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_3
           value: Cidade FM
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_url_3
           value: http://mcrscast.mcr.iol.pt/cidadefm
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_4
           value: Comercial
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_url_4
           value: http://mcrscast1.mcr.iol.pt/comercial.mp3
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_5
           value: Oceano Pacifico
       - service: input_text.set_value
         data:
           entity_id: input_text.radio_url_5
           value: https://21283.live.streamtheworld.com/OCEANPACIFICAAC_SC









1 Curtiu

Olá @byjaps. Podes pff partilhar o card?

Aqui está ele…

Eu adicionei um “botão” de reset que coloca as rádios pré definidas… ( script “rádio reset” ) É inútil, por exemplo, quando se usa o rádio pela primeira vez evitando assim o trabalho de configurar todas as rádios… Basta executar esse script…

Já atualizei o código no meu post anterior…

cards:
  - text: RÁDIO
    type: 'custom:text-divider-row'
  - entities:
      - entity: input_boolean.radio_mini_sala
        tap_action:
          action: call-service
          service: input_boolean.toggle
          service_data:
            entity_id: input_boolean.radio_mini_sala
      - entity: input_boolean.radio_mini_cozinha
        tap_action:
          action: call-service
          service: input_boolean.toggle
          service_data:
            entity_id: input_boolean.radio_mini_cozinha
      - entity: input_boolean.radio_mini_wc
        tap_action:
          action: call-service
          service: input_boolean.toggle
          service_data:
            entity_id: input_boolean.radio_mini_wc
      - entity: input_boolean.radio_mini_quarto
        tap_action:
          action: call-service
          service: input_boolean.toggle
          service_data:
            entity_id: input_boolean.radio_mini_quarto
    show_icon: true
    show_name: true
    show_state: false
    style: |
      ha-card {
        border-radius: 30px;
      }
    type: glance
  - card:
      entities:
        - entity: sensor.radio_sala
          tap_action:
            action: none
        - entity: input_number.radio_volume_mini_sala
          tap_action:
            action: none
        - entity: input_select.radio_estacao_sala
          tap_action:
            action: call-service
            service: script.radio_sala
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_boolean.radio_mini_sala
        state: 'on'
    type: conditional
  - card:
      entities:
        - entity: sensor.radio_cozinha
          tap_action:
            action: none
        - entity: input_number.radio_volume_mini_cozinha
          tap_action:
            action: none
        - entity: input_select.radio_estacao_cozinha
          tap_action:
            action: call-service
            service: script.radio_cozinha
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_boolean.radio_mini_cozinha
        state: 'on'
    type: conditional
  - card:
      entities:
        - entity: sensor.radio_wc
          tap_action:
            action: none
        - entity: input_number.radio_volume_mini_wc
          tap_action:
            action: none
        - entity: input_select.radio_estacao_wc
          tap_action:
            action: call-service
            service: script.radio_wc
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_boolean.radio_mini_wc
        state: 'on'
    type: conditional
  - card:
      entities:
        - entity: sensor.radio_quarto
          tap_action:
            action: none
        - entity: input_number.radio_volume_mini_quarto
          tap_action:
            action: none
        - entity: input_select.radio_estacao_quarto
          tap_action:
            action: call-service
            service: script.radio_quarto
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_boolean.radio_mini_quarto
        state: 'on'
    type: conditional
  - card:
      entities:
        - entity: input_text.radio_1
        - entity: input_text.radio_url_1
        - entity: input_text.radio_2
        - entity: input_text.radio_url_2
        - entity: input_text.radio_3
        - entity: input_text.radio_url_3
        - entity: input_text.radio_4
        - entity: input_text.radio_url_4
        - entity: input_text.radio_5
        - entity: input_text.radio_url_5
        - entity: script.radio_reset
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_select.radio_estacao_sala
        state: '[[ Editar Rádios ]]'
    type: conditional
  - card:
      entities:
        - entity: input_text.radio_1
        - entity: input_text.radio_url_1
        - entity: input_text.radio_2
        - entity: input_text.radio_url_2
        - entity: input_text.radio_3
        - entity: input_text.radio_url_3
        - entity: input_text.radio_4
        - entity: input_text.radio_url_4
        - entity: input_text.radio_5
        - entity: input_text.radio_url_5
        - entity: script.radio_reset
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_select.radio_estacao_cozinha
        state: '[[ Editar Rádios ]]'
    type: conditional
  - card:
      entities:
        - entity: input_text.radio_1
        - entity: input_text.radio_url_1
        - entity: input_text.radio_2
        - entity: input_text.radio_url_2
        - entity: input_text.radio_3
        - entity: input_text.radio_url_3
        - entity: input_text.radio_4
        - entity: input_text.radio_url_4
        - entity: input_text.radio_5
        - entity: input_text.radio_url_5
        - entity: script.radio_reset
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_select.radio_estacao_wc
        state: '[[ Editar Rádios ]]'
    type: conditional
  - card:
      entities:
        - entity: input_text.radio_1
        - entity: input_text.radio_url_1
        - entity: input_text.radio_2
        - entity: input_text.radio_url_2
        - entity: input_text.radio_3
        - entity: input_text.radio_url_3
        - entity: input_text.radio_4
        - entity: input_text.radio_url_4
        - entity: input_text.radio_5
        - entity: input_text.radio_url_5
        - entity: script.radio_reset
      style: |
        ha-card {
          border-radius: 30px;
        }
      type: entities
    conditions:
      - entity: input_select.radio_estacao_quarto
        state: '[[ Editar Rádios ]]'
    type: conditional
  - text: ♬
    type: 'custom:text-divider-row'
type: vertical-stack

Com os rádios todos desligados fica assim…

1 Curtiu

Muito obrigado pela partilha.

1 Curtiu

Muito bom !!!
E para a Alexa , alguém tem ?

Obrigado.

Obrigada.

Eu só tenho Google’s minis mas supostamente também deve funcionar com a alexa…

Eu nos Mimis ativo os booleana através da voz e ligo o rádio do HA e supostamente o Google agora também suporta os input_select o que dá pra trocar a rádio mas ainda não testei…

1 Curtiu

Tópico interessante para quem tem várias colunas e pretende ouvir rádio. A nível de interface, penso que seria interessante selecionar na rádio logo na parte onde as colunas são activadas/desativadas. Mas ideia tá muito fixe!

Boas. Para tocares a mesma rádio em todas as colunas de forma a que fiquem em sintonia basta criar um grupo na app Home. Esse grupo vai aparecer automaticamente no HA.

Boas.
E dá para tocar o áudio dos videos do youtube em nest minis?
E dará para usar nest minis em conjunto com echo dots tipo multiroom?
Obrigado!

Boa noite.

Interajo com o Há via Google Assistant à algum tempo e via vários dispositivos, no entanto pretendo começar a adicionar “smart speakers”, mas tenho algumas dúvidas.

Esta solução funciona com qualquer coluna que suporte Google Assistant?

Estou a ponderar adquirir a Xiaomi Smart Speaker IR.
Irá funcionar?

E se de futuro comprar outro modelo, por exemplo a Nest Mini. O multiroom irá funcionar bem?


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


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