Control android tab with openhab

HI, i have (for now) two android tab to control my apartment. I want to control them via openhab. I want to turn on or of the screen from a rule. Or may be start and stop day dream !

So i could do thing like if nobody home turn off the screen. if everybody sleeping start daydream etc…

Tasker can start daydream.


there should be a way to get commands to tasker with openhab

1 Like

From memory:
I got openhab to send to the device a push via pushbullet.
Tasker would respond to the specific text in pushbullet and carry out the action.
I had Tasker run daydream at specific times.
I also had Tasker dismiss the message from pushbullet to keep it all clean.
Josh

I’m doing something similar with an AndroidTV (Nvidia Shield). It’s a bit of a “hack” solution, but it may work for you. (credit to the Nvidia Shield forums for suggesting this).

I’m using adb over the network to send Android keyevents to the device. Here’s what got me working on my OH1 server (running on Ubuntu):

  1. Install android-tools-adb package
$sudo apt-get install android-tools-adb
  1. Enable “Developer Mode” on the device, enable “USB Debugging” and “Network Debugging” Connect your device to the OH server USB port (may need to change to the ‘openhab’ user to make this work)
$adb devices
$adb connect 10.1.1.100 (or whatever your tablet's IP is)

You should see a warning on your device asking if you trust the OH server. Accept and never ask again. This is a one-time step. You should be able to do everything else over the network without prompting.

  1. For OH1 integration, you’ll want to create bash script that connects to the device over the network and issues keyevents (like SLEEP and KEYCODE_POWER). Here is the script that I use for going to sleep and waking-up

AndroidOn.sh

#!/bin/bash
adb kill-server
adb start-server
adb connect 10.1.1.100:5555
sleep 1
timeout 5 adb -s 10.1.1.100:5555 shell input keyevent KEYCODE_POWER
adb kill-server

AndroidOFF.sh

#!/bin/bash
adb kill-server
adb start-server
adb connect 10.1.1.100:5555
sleep 1
timeout 5 adb -s 10.1.1.100:5555 shell input keyevent SLEEP
adb kill-server

You may need to change the ownership and execution to openhab and 755 respectively:

$sudo chown openhab: /etc/openhab/configurations/scripts/AndroidOFF.sh
$sudo chmod 755 /etc/openhab/configurations/scripts/AndroidOFF.sh

You can launch it within a rule by using the executeCommandLine() command:

executeCommandLine("/usr/share/openhab/bin/AndroidOFF.sh")

EDIT: Just found out about a feature(?) that files in “/etc/openhab/configurations/scripts” get their permissions changed when OH restarts, and it removes the execute perms. Suggest putting it someplace else so you don’t have to change permissions each time it’s restarted. Updated the example above.

There are a whole lot of other KeyEvents that can be sent to it, but I wouldn’t suggest trying to use it for any real remote-controlling. It’s pretty slow. The sleep 1 is in there to add more reliability (was only working 75% of the time without it).

2 Likes

wow i really like this ! can i lunch an app to ( like day dream ) ?

Yes. You can launch apps via adb (see this StackOverflow post).

You can also change settings via adb (blog about it here).

I don’t specifically know if DayDream is considered an app or service in android. I don’t know much about it.

I’m using Tasker with the “Tasker Network Event Server” on the Android tablet and using openhab httpget commands in my rules to do things on the Android like wake screen and text to speech.

Chris

it’s really nice to all of you to give me idea like that !

Now i wana now ! What do you do with your tab ?

Alway open ? (it’s a good way to reduce the life of the tab and it make a lot of light at night)
Daydream ? ( it also make a lot of light and you need to tap on the screen each time you want to use it)
Motion sensor ? (does it work with low light ? )
Rule ? (how do you manage it ?? )

Thanks

Daydream during the day, screen off at night.
Linked to my phone:
Night time was after on charge and screen off for 15 min.
Day time was screen on after 2am.
Josh

I wish this had been around when I started figuring this out for my tablets stuck to the wall. Might as well share my scripts in case they’re useful for someone. I’ve also set up a contact item to monitor screen state.

Blog post w/ scripts and directions http://www.ragingcomputer.com/2016/06/controlling-android-tablet-screen-with-openhab-and-adb

Demo video https://www.youtube.com/watch?v=tE6RqvjlHQg

1 Like