Skip to content

Instantly share code, notes, and snippets.

@JackPoint
Last active December 8, 2022 18:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save JackPoint/2375dd5d15f0b4c52161207170c14f60 to your computer and use it in GitHub Desktop.
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.
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
@RW-7
Copy link

RW-7 commented Dec 15, 2020

add
zone: name: Zone description: Select the Zone is needet. selector: entity: domain: zone

and bei state from home to !input zone
condition:

  • condition: state
    entity_id: !input person
    state: !input zone

@JackPoint
Copy link
Author

Thanks for the suggestion, ill add it!

@denkyem
Copy link

denkyem commented Dec 15, 2020

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


@JackPoint
Copy link
Author

Thanks! I’ve updated this gist and the HA community page here with your suggestion.

@pepe59
Copy link

pepe59 commented Dec 22, 2020

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