Skip to content

Android Devices 'Always On'

dcapslock edited this page Jun 4, 2025 · 2 revisions

Extensive review has been undertaken by @dcapslock, understanding everything about Android and options to assist in using Companion App in a Kiosk mode keeping the device on. I have both Virtual Android (Pixel Pro 9: API 36 "Baklava"; Android 16.0 with Google Play Store) and a real Samsung Galaxy Tab A9+. Methods described below are working on both devices.

Before I go further, I do not believe that there is any way to stop frozen state after 5 minutes of a browser visibility changing to hidden. What I have focussed on are ways to ensure Home Assistant stays visible and device on, or device can be woken and Home Assistant started.

Browser Only ?

Unless you are using Fully Kiosk Browser and have successfully kept your device alive with FKB settings, using a browser only cannot achieve a device always on. I could not find WakeLock API available on Chrome on Android. Since I have had good outcomes with Companion App, I have not ventured any further down this path.

Android Companion App

I have found the best option for Android is to use the Companion App. On a well behaving device all that you should need to do is set Keep screen on. This setting is found in Other Settings. This is where you can also set Fullscreen mode.

Image

Some important notes:

  1. The screen will only be kept on when a Dashboard is showing. If you go to an area of the Companion App like settings and not return to a Dashboard, the screen will not be kept on. This could be managed with an automation if desired.
  2. If the device is not plugged into a power source, it may doze at any time.
  3. The Android Companion App uses a development time setting to keep the screen on. This is not available to browser only setups.

Keeping the 'Lights On'

I have tested the best method to be able to wake up a device and start Home Assistant should it not stay in the foreground for any reason, though I found the Keep screen on setting to be reliable. You can wake up and start Home Assistant by using Notification Commands with the Android Companion App. Namely, command_screen_on and command_launch_app.

Android Companion App notifications can be set to be delivered by Google Firebase Cloud Messaging (FCM) or direct )(Local Push) Websocket. As devices set to be wall panels are likely on the same network, Websocket delivery is preferred. However, as described later, FCM may be used as a fallback when the device dozes off. I found that when the notification was received via Websocket, the command was 100% timely and reliable. However, when received via FCM, there were delays, though repeating for a few tries was always successful in the end.

Best practices for Websocket delivery is to set Always for Persistent connection:

  1. In Companion App Settings, click on your server under Servers & devices.
  2. In Other settings click Persistent connection.
  3. Click Always. If you have not set Home Assistant to run in background, you will be asked to set that permission.
  4. Use the Manage persistent connection notification link to setup options for the notification. It can be silent and you may wish to uncheck Show notification dot.

Once the persistent connection is set, you can use notification action in Home Assistant to send commands to the device. NOTE: Make sure to use ttl: 0 and priority: high to help timely delivery if FCM fallback is used for receiving the notification.

command_screen_on
  action: perform-action
  perform_action: notify.mobile_app_galaxy_tab_a9
  target: {}
  data:
    message: command_screen_on
    data:
      ttl: 0
      priority: high
command_launch_app

NOTE: for command_launch_app the Display over other apps permission needs to be allowed. This can be usually found in App settings. Find Home Assistant, find Display over other apps and set to Allowed.

  action: perform-action
  perform_action: notify.mobile_app_galaxy_tab_a9
  target: {}
  data:
    message: command_launch_app
    data:
      package_name: io.homeassistant.companion.android
      ttl: 0
      priority: high

If browser mod visibility of a browser changes to hidden, unknown or undefined, you can try and automate sending command_screen_on follwed by command_launch_app. NOTE: For the Samsung Galaxy Tab A9+, the sequence of command_screen_on followed by command_launch_app was critical.

Checking notifications received

You can check that a notification was successfully received via Notification history in the Companion App settings. Here you will see the command and how the notification was received, whether it be Websocket or FCM. If you are testing a 'Lights Off' scenario (device dozing with Home Assistant not running), and notice delays, when you check Notification history you will likely see that the notification command was received via FCM.

Image

Still having issues ?

If you are still having issues, please describe your setup as much as possible, as the key is to have the Companion App set to keep the screen on, so any assistant given, will be to work out why that may be an issue. There will be no workarounds or hacks in browser mod, nor work on any webview builds (others can do so if they wish) as that will only drive for more complication and maintenance headaches when in my view, setups should be straightforward.

Fully Kiosk Browser

I note the workaround solution using FKB rest API presented by @mdwhitten . I understand this will be reliant on the Websocket being kept alive for FKB to be able to receive the rest API commands. If FKB works well with this setup, then the Companion App with Keep screen on should also work well. I don't see any reason for using FKB for a simple setup, unless you desire FKB features.

Suspend background connections ?

Suspend background connections has been suggetsed as a workaround. I have found this not required, nor will it help when connections are stopped due to browser freeze state. For a powered device, not running on battery alone, you will find that connections will close 5 minutes after browser visibility changes to hidden, no matter the setting of Suspend background connections.

NOTE: The Suspend background connections setting is per browser, being persisted in localStorage[suspendWhenHidden] by Home Assistant. It is not a server option. So if you are testing its use, keep this in mind.

Clone this wiki locally