How can door bell mute when I open the door

My doorbell automation play doorbell.mp3 on Google home speaker when push the doorbell button. I want when I open the door my door bell will mute.
Do I need separate automation or is that possible in template ?

Here is my doorbell automation

- id: '16097843297'
  alias: Doorbell
  description: ''
  trigger:
  - entity_id: binary_sensor.doorbell
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - service: media_player.play_media
    data:
      entity_id: media_player.home_assistant_speaker
      media_content_id: https://xxx.duckdns.org/local/doorbell/doorbell.mp3
      media_content_type: music
  mode: single

Use wait for trigger, and set the trigger to the door changing from closed to open. Set the timeout to the length of the audio clip, and don’t continue on timeout. Then just use media_player.volume_set and set it to 0. Add a delay for 10 seconds (or something like that) and then call media_player.volume_set again.

1 Like

Do you mean make another automation?

No, add more stuff to the end of your automation.

Not really useful imo. He wants it mute when it’s playing and he opens the door. In other words, if he doesn’t open, the doorbell.mp3 file must continue to play. So no timeouts

One way would be, when door sensor is triggered, then mute volume. Only bad thing about this is that the speaker remains muted (vol 0) and you have to raise volume again. entity id is “home_assistant_speaker”? So i assume a dedicated speaker for HA only? If so, put vol at X when starting the automation so you don’t have that issue.

Other way could be, as you play media, when door sensor triggered end it. You could achieve this by putting an extra trigger check, if doorsensor from off to on (closed to open) and in thee action use if is_state and define when door closed, doorbell press. play sound. and other if, if playing and door sensor == on (or open) then command would be to end the media player.

Once you call the media_player.play_media service, it continues to play, no matter what happens.

Needs a bit rebuilding but the action should come after defined if statement. And you have media_play_pause or media_pause

With the help of some input booleans


action:
  - service_template: >
      {% if is_state('media_player.home_assistant_speaker', 'playing') %}
        input_boolean.turn_on
      {% else %}
        input_boolean.turn_off
      {% endif %}
    entity_id: input_boolean.media_was_playing
  - ...

Thanks @KTibow @Vasco

Here is my working Automation

alias: Doorbell
description: ''
trigger:
  - entity_id: binary_sensor.doorbell
    from: 'off'
    platform: state
    to: 'on'
condition: []
action:
  - service: media_player.volume_set
    entity_id: media_player.home_assistant_speaker
    data:
      volume_level: 0.9
  - service: media_player.play_media
    data:
      entity_id: media_player.home_assistant_speaker
      media_content_id: 'https://xxx.duckdns.org/local/doorbell/doorbell.mp3'
      media_content_type: music
  - wait_for_trigger:
      - platform: state
        entity_id: binary_sensor.front_door
        from: 'off'
        to: 'on'
    continue_on_timeout: false
  - service: media_player.volume_set
    data:
      volume_level: 0
    entity_id: media_player.home_assistant_speaker
mode: single