Affect change on my phone with home assistant?

Tonight, as I was driving, I was thinking about how it might be good if I could automate toggling do-not-disturb mode on my phone when I was in the car by the state of the “detected activity” sensor. This way I wouldn’t get bothered by non critical notifications while driving.

Is this sort of thing even possible with home assistant?

Yep, you can send commands via notifications:

2 Likes

This is outstanding. The more I dig into it, the more impressed I amm with Home Assistant - and now the Home Assistant App as well does this? :grinning: :grinning: :grinning: :grinning: :grinning:

This did the trick for me. I have yet to test this out while driving, but here’s the bones of the automation.

I have plans to make this into a blueprint so that my wife can use it as well, but it’s just for me for now. I’d need parameters for the phone detected activity sensor, a helper for caching the value of the sensor, and the name of the notify service for the phone.

Automation YAML

alias: steve_dnd_while_driving
description: "Enable Do-Not-Disturb mode while driving"
trigger:
  - platform: state
    entity_id:
      - sensor.steve_galaxy_s23_detected_activity
    to: in_vehicle
    id: driving
  - platform: state
    entity_id:
      - sensor.steve_galaxy_s23_detected_activity
    id: not_driving
    from: in_vehicle
    for:
      hours: 0
      minutes: 2
      seconds: 0
condition: []
action:
  - choose:
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'driving' }}"
            alias: "sensor detected driving activity"
          - condition: state
            entity_id: sensor.steve_galaxy_s23_do_not_disturb_sensor
            state: "off"
        sequence:
          - service: input_text.set_value
            target:
              entity_id: input_text.steve_do_not_disturb
            data:
              value: "{{ states('sensor.steve_galaxy_s23_do_not_disturb_sensor') }}"
            alias: "Save previous value of do-not-disturb sensor"
          - service: notify.steve
            data:
              message: command_dnd
              data:
                command: priority_only
            alias: "Set do-not-disturb to Priority Only"
        alias: We're driving
      - conditions:
          - condition: template
            value_template: "{{ trigger.id == 'not_driving' }}"
          - condition: not
            conditions:
              - condition: state
                entity_id: input_text.steve_do_not_disturb
                state: ""
            alias: "Saved value of do-not-disturb is not empty"
        sequence:
          - alias: Set do-not-disturb to 'off'
            service: notify.steve
            data:
              message: command_dnd
              data:
                command: "{{ states('input_text.steve_do_not_disturb') }}"
          - service: input_text.set_value
            target:
              entity_id: input_text.steve_do_not_disturb
            data:
              value: ""
            alias: "Clear saved do-not-disturb value"
        alias: We've stopped driving
mode: queued
max: 10