My Solution for Controlling Any Android App From Home Assistant

Hi Everyone,

I wanted to share my solution for controlling any Android App from Lovelace. It’s got a few different moving parts, but overall I don’t think it’s that difficult to implement. I wanted to get feedback from the HA community to see if anyone has ideas on a better / more efficient way of implementing the same concept.

My solution involves a few different parts:

  1. An Android App called ScreenStream that streams your Android screen to a local url (like http://192.168.1.156:8080/stream.mjpeg)

  2. joaoapps Tasker and AutoRemote that work together to create a cloud-based API that you can use to POST http requests and take action on your Android device.

  3. joaoapps AutoInput to handle more complicated actions on the Android Device.

  4. A few different Home Assistant Scripts, Automations, updates to configuration.yaml and the Lovelace yaml.

Here’s a ~ 9 minute video I just put together illustrating the prep work that needs to be done on your Android device using Tasker, etc.

Add the following to your configuration.yaml:

(NOTE: Replace ‘192.168.1.156’ with the IP of your Android device)

(NOTE: Get the rest_command URLs via AutoRemote (see the last minute of the above video))

input_select:
  android_controls:
    name: Android Controls
    options:
      - Select Action
      - Toggle ScreenStream
      - View Ring Front Door
    initial: Select Action
    icon: mdi:apps

stream:

camera:
  - platform: mjpeg
    mjpeg_url: http://192.168.1.156:8080/stream.mjpeg
    name: android_stream

rest_command:
  android_toggle_screenstream:
    url: 'https://autoremotejoaomgcd.appspot.com/sendmessage?key=...&message=Toggle%20ScreenStream'
  android_view_ring_front_door:
    url: 'https://autoremotejoaomgcd.appspot.com/sendmessage?key=...&message=Ring%20Live%20View'

Add the following to your scripts.yaml:

android_reset_input_select:
  alias: Android Reset Input Select
  sequence:
      - service: input_select.select_option
        data_template:
          entity_id: input_select.android_controls
          option: 'Select Action'
toggle_screenstream:
  alias: Refresh Android Screen Stream
  sequence:
      - service: rest_command.android_toggle_screenstream
android_view_ring_front_door:
  alias: View Ring Front Door
  sequence:
      - service: rest_command.android_view_ring_front_door

Add the following to your automations.yaml (make sure the IDs are not the same as any of your existing Automations):

- id: '1572704111917'
  alias: AndroidControlToggleScreenStream
  description: ''
  trigger:
  - entity_id: input_select.android_controls
    platform: state
    to: Toggle ScreenStream
  condition: []
  action:
  - service: script.toggle_screenstream
  - data: {}
    service: script.android_reset_input_select
- id: '1572704356298'
  alias: AndroidControlLaunchRing
  description: ''
  trigger:
  - entity_id: input_select.android_controls
    platform: state
    to: View Ring Front Door
  condition: []
  action:
  - service: script.android_view_ring_front_door
  - data: {}
    service: script.android_reset_input_select

Now, let’s make a new tab in Lovelace by adding the following yaml via the “Raw Config editor”:

- cards:
    - entities:
        - input_select.android_controls
      type: entities
    - camera_image: camera.android_stream
      camera_view: live
      entities:
        - camera.android_stream
      title: My Android Device
      type: picture-glance
panel: true
path: android
title: AndroidControl

Now you can navigate to the “AndroidControl” tab in your Home Assistant frontend and execute a couple of Tasker commands via the input_select dropdown above the livestream of the Android screen! You, of course, can add as many additional Tasker commands as you want following the patterns illustrated in the above.

Any feedback/criticism is welcome - especially anything that makes this more efficient (less moving parts, etc).

5 Likes

Pretty cool, I changed the category to “share your projects” as it fits better.

1 Like