Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Fire TV control via PH Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: June 18 2018 at 20:02 | IP Logged Quote smarty

I am starting this thread to document my efforts towards getting PH to control the Fire TV boxes that I have attached to each of my TV's.

I am doing this for a number of reasons, including:
1) I have recently gotten rid of my cable boxes and fully rely upon the internet for all media content.

2) I have Echo Dot's in all rooms of the house. From these, I can issue voice commands to natively control some aspects of the Fire TV (app launching, pause/play, and the "home" command). Additionally, I use other voice commands through a Hue Bridge Emulator (that points back to PH via the PH web server) to turn "on/off" or "set" anything else that I have controllable from PowerHome.

Since all of my TV's are controllable via two-way serial control, I can tell Alexa to "Turn on the Bedroom TV", and a PH macro will turn on the TV, set it to the right input and even adjust the volume; but if the Fire TV box is sleeping, the TV screen is dark and it looks like the TV isn't on (until you send the Fire TV a signal to wake it up or lunch an app). So that it why I starting looking into Fire TV control.

After some Google searching, this is what I have come up with so far.

Step 1 - Download and install ADB - "Android Debug Bridge". I used the 15_Second ADB installer here:
https://androidmtk.com/download-15-seconds-adb-installer
(use at your own risk - I hope it's not malware).

Step 2 - Enable ADB Debugging on your Fire TV device.

Step 3 - ph_run("c:\adb\adb start-server")
This starts an "adb.exe" process

Step 4 - ph_run("c:\adb\adb.exe connect 192.168.0.XXX")
This connects to the Fire TV you want to control

You can verify the connection via a DOS command window by typing: "c:\adb\adb.exe devices"

Once connected, there are a number of commands you can run, including app launching:
ph_run("adb shell monkey -p org.xbmc.kodi 1")
ph_run("adb shell monkey -p com.plexapp.android 1")
ph_run("adb shell monkey -p com.netflix.ninja 1")
ph_run("adb shell monkey -p com.silicondust.view 1")
Above are the four are what I most use.

There is keypad and alpha keyevent like:
"c:\adb\adb.exe shell input keyevent 62"<=space key
"c:\adb\adb.exe shell input keyevent 51"<= w key
"c:\adb\adb.exe shell input keyevent 3" <= Home key
"c:\adb\adb.exe shell input keyevent 26" <=sleep toggle

Once your done, you can disconnect from the Fire TV by:
"c:\adb\adb.exe disconnect 192.168.0.XXX"

and then you can stop the "ADB.exe" server process by:
"c:\adb\adb.exe kill-server"


Note - I wrap most of my commands with the ph_run("") function. This works OK if there is no command feedback. But there are a number of ADB commands that could give very useful feedback to PowerHome (if there was a way to pass the information back into PH - this is what I need help with).

ADB commands like:   
"adb shell pm list packages -f" <= lists all the installed packages on your Fire TV device.
Parsing this list lets you launch individual apps

The "c:\adb\adb.exe devices" command could also tell PH which Fire TV devices you are presently connected to.

Any help here would be appreciated.



Here are some links as footnotes/resources I found useful:
"15 Sec ADB Installer" Ver 1.4.3
https://forum.xda-developers.com/showthread.php?p=48915118#p ost48915118


http://www.aftvnews.com/how-to-remotely-control-an-amazon-fi re-tv-or-fire-tv-stick-via-adb/

http://developer.android.com/reference/android/view/KeyEvent .html

http://www.aftvnews.com/how-to-connect-to-a-fire-tv-or-fire- tv-stick-via-adb/




__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: June 20 2018 at 07:11 | IP Logged Quote dhoward

Steve,

It looks like a lot of what you've posted here is what Ive got in the ADB Fire TV plugin (nearly the same code just wrapped up as a plugin). I have not
yet worked on receiving data (just sending like you've done). If you do make any headway into that arena, let me know and I'll update the plugin code
(or you can when I release the source ).

I'll be curious how reliable the code above is for you and if you experience any hanging. The plugin will work all right for awhile and then just quit
requiring the Fire TV to be reset and/or ADB to be reset. Not sure if this is a problem with ADB or the way Ive coded the plugin so interested in the
mileage you get.

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
smarty
Super User
Super User
Avatar

Joined: May 21 2006
Location: United States
Online Status: Offline
Posts: 728
Posted: October 14 2021 at 11:11 | IP Logged Quote smarty

Some general notes...

My FTV PH control reliability increases when I change settings so that my FTV NEVER goes to sleep and the screen saver
doesn't turn on.

The ADB commands are described here:   https://kinkeadtech.com/how-to-preven t-fire-tv-stick-from-go ing-to-sleep/

To NEVER sleep I use:
adb -s 192.168.xx.xx shell settings put secure sleep_timeout 0

For a long screen save timeout I use:
adb -s 192.168.xx.xx shell settings put system screen_off_timeout 2147460000


It seems that whenever the FTV OS is updated, these settings revert back to something else (especially the sleep). Therefore
I push them to my FTV's periodically.

Also, The ADB version does make a difference (the link above is very OLD). After updating to the latest ADB version, when
connected to multiple FTV devices, I was able to specify what device to send the command to by specifying "adb.exe -s". Like
the VLC launch below:

adb -s 192.168.XX.XX shell am start -n org.videolan.vlc/org.videolan.vlc.gui.video.VideoPlayerActiv ity -a
android.intent.action.VIEW -d http:/XXXXXXXXXXXX.ts



Edited by smarty - October 14 2021 at 18:09


__________________
Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
Back to Top View smarty's Profile Search for other posts by smarty
 
AdrusBarba
Newbie
Newbie


Joined: February 11 2022
Online Status: Offline
Posts: 1
Posted: February 11 2022 at 03:00 | IP Logged Quote AdrusBarba

http://developer.android.com/reference/android/view/KeyEvent .html
Useful
Back to Top View AdrusBarba's Profile Search for other posts by AdrusBarba
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum