Skip to content

Instantly share code, notes, and snippets.

@ludeeus
Last active December 15, 2020 09:55
Show Gist options
  • Save ludeeus/58ab08b94424c12a8f911e932eb2f46a to your computer and use it in GitHub Desktop.
Save ludeeus/58ab08b94424c12a8f911e932eb2f46a to your computer and use it in GitHub Desktop.
Home Assistant Blueprint: Pause Playing Media During Calls
blueprint:
name: Pause Playing Media During Calls
description: >
Automatically pause the playing media when you get a call!
Currently this only works with the Home Assistant Companion app for Android.
domain: automation
input:
phone_state_sensor:
name: Phone state sensor
description: >
Select the sensor that holds the phone state you want to track.
selector:
entity:
domain: sensor
media_player:
name: Media player
description: Select media player to control. This will only work for entities, not areas or devices.
selector:
target:
entity:
domain: media_player
variables:
players: !input media_player
playing: >
{{ dict((states.media_player|selectattr('entity_id', 'in', players.entity_id)|list )|groupby('state'))['playing']|map(attribute='entity_id') | list }}
trigger:
platform: state
entity_id: !input phone_state_sensor
from: idle
condition:
condition: template
value_template: "{{ (playing | count) != 0 }}"
action:
- service: media_player.media_pause
data:
entity_id: "{{ playing }}"
- wait_for_trigger:
- platform: template
value_template: "{{ states[trigger.entity_id].state == 'idle' }}"
- service: media_player.media_play
data:
entity_id: "{{ playing }}"
@JackPoint
Copy link

Here is some inspiration with my version, it uses mute and checks if the person is at home: https://gist.github.com/JackPoint/2375dd5d15f0b4c52161207170c14f60

Nice solution for the multi media player is playing check btw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment