Simple (and free): Turn an android tablet/phone on/off based on camera motion detection

I haven’t seen a complete example of this anywhere and didn’t want to pay for Fully Kiosk Browser app. This guide should take you like 10 minutes. So here it is:

HA configuration:

  1. Install Home Assistant companion app on your android device (from here on, a tablet)
  2. in android, go to the app info settings and allow all permissions such as “Enable system configuration”
  3. integrate it with your HA server, an action such as notify.mobile_app_lenovo_tb_x606f should become available
  4. go to developer tools/actions e.g. http://homeassistant.local:8123/developer-tools/action and try sending some command such as this simple one:
action: notify.mobile_app_lenovo_tb_x606f
data:
  message: command_screen_on
  data: {}
  1. it should turn on the screen on your screen switch off tablet

Using the device camera for motion detection

  1. on your tablet, download https://play.google.com/store/apps/details?id=com.pas.webcam (you don’t need PRO version)
  2. in the settings, enable Data logging and motion detection, click on Start server
  3. note the IP Address at the camera screeen at the very bottom
  4. go to home assistant and enable this integration Android IP Webcam - Home Assistant where you put your IP Address (password and username if you set that in the app earlier, but not needed, same with port)
  5. it should add new sensors to your homeassistant, most importantly e.g. binary_sensor.192_168_0_167_motion_active that says if a motion has been detected or not

Putting it together:

Simple automation:

alias: Turn on tablet screen when motion detected
description: ""
triggers:
  - trigger: state
    entity_id:
      - binary_sensor.192_168_0_167_motion_active
    to: "on"
conditions: []
actions:
  - action: notify.mobile_app_lenovo_tb_x606f
    data:
      message: command_screen_on
  - action: notify.mobile_app_lenovo_tb_x606f
    data:
      message: command_webview
  - action: notify.mobile_app_lenovo_tb_x606f
    data:
      message: command_screen_off_timeout
      data:
        command: 30000
mode: single

This will turn on the screen if off, navigate to the webview lovelace, and turn off the screen after 30 secons. You can of course infinitely customize this.

You can let the screen go off, the IP Camera will still work (and the sensor). I have reduce the streaming quality and FPS to reduce the load, as it is not needed for my usecase, I just need simple motion detection so my hope is the lower the CPU resources/battery drain.

I also used the free Fully Kiosk Browser and HACS GitHub - NemesisRE/kiosk-mode: 🙈 Hides the Home Assistant header and/or sidebar to setup my specific dashboard so when accessed with the former on e.g. http://myhas/lovelace/dashboard-with-kiosk?kiosk shows up when woke up. I also removed the overlay “IP Webcam is running in background” so when the Browser is open, there is nothing about the camera recording.

Note that when tweaking stuff via accessing the settings of IP webcam, e.g. at http://192.168.0.167:8080/ , the motion detection won’t work, you have to close that.

On my own Lenovo tablet, the whole screen-on reaction takes about 2-5 seconds, which is not great :snail:

3 Likes