Mute media player when on phone, only when home

Get started

Click the badge to import this Blueprint: (needs Home Assistant Core 2021.3 or higher)

Open your Home Assistant instance and show the blueprint import dialog with a specific blueprint pre-filled.

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

I converted my “Mute media player when on phone, only when home” to a blue print so its available for everyone to use or get inspiration.

Inputs:

  • Phone State sensor from Android app
  • Person to check if zone is home
  • Media player to mute

I choose mute instead of play/pause. This might work better in some cases when streaming.

10 Likes

No valid blueprint found in the topic. Blueprint syntax blocks need to be marked as YAML or no syntax.

1 Like

You can import the gist, but now I also added the yaml in the post

Hello, great idea and it even works right away.
It would be nice if you could still adjust the zone.
At home is okay, but far better if you could use smaller zones

Thanks for the suggestion, i’ve added the zone option. Default zone is home

is there a phone_state that works for iOS?

1 Like

According to the docs, it’s Android only

Hmm, problem is, the zone is an input now, so the value is zone.home. But the condition uses the platform state, and there the value is home. Any one here an idea how to add the zone as a condition? If there is no solution, I can use a template thingy to remove the zone. part, but I hope there is a more elegant solution.

Hi @JackPoint
I post a comment on your git to resolve the zone problem, it works, but it’s using a “template thingy” :wink:

1 Like

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

It doesn’t work for a Spotify media player.
Maybe it’s because it has no mute service?

I think so. I’ve tested it from the developer tools, no error but also no mute action or something.

Can you advise how to rewrite it to play/pause instead of mute?
BTW! maybe it would be good idea to make user be able to choose between pause and mute while creating automation from the blueprint?

Nice Blueprint. This was the first one I tried :cowboy_hat_face:. You’re a natural. Using your inspiration I tried to make a blueprint with volume.set instead of mute but it didn’t work. Do you have the time to add another one with a volume set?

tried many times, but no luck.
My media is TV samsung (integrated).
phone is set up in integration and has sensor.state active. I’m seen as home since 4 hours. I tried to call and to be called, nothing. My phone state is going from idle to webhook
What should i check ?

@CAHTA You can replace the media_player.volume_mute service calls with media_player.media_play_pause.

@Quasimodo Thanks! At first I build one with a volume.set but that’s a bit more complex because you need to remember the volume level before turning it down. That’s why I decided to use mute instead.

@Adrian_Stanciu You need to select the phone state sensor. Check the state of the sensor when making a call, it should change from idle to offhook. If that works, check if your media player supports muting. You can try it with the developer tools. (service: media_player.volume_mute fill it with the example data and change it to your media player. If that works, check if the person you selected is in the zone you selected. The developer tools list it without the zone. part. If this all works, but the media player doesn’t mute on a call, check your logs.

1 Like

I wrote that i have:

  • a phone state sensor which turns from idle to webhook ;
  • a tv integrated (samsung smart that supports mute) ;
  • person which is home.

I called the service media_player.volume_mute and it works.

The sensor value turns to webhook? Is that an auto complete error and you mean offhook?

Did you validate and reload the automations after adding it?

The blueprint is updated a few times, make sure you’re using the last version. Remove and add it again if you’re not sure.

I wrote in initial post…phone state value changes from idle to webhook.
I reinstalled and reloaded automations 1 hour ago.

According to the docs, webhook isn’t a valid state for that sensor. This blueprint/automation isn’t listing to that event change, only to ringing and offhook.