Hello Everyone,
I have few Chromecast speakers which are placed in different rooms. I play a stream from internet on these speakers. The stream plays an advertisement at random times. I use the below automation/script to mute the speaker when the advertisement starts to play and once the advertisement is finished the speaker is unmuted. The script works fine.
Is there a way to make the script generalised so that it checks which speaker or speakers is playing the advertisement and mute/unmute only that speaker or speakers?
Please guide.
alias: Mute On AD
description: ""
trigger:
- platform: template
value_template: >-
{{
state_attr('media_player.bedroom_speaker,'media_title')[-7:]=='Advert:'
or
state_attr('media_player.bedroom_speaker','media_title')[-11:]=='application'
or
state_attr('media_player.bedroom_speaker','media_title')[-7:]=='Premium'
}}
id: ad_start //ad starts
- platform: template
value_template: >-
{{
state_attr('media_player.bedroom_speaker','media_title')[-7:]!='Advert:'
and
state_attr('media_player.bedroom_speaker','media_title')[-11:]!='application'
and
state_attr('media_player.bedroom_speaker','media_title')[-7:]!='Premium'
}}
id: ad_end //ad ends
condition: []
action:
- choose:
- conditions:
- condition: trigger
id: ad_start
sequence:
- service: media_player.volume_mute
data:
is_volume_muted: true
target:
entity_id: media_player.bedroom_speaker
- conditions:
- condition: trigger
id: ad_end
sequence:
- service: media_player.volume_mute
data:
is_volume_muted: false
target:
entity_id: media_player.bedroom_speaker
default: []
mode: single