Be Smart, Go Local.

How To Control Your Phone with Home Assistant

We’ve all been using our mobile devices to control Home Assistant, but what about controlling our mobile devices with Home Assistant?

We’ve all been using our mobile devices to control Home Assistant, but what about controlling our mobile devices with Home Assistant?

As is turns out, setting ringer volume and mode, changing media, notifications control, starting and stopping apps, updating sensors, polling for location and adjusting screen settings are some of the things you can control on your mobile device with Home Assistant.

Control Phone with Home Assistant: Featured Image

This article is a deep dive with examples of how to control Android and iOS devices through notification commands in Home Assistant, without third party integrations or components.

Also check out: Voice Calling Home Assistant With An Old Phone

Why control your phone through HA?

Home Assistant is already well known for replacing a million different smart home apps and bringing all smart devices under one umbrella, rightfully regarded as the ultimate platform for Home Automation.

By using Home Assistant to control a mobile device, you get some remote functionality that you would normally need another app for. So, even though controlling mobile devices is not the focus of Home Assistant, it can probably replace a couple of apps on your phone like family trackers or find-my-phone apps.

It’s important to note that these particular service calls are executed through notification commands which operate within the constraints of the operating system (Android, iOS) so they are limited in certain ways, although still very very useful.

Requirements

The are certain requirements that need to be met before notification commands can be used on your mobile device. Some are OS dependent, others are permission dependent and some are limited by the state of the companion app. I will explain how each individual commands works and what’s required, but in general you need:

  • Home Assistant Companion App Installed
  • All permission granted to the Companion App
  • Required sensors enabled in the app
  • Android or iOS (Limited functionality)

Notification Command Types and Examples

Each notification command sends a specific payload through a service call in Home Assistant, so rather than displaying an actual notification on the device, you have the option to send a command with a message payload to initiate specific actions on your phone.

Clearing Notifications

You can automatically clear notifications on Android and iOS by defining a tag when initially sending the notification. Some platforms may need you to have recently used the companion app to clear notifications. This is true for all iOS notifications and non-critical Android notifications. Let’s say you are sending this simple notification:

Works with Android OS Logo SmartHomeScene Apple iOS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  title: "Living Room Light"
  message: "Living Room Light Was Turned On"
  data:
    tag: "living-room-light" #Define a tag

Now in order to clear this notification remotely, you need to send the same tag which was sent in the original message:

service: notify.mobile_app_sm_g998b
data:
  message: "clear_notification"
  data:
    tag: "living-room-light" #Send the same tag

On iOS, you can also silently clear the badge from the app icon without displaying a notification:

Works with Apple iOS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "clear_badge"

Request Location Update

This command will force request a location update from your mobile device, by sending a notification command not visible to the device owner and only works when the app is running in the foreground or background.

If your device gets the notification, it will try to find its location within 5 seconds and send it to Home Assistant. However, it might not always work perfectly on iOS because Apple limits the time the app can interact with the notification, and delays in location updates can happen, like waiting for GPS to connect.

Works with Android OS Logo SmartHomeScene Apple iOS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "request_location_update"

Since GPS is very battery hungry, it’s not advisable to use this in an Automation and request location at frequent intervals. This command can seriously affect the battery life and health of your phone, so it’s better to manually trigger it when needed.

Set High Accuracy Mode

Control Phone with Home Assistant: High Accuracy Mode

You can also control the high accuracy mode of the background location sensor by using the command_high_accuracy_mode message with commands like turn_off, turn_on, force_off, or force_on. This can be useful before requesting a location update, if you want to get a precise update.

The difference between turn and force only matters when zone and/or Bluetooth constraints are configured. When using force_on, high accuracy mode stays active until receiving force_off or when constraints shift from active to inactive. Similarly, force_off deactivates high accuracy mode until either force_on is sent or the constraints change from inactive to active.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_high_accuracy_mode"
  data:
    command: "turn_off"

In addition to toggling the high accuracy mode on or off, you can also change the reporting time of the high accuracy sensor, whose value cannot be lower than 5.

service: notify.mobile_app_sm_g998b
data:
  message: "command_high_accuracy_mode"
  data:
    high_accuracy_update_interval: 60
    command: "high_accuracy_set_update_interval"

Request Sensors Update

This basic command will check for updates from all active sensors enabled in the Companion App and, if the present state differs from the previous one, it will update their status in Home Assistant.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_update_sensors"

