Do not disturb mode of the phone as a switch

Hi, how could I convert my cell phone’s “Do Not Disturb” sensor into an on and off switch?
The sensor is called:

sensor.s9_do_not_disturb_sensor

When the sensor is off, I would like the switch to go off, when it is in “priority_only” (it is called this on the history when the do not disturb mode is activated) the switch to go on.

Just create a Template Switch: Template Switch - Home Assistant
The first example in that is just what u need. Just replace the sensor with your phone DND sensor.

Ok, I put this:

# cell switch s9+
  - platform: template
    switches:
      s9_do_not_disturb_sensor:
        value_template: "{{ is_state('sensor.s9_do_not_disturb_sensor', 'on') }}"
        turn_on:
          service: switch.turn_on
          target:
            entity_id: switch.not_disturb_on
        turn_off:
          service: switch.turn_off
          target:
            entity_id: switch.not_disturb_off

But it doesn’t work, when I do the validation it says:

Invalid config for [binary_sensor.template]: [switches] is an invalid option for [binary_sensor.template]. Check: binary_sensor.template->switches. (See ?, line ?).

Well, what do you want to do with it? Does the entity switch.not_distrurb_on exsists?
If not you will need to create that with an helper.
Normal usecase for this is to turn a non switch into a switch, but in general you would use automation for that and use the sensor.s9_do_not_disturb_sensor as atrigger and condition.
For example, turning on the garden light when i charge my phone wireless :smiley:

alias: Test
description: ''
trigger:
  - platform: state
    entity_id: sensor.toestel_1_charger_type
condition: []
action:
  - choose:
      - conditions:
          - condition: state
            entity_id: sensor.toestel_1_charger_type
            state: wireless
        sequence:
          - type: turn_on
            device_id: cd77c64a0eb1c52c1db5808efa1e8608
            entity_id: light.tuinverlichting
            domain: light
    default:
      - type: turn_off
        device_id: cd77c64a0eb1c52c1db5808efa1e8608
        entity_id: light.tuinverlichting
        domain: light
mode: single

It works, in my case I did it like this:

- id: '1648995568523'
  alias: '[Non disturbare] "Non disturbare" su cellulare'
  description: ''
  trigger:
  - platform: state
    entity_id: sensor.s9_do_not_disturb_sensor
  condition: []
  action:
  - choose:
    - conditions:
      - condition: state
        entity_id: sensor.s9_do_not_disturb_sensor
        state: priority_only
      sequence:
      - service: input_boolean.turn_on
        data: {}
        target:
          entity_id: input_boolean.buonanotte
    default:
    - service: input_boolean.turn_off
      data: {}
      target:
        entity_i

but I would also like the inverse function, if I turn the input boolean on or off, the do not disturb mode on the mobile phone is activated or deactivated

Thats not possible via the app, maybe via something like Tasker

It is with Android.

            - service: notify.mobile_app_sphone
              data:
                message: command_dnd
                title: off
2 Likes

No it’s possible

I was able to find a guide, so it works:

alias: test on
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.buonanotte
    from: 'off'
    to: 'on'
condition: []
action:
  - service: notify.mobile_app_s9
    data:
      message: command_dnd
      title: priority_only
mode: single

alias: test off
description: ''
trigger:
  - platform: state
    entity_id: input_boolean.buonanotte
    from: 'on'
    to: 'off'
condition: []
action:
  - service: notify.mobile_app_s9
    data:
      message: command_dnd
      title: 'off'
mode: single

This is the site where in case you are interested: Notification Commands | Home Assistant Companion Docs

Anyway, thank you for the automation you suggested to me earlier!

1 Like

Thanks anyway, I found it just before you answered!

For the record, Do not disturb isn’t actually a boolean. There are 4 possible states it could be in:

  • off
  • alarms_only
  • priority_only
  • total_silence

I suppose you could coerce it into a boolean if you want by treating everything not off as on. For me, I just have this select in my system:

template:
  select:
    # Do Not Disturb control on mike's phone
    - name: Mikes phone do not disturb
      unique_id: b1effca8cc404280a65c24990375a8e0_select_mikes_phone_do_not_disturb
      state: "{{ states('sensor.mikes_phone_do_not_disturb') }}"
      availability: "{{ states('sensor.mikes_phone_do_not_disturb') not in ['unknown', 'unavailable'] }}"
      options: "{{ ['off', 'priority_only', 'alarms_only', 'total_silence'] }}"
      icon: >-
        {% if is_state('select.mikes_phone_do_not_disturb', 'off') %}
          mdi:minus-circle-off-outline
        {% else %}
          mdi:minus-circle-outline
        {% endif %}
      select_option:
        service: notify.mobile_app_mikes_phone
        data:
          message: command_dnd
          title: "{{ option }}"

This way I don’t even need an automation, it just handles itself.

2 Likes

You beat me to it. I was just putting one together in my own config to test it before posting!

Edit: Now that I think about it the mobile app integration should just provide this as a select out of the box…

Haha I am chatting with dshokouhi about that right now. I have a list of switches, selects, and numbers I made out of the sensors. Would be cool if mobile app provided those instead :slight_smile:

1 Like

Definitely! Send my +1 to him!

A lot of the stuff done my notification command could also probably be instantiated as entities. Volumes as number entities, location update as a button etc etc.

Looking forward to see what you guys do with it. :slight_smile:

O, thats nice. I was under the impression you needed a workaround based on previous posts about just this issue. But thanks for the correction, @dshokouhi too ofc.

In my opinion that would need a new “chapter” of the app since it’s not sensors anymore.
This would need to be “switches and controls” perhaps.

It would be nice and convenient to have some controls that way instead of using the notification commands all the time.

I’m receving this notification in the drawer, but the state of the DND switch does not change. I have Samsung Galaxy S20+ 5G. Is Samsung compatible with ‘command_dnd’ directive, or this is only for Pixel phones? The entity sensor however, shows the state I set on the phone. But I cannot change the state back, from HA towards Samsung.

thats your sign the command did not work, please paste the YAML you used so we can see if there is an issue with it. More than likely you are following something that was before a breaking change. Make sure to check the logs to ensure the format is correct as the example up above is not.

alias: DND ON
description: “”
trigger:

  • platform: state
    entity_id:
    • person.xxxx
      to: home
      condition:
  • condition: state
    entity_id: person.yyyy
    state: home
    action:
  • service: notify.mobile_app_galaxy_s20_5g
    data:
    message: command_dnd
    title: priority_only
    mode: single

I tried exactly like it is here or on some few other posts.

as mentioned in my post up above this is the old format, so anything you see in this thread is out of date. Please refer to the link for the updated format.

service: notify.mobile_app
data:
  message: command_dnd
  data:
    command: priority_only
1 Like