I was looking for a faster way to control the Fire TV 4k Max gen 2 which restricts the use of the sendevent and didn’t want to use another component to control it. (I know there are keyboard control options but this worked out better) I decided to try and figure out how the apps control the Fire Sticks. I am not a great coder so I am not sure I will be able to make an integration but I reversed engineered the apps and made a work around that works pretty well. If anyone can turn this into a integration please do. The hardest part was figuring out how the token gets sent when the pin is given. You may need to wake it up before requesting the pin but the details are as follows.
Using curl or postman or something you can easily send and receive post commands. Use the following to request the pin.
curl -k https://firetvip:8080/v1/FireTV/pin/display \
-H "X-Api-Key: 0987654321" \
-H "Content-Type: application/json" \
-d '{"friendlyName": "ha\'s Fire TV"}'
Once the pin is displayed you will need to send it back to generate a token.
curl -k https://firetvip:8080/v1/FireTV/pin/verify \
-H "X-Api-Key: 0987654321" \
-H "Content-Type: application/json" \
-d '{"pin":"xxxx"}'
This will output something like {"description":"Wj9PP8I"}
. This is the token we will be using for the control.
There are 3 different urls depending on what you are doing.
- Media Controls:
ftv_key_media:
url: 'https://firetvip:8080/v1/media?action={{state}}'
method: POST
headers:
X-Api-Key: "0987654321"
X-Client-Token: "Wj9PP8I"
user-agent: "okhttp/4.10.0"
Content-Type: "application/json"
verify_ssl: false
payload: "{{main}}"
The list of commands are:
Fast Forward:
action:
- service: rest_command.ftv_key_media
data:
state: 'scan'
main: '{"direction":"forward", "keyAction":{"keyActionType":keyDown"}}'
Rewind:
action:
- service: rest_command.ftv_key_media
data:
state: 'scan'
main: '{"direction":"back", "keyAction":{"keyActionType":keyDown"}}'
Play/Pause:
action:
- service: rest_command.ftv_key_media
data:
state: 'play'
- Main Controls
ftv_key_controls:
url: 'https://firetvip:8080/v1/FireTV?action={{state}}'
method: POST
headers:
X-Api-Key: "0987654321"
X-Client-Token: "Wj9PP8I"
user-agent: "okhttp/4.10.0"
verify_ssl: false
The tested commands are:
Left = dpad_left
Right = dpad_right
UP = dpad_up
Down = dpad_down
Select = select
Home = home
Back = back
Menu = menu
(There may be more options but these are what I have confirmed so far)
- Apps can also be launched this way.
ftv_key_controls:
url: 'https://firetvip:8080/v1/FireTV/app/{{app}}'
method: POST
headers:
X-Api-Key: "0987654321"
X-Client-Token: "Wj9PP8I"
user-agent: "okhttp/4.10.0"
verify_ssl: false
Tested App list (These are the ones tested there will be more):
Disney Plus = com.disney.disneyplus
Youtube = com.amazon.firetv.youtube
Netflix = com.netflix.ninja
Prime Video = com.amazon.cloud9
Amazon Music = com.amazon.bueller.music
Pandora = com.pandora.android.gtv
Hulu = com.hulu.plus
BBC = uk.co.bbc.iplayer
NowTV = com.bskyb.nowtv.beta
AppleTV = com.apple.atve.amazon.appletv
ITV = air.ITVMobilePlayer
Chan 4 = com.channel4.ondemand
Demand 5 = com.mobileiq.demand5
SkyNews = com.onemainstream.skynews.android
If you find more commands or apps please share them.