Set Ringer Mode

Control Phone with Home Assistant: Ringer Mode

This command can remotely change the ringer mode of your phone to normal, vibrate or silent. Some devices may require you to give a special permission. If you haven’t granted it yet, a request for permission will pop up when you send the first command.

This command also affects Do Not Distrurb mode on Android devices: If the device is in Do Not Disturb mode, changing it to normal or vibrate will turn it off. If it’s not in Do Not Disturb mode, selecting silent will turn it on.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_ringer_mode"
  data:
    command: "normal"
#Change with "vibrate" or "silent"

Set Do Not Disturb mode

Control Phone with Home Assistant: Do Not Disturb mode

Do Not Disturb mode can be controlled on android devices with a notification command but in addition to sending the message payload, you must also provide a command state, one of the following:

  • alarms_only
    • Blocks all notifications except those in the alarm category. It also mutes some audio streams.
  • priority_only
    • Blocks all notifications except those in the priority category. It also mutes some audio streams.
  • total_silence
    • Blocks all notifications, mutes all audio streams (except for phone calls), and stops vibrations.
  • off
    • Normal filter – no notifications are suppressed.

To use this command, you need to grant a specific permission which the app can’t prompt or automatically accept. When you send the command for the first time, the app will open an activity, prompting you to allow Home Assistant access to the device’s Notification Policy. This is necessary for the app to take control of this setting.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_dnd"
  data:
    command: "priority_only"
#Change with "alarms_only", "total_silence" or "off" 

Apps Control

To launch an app on your Android device, you can simply send a message payload with the app package name. This command requires the Draw Over Other apps permission, which is request when first executing the command:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_launch_app"
  data:
    package_name: "com.twitter.android"

The Home Assistant companion app has a built in app-lock setting which relies on your chosen phone lock method. You can control this behavior by sending a payload to enable, bypass or timeout the security lock in a single command:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_app_lock"
  data:
    app_lock_enabled: true
    app_lock_timeout: 60
    home_bypass_enabled: false

If you have a wall mounted tablet, you can navigate to a specific view or dashboard by executing a Webview command with a specified path. For example, to navigate to my custom dashboard I just copy the URL from the browser:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_webview"
  data:
    command: "/dashboard-smarthomescene/0"

Using the same command, you can also pop-up a more-info dialog window for a specified entity:

service: notify.mobile_app_sm_g998b
data:
  message: "command_webview"
  data:
    command: "entityId:weather.forecast_home" #Replace with Entity ID

Media Control

Users can manage ongoing media sessions on their devices by setting the message to command_media. Choose a media_command from the provided list, and specify the media_package_name with the package name you want to control. A list of app package names can be obtained with any of the package list apps from the Play Store. Accepted media commands:

  • fast_forward
  • next
  • pause
  • play
  • play_pause
  • previous
  • rewind
  • stop

For example, let’s say I want to control the current Spotify session and skip tracks:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_media"
  data:
    media_command: "next"
    media_package_name: "com.spotify.music"

Volume Control

Control Phone with Home Assistant: Volume Levels

You can also adjust your Android device’s volume levels by sending command_volume_level with a numerical command. If the value exceeds the maximum level, it defaults to the maximum; if less than 0, it defaults to 0. Some devices may require a special permission, similar to Do Not Disturb permission above which is granted when the first command is executed. The available media_stream payloads:

  • alarm_stream: Volume level for the alarm stream.
  • call_stream: Volume level for the voice call stream.
  • dtmf_stream: Volume level for DTMF tones.
  • music_stream: Volume level for the music stream.
  • notification_stream: Volume level for the notification stream.
  • ring_stream: Volume level for the ring stream.
  • system_stream: Volume level for system stream.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_volume_level"
  data:
    media_stream: "music_stream" #Music volume level
    command: 20
service: notify.mobile_app_sm_g998b
data:
  message: "command_volume_level"
  data:
    media_stream: "ring_stream" #Ringer volume level
    command: 10

Screen Control

Control Phone with Home Assistant: Brightness

If you have a wall mounted tablet and you are using the Companion App to display your dashboard, you can control the screen of the device remotely. For example, you can turn_on or turn_off the auto-screen brightness:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_auto_screen_brightness"
  data:
    command: "turn_on"

