3 minutes

Do not disturb signSometimes, I want to have some time on my own. Watch a movie or series without interruptions of my phone. So, I created two automations in Home Assistant which turn on and off do not disturb on my phone in specific situations. It worked great, with one big exception. Home Assistant did just send commands. It couldn’t tell me if my phone was on do not disturb mode. Until, I found a sensor which just does exactly that. Time to improve and create a dedicated switch for it in Home Assistant.

The advantage of a dedicated switch for do not disturb in home Assistant is that it will be possible to trigger automations by toggling do not disturb on your phone. It’s also possible to connect more than one phone or other devices like smart speakers, smart doorbells, intercoms, e.g. to this switch. You can add a device tracker as a condition, so that do not disturb will only be triggered when the specific phone is at home. I didn’t do that, because I’m the only person living in my apartment.

Let’s imagine that you’re coming home late. Your partner is already asleep, so the do not disturb switch will be enabled. It didn’t activate do not disturb on your phone, since you were not home at the time, but you can set up another automation which will activate DND as soon as the device tracker of your phone reports home and the DND switch is on. This way, you’ll never have to worry about your sleeping partner and an accidental loud ringtone again.

For the switch, I’m still using the webhook service to toggle the do not disturb mode on my phone. As far as I know, this function is only available for Android phones. There are a lot of tutorials how to set up a webhook and how to trigger do not disturb via IFTTT, so I’m not going into that. The switch value is the do not disturb sensor, which I found within Home Assistant. When DND is turned on, the sensor state will be ‘priority_only’. This way the switch knows if it needs to be in the on or off position. This switch looks as follows in my configuration file.

# Switch example
switch:
  - platform: template
    switches:
      do_not_disturb:
        friendly_name: "Do not disturb"
        value_template: "{{ is_state('sensor.pixel_2_xl_do_not_disturb_sensor', 'priority_only') }}"
        turn_on:
          service: rest_command.do_not_disturb_on
        turn_off:
          service: rest_command.do_not_disturb_off

To enable do not disturb on my Amazon Echo’s, I also created a motion sensor to trigger routines.

# Binary sensors
  - platform: template
    sensors:
      do_not_disturb:
        friendly_name: "Do not disturb sensor"
        device_class: motion
        value_template: "{{ is_state('switch.do_not_disturb', 'on') }}"

I already had two automations which toggled do not disturb. So, I only had to upgrade these with the new switch I made. I am taking this opportunity to share these automations with you.

There are several moments on which I want do not disturb to be enabled. When I sleep, when I watch tv (See cinematic experience), when I take a shower or when I record voice-overs. To turn on do not disturb, the automation looks as follows:

  alias: Turn on do not disturb
  description: ''
  trigger:
  - entity_id: input_boolean.night_mode
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: input_boolean.shower_mode
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: input_boolean.home_theater
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: binary_sensor.bedroom_tv
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: input_boolean.recording_mode
    from: 'off'
    platform: state
    to: 'on'
  condition: []
  action:
  - data: {}
    entity_id: switch.do_not_disturb
    service: switch.turn_on
  mode: single

Turning off do not disturb is a little more tricky. I wanted DND only to turn off when all the situations above are false. What I don’t want to happen for example is that DND is turned off after I turned off my tv and night mode is enabled. That would be a real bug. That’s why I added so many conditions in the automation below.

  alias: Turn off do not disturb
  description: ''
  trigger:
  - entity_id: input_boolean.night_mode
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: input_boolean.shower_mode
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: input_boolean.home_theater
    from: 'on'
    platform: state
    to: 'off'
  - entity_id: binary_sensor.bedroom_tv
    from: 'off'
    platform: state
    to: 'on'
  - entity_id: input_boolean.recording_mode
    from: 'on'
    platform: state
    to: 'off'
  condition:
  - condition: state
    entity_id: input_boolean.night_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.shower_mode
    state: 'off'
  - condition: state
    entity_id: input_boolean.home_theater
    state: 'off'
  - condition: state
    entity_id: binary_sensor.bedroom_tv
    state: 'on'
  - condition: state
    entity_id: input_boolean.recording_mode
    state: 'off'
  action:
  - data: {}
    entity_id: switch.do_not_disturb
    service: switch.turn_off
  mode: single

I also created two Alexa routines to toggle do not disturb on my smart speakers.

That’s how my improved DND switch is set up in Home Assistant. Questions or recommendations? Please let me know! I’m human, and humans dome mistakes from time to time.