Wake screen on mobile app based on Home Assistant Automation

Hey guys

I would like to install an old tablet in my entry way as a dashboard for Home Assistant, but don’t want the screen to be on all the time.

Is there any way to wake the screen on a motion sensor or door sensor trigger on Home Assistant, or something like that ?

6 Likes

there is no current way using the companion app, you may need to use tasker but feel free to submit an enhancement request on github for this

I would love to see this feature as well. Have been using Wallpanel until now, but that became very sluggish. Considering switching to native app.

1 Like

I simply use a xiaomi motion Sensor and the Androids ADB-Shell to wakeup & Hybernate (Keyevent 224&223) via automations. With HA`s “platform: androidtv” and the coressponding “media_player” i can also call Input-Select “homeassistant” via ADB, so the App is always in foreground when the Screen comes up.

4 Likes

Hi,
yes there is a way, I had the same problem and there is an amazing app that help you in this integration: the name is Automagic.
You can find it here: https://automagic4android.com/download_en.html
What can you do with it ? You make the app listen to a web call and associate the call with the simple action of wake up the display, that’s it. I have a camera that sense the motion and when it fire the event an automation listen and call a shell script containing:
cat wakeup_tablet.sh (name of shell script)
#! /bin/bash
wget -q http://192.168.1.60:8080/automagic -O /dev/null

My next step will be to use the camera of the tablet to sense the motion so the wake up will happen in a more restricted area.
Hope it helps :slight_smile:
M.

2 Likes

Fully Kiosk Browser app should achieve what you want.

1 Like

In the mean time the Android Hass companion app has a feature for this. Send a notification with “command_screen_on”.

However it seems this only works when the android device’s screen is off and the device is NOT sleeping. As soon as the Android device sleeps the command doesn’t work anymore. At least for me.

Any way to make this work when the device sleeps with the native companion app?

3 Likes

So you can treat the tablet like TV?

hello, any one had a complete job with wake screen on / off in actual ha version and android 10? all of tutorials are old. how tu instal adb server actualy? Integration AndroidTV want connect to tablet. Of coure programer mode is enable and debug usb enabled. I dont have options lik ADB over WiFI.

1 Like

we need a brilliant mind to do this :pray:

I use wallpanel app on android and can send mqtt messages to wake the screen, indeed…when motion is detected :slight_smile:

1 Like

thank you! can you specify how to wake up with mqtt?

This is my automation, triggers on motion and then opens a HA tab/dashboard (‘motion’) in panel view with the picture glance card. After 20 sec. it relaunches to go back to the main dashboard

alias: TabA motion screen
description: >-
  Trigger TABA in case of motion
  sec.
trigger:
  - platform: state
    entity_id:
      - binary_sensor.tapo_camera_545d_motion
    for:
      hours: 0
      minutes: 0
      seconds: 0
condition:
  - condition: time
    after: "06:00:00"
    before: "19:00:00"
action:
  - service: mqtt.publish
    data:
      topic: wallpanel/mywallpanel/command
      payload: "{             \"wake\": \"true\" ,\"wakeTime\": 10        }"
  - delay:
      hours: 0
      minutes: 0
      seconds: 0
      milliseconds: 10
  - service: mqtt.publish
    data:
      topic: wallpanel/mywallpanel/command
      payload: >-
        {             "url" :
        "http://192.168.1.20:8123/lovelace-tab/motion"           }
  - delay:
      hours: 0
      minutes: 0
      seconds: 20
      milliseconds: 0
  - service: mqtt.publish
    data:
      payload: "{\"relaunch\": true}"
      topic: wallpanel/mywallpanel/command
mode: single
2 Likes

Using Fully Kiosk you can set to Turn Screen On on Power Connect and Sleep on Power Disconnect. Works in free version as well.
Then connect the tablet via a HA controlled relay switch which you trigger by a presence sensor.
You need it anyway to prevent battery swelling - program your switch further to maintain the charge at about 20-70%.

I was also able to do this with adb. My device is a pretty old rooted Nexus 7 2013 tablet with Lineage OS.

The steps were roughly as follows:

For the tablet

(first first get a computer with the adb command aka android debug bridge, google it)

  • Enable developer menu (tap 7 times the build number)
  • Enable usb debugging via adb
  • Plug the tablet to the computer via usb
  • Enable root adb connection
    • adb root
  • Enable tcp for adb so it does not need usb cable
    • adb tcpip 5555
  • Enable tcp on boot
    • adb shell setprop persist.adb.tcp.port 5555
  • Now you should be able to wake up the screen and the app from any computer on your network with adb
    • Connect the to tablet over tcp
      • adb connect <the tablet ip>:5555
    • adb shell input keyevent KEYCODE_WAKEUP
    • adb shell monkey -p io.homeassistant.companion.android.minimal 1
    • I installed the Home Assistant Android app from F-Droid so your value here might vary

Next you’ll need to get adb for Home Assistant. Bit weirdly this is available in the “Android TV” integration. I added my tablet as a “Fire TV” even it is not a one. Seems to work. Probably any device type works. Even a car :sweat_smile:

And now I was able to create a script / automation which wakes up the screen and open Home Assistant on the tablet:
Here’s the script:

alias: Wake up Nexus 7
sequence:
  - service: androidtv.adb_command
    data:
      command: input keyevent KEYCODE_WAKEUP
    target:
      device_id: xxxyoursxxx
  - service: androidtv.adb_command
    data:
      command: monkey -p io.homeassistant.companion.android.minimal 1
    target:
      device_id: xxxyoursxxx
mode: single
icon: mdi:tablet

1 Like

Nice guide, thank you.
The requirement here is to have root access to the tablet and, in my case, I don’t have (old Nexus 10, original).
Anyway, after years now I can say that tablet management via the app Automagic is quite stable and efficient, I use even the tablet’s camera to identify when I am in front of it and wake up the display for the 30 seconds necessary.

If you use the companion app you can use a template switch. I am using this configuration:

- platform: template
  switches:
    flur_tablet_screen:
      value_template: "{{ is_state('binary_sensor.sm_t736b_interactive', 'on') }}"
      turn_on:
        - service: notify.mobile_app_sm_t736b
          data:
            message: "command_screen_on"
        - service: notify.mobile_app_sm_t736b
          data:
            message: "command_webview"
            data:
              command: "/lovelace-flur"
      turn_off:
        service: notify.mobile_app_sm_t736b
        data:
          message: command_activity
          data:
            intent_action: "android.intent.action.MAIN"
            intent_package_name: "com.teslacoilsw.launcher"
      unique_id: 6d987d00-b485-4f63-fa25-9ca17ddb1235

Set the Display Timeout of Android to 10 seconds or something like that. In the companion app enable the ‘Keep Screen on’ setting. Enable the interactive sensor somewhere in the energy sensors. Replace my lovelace view with something that fits yours.
When you turn the template switch on it launches the companion app and the screen will remain on. If you turn the switch off, it launches novalauncher (you have to install it on your device and make it the default launcher). After a short time the display times out und the screen goes off.
If you know the intent to launch your favorite launcher you can use that instead.
I found this way here in the forum and the idea is really neat i think (and it works really good, no root and no other software ist needed).

2 Likes

Actually it is only required to ensure adb starts in the tcp mode on boot. Everything else should work without it.

1 Like

I use Motion Detector ( Emparador ) to wake up the screen, when motion is detected.

Hello,

Thanks for the explanation.
Im getting the hang of home assistant but not quite yet regarding templates and value templates.
Can you give me some more information regarding the value template binary sensor?
Do i need to create the binary sensor or how does this work.
The unique ID i have already made, and i have copy pasted your template and adjusted it to my own.
Will show you my template later on. Hope you can help me.

Sjors