To change the screen brightness level, you can send a payload with value between 0 – 255:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_screen_brightness_level"
  data:
    command: 255 #Max brightness

To change the built in screen timeout setting, you can send a payload in milliseconds which respect the built-in options of the device. For example, I wanted to set timeout to 1 minute:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_screen_off_timeout"
  data:
    command: 60000 #60000ms = 60sec
Control Phone with Home Assistant: Screen Timeout

On Android, you can turn on the screen by sending a notification with the message command_screen_on. It’s important to note that this action does not remove or disable any lock screens you may have configured on your device.

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_screen_on"

Additionally, you can control the Keep Screen On setting in the companion app, which just keeps the screen alive as long as you are looking at a dashboard:

Works with Android OS Logo SmartHomeScene

service: notify.mobile_app_sm_g998b
data:
  message: "command_screen_on"
  data:
    command: "keep_screen_on" #Use keep_screen_off for turning the setting off

Bluetooth Control

Control Phone with Home Assistant: Bluetooth

On Android 12 or older devices, you can toggle Bluetooth On or Off by sending this message:

Works with Android OS Logo SmartHomeScene ≤ 12

service: notify.mobile_app_sm_g998b
data:
  message: "command_bluetooth"
  data:
    command: "turn_off"

Apple Watch Complications

Complications in the Home Assistant Apple Watch App enable you to display the values of your Home Assistant sensors directly on your Apple Watch face. To generate complications, use the Home Assistant Companion App on a connected iPhone through the Apple Watch page within the Configuration section of the Companion App. You can refresh complications with the following command:

Works with Apple iOS Logo SmartHomeScene Watch

service: notify.mobile_app_sm_g998b
data:
  message: update_complications

Automations and Scripts

Each of these service calls can be used in automations or scripts in Home Assistant, which can be helpful if you want to automate certain aspects of your wall mounted dashboard or your phone GPS tracker for example.

For example, let’s say I want to set brightness to the maximum on my wall mounted tablet whenever someone approaches and keep the screen on. This way, everything is visible for a few minutes when it’s being controlled and goes back to auto-brightness when no one is around. I am using a DIY LD2410 to detect motion/presence:

description: Set Brightness to 255 when presence is detected
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.diy_ld2410_presence
    from: "on"
condition: []
action:
  - service: notify.mobile_app_sm_g998b
    data:
      message: command_screen_brightness_level
      data:
        command: 255
  - service: notify.mobile_app_sm_g998b
    data:
      message: command_screen_on
      data:
        command: keep_screen_on

And whenever presence is cleared (controlled through the presence keep time parameter of the LD2410), I just send the auto-brightness turn_on message and keep_screen_off:

description: Set Brightness to 255 when presence is detected
mode: single
trigger:
  - platform: state
    entity_id:
      - binary_sensor.diy_ld2410_presence
    from: "off"
condition: []
action:
  - service: notify.mobile_app_sm_g998b
    data:
      message: command_auto_screen_brightness
      data:
        command: turn_on
  - service: notify.mobile_app_sm_g998b
    data:
      message: command_screen_on
      data:
        command: keep_screen_off

As script example, let’s assume I want to periodically request a Location Update from a mobile device. I don’t want to do it too often, as this can cause issues and diminish my battery health and lifespan. So I will create a script that I will manually trigger from Home Assistant:

alias: Request location update
sequence:
  - service: notify.mobile_app_sm_g998b
    data:
      message: request_location_update
mode: single
icon: mdi:map-marker-plus

Summary

Whenever you send a message payload to your mobile device through a service call in Home Assistant and it gets displayed as an actual notification, you know the notification command has failed. That’s your cue you have a mistake or a typo.

If a command was successful, no notification will be shown and the wanted action will just be executed on your device. The full documentation for notification commands in Home Assistant can be found on the official Companion Apps portal.

Controlling iOS devices through notification commands is severely limited compared to Android, this is just an OS constraint that limits apps in certain ways. You can use Shortcuts to achieve the same things from the examples above, albeit with another app.

2 thoughts on “How To Control Your Phone with Home Assistant”

  1. Wow, ‘Request Sensors Update’ helped me fix infrequent updates from my watch. I created a script and an automation to update every so often – perfect.

  2. Hey.

    Very nice and useful post. Good for you.

    I locked my HA application and it worked fine.

    Now I want to remove this lock and can’t. How do you remove the lock?

    Thanks!

Comments are closed.