Last active
December 8, 2022 18:13
-
-
Save JackPoint/2375dd5d15f0b4c52161207170c14f60 to your computer and use it in GitHub Desktop.
HomeAssistant Blueprint - Mute media player when phone rings or is calling. Only when person is home and the mediaplayer is playing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
blueprint: | |
name: Mute mediaplayer when calling. | |
description: > | |
Mute a mediaplayer when phone rings or is calling. | |
Only when person is home and the mediaplayer is playing. | |
domain: automation | |
input: | |
phone_state: | |
name: Phone State sensor | |
description: All sensors form the mobile app. Select the phone state sensor here. | |
selector: | |
entity: | |
integration: mobile_app | |
domain: sensor | |
person: | |
name: Person | |
description: Select the person that needs to be at the zone selected. | |
selector: | |
entity: | |
domain: person | |
zone: | |
name: Zone | |
description: Select the Zone the person needs to be in. | |
default: zone.home | |
selector: | |
entity: | |
domain: zone | |
media_player: | |
name: Media Player | |
description: Select the media player that needs to be muted. | |
selector: | |
entity: | |
domain: media_player | |
trigger: | |
- platform: state | |
entity_id: !input phone_state | |
to: "ringing" | |
- platform: state | |
entity_id: !input phone_state | |
to: "offhook" | |
variables: | |
zone: !input zone | |
zone_name: "{{ zone[5:] }}" | |
entity: !input person | |
condition: | |
- "{{is_state(entity, zone_name)}}" | |
- condition: state | |
entity_id: !input media_player | |
state: playing | |
action: | |
- service: media_player.volume_mute | |
entity_id: !input media_player | |
data: | |
is_volume_muted: true | |
- wait_for_trigger: | |
- platform: state | |
entity_id: !input phone_state | |
to: "idle" | |
timeout: | |
seconds: 300 | |
- service: media_player.volume_mute | |
entity_id: !input media_player | |
data: | |
is_volume_muted: false |
This should resolve the zone issue. It's not that best approach, but should do the job
trigger:
- platform: state
entity_id: !input 'phone_state'
to: ringing
- platform: state
entity_id: !input 'phone_state'
to: offhook
variables:
zone: !input zone
zone_name: "{{ zone[5:40] }}"
condition:
- condition: state
entity_id: !input 'person'
state: >-
{{ zone_name }}
- condition: state
entity_id: !input 'media_player'
state: playing
Thanks! I’ve updated this gist and the HA community page here with your suggestion.
Calling the media_player.volume_mute service twice will cause a warning in the log that the service is already running.
It can be removed somehow. I can't figure it out.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks for the suggestion, ill add it!