Hi all,
I would like to automatically start a specific netflix tv show on my firetv stick. I have configured the androidtv component and everything works fine. I can send some standard commands through the androidtv.adb_command service with a json formatted like this:
The documentation says that I can send some adb shell commands, so my question is how can I do that to start e.g. netflix to open a specific tv show?
I have found this adb command which could work: adb shell am start -n com.netflix.ninja/.MainActivity -a android.intent.action.VIEW -d netflix://title/80997085
But I don’t know how to enter it properly into the service json field.
I couldn’t find a way to do that, after searching for almost a week.
I.e. I’m looking for an activity or intent that starts streaming Hue Sync
At the moment I’m letting Home Assistant start Hue Stream and Kodi at a certain time in the evening and navigate through the app with Harmony. This seems overly complicated and relies on Hue Stream being off, else the automation would be turning it off instead of on.
- id: kodi_21_15_an
alias: Kodi 21:15 an
trigger:
- at: '21:15:00'
platform: time
condition:
condition: and
conditions:
- condition: state
entity_id: media_player.kodi
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.google_maps_******
state: home
- condition: state
entity_id: device_tracker.google_maps_******
state: home
action:
- data:
activity: '37467008'
entity_id: remote.harmony_hub
service: remote.turn_on
- delay: 00:00:30
- data:
entity_id: media_player.fire_tv
source: com.bullbash.huestream
service: media_player.select_source
- delay: 00:00:05
- data:
command: DirectionDown
device: '59741152'
entity_id: remote.harmony_hub
service: remote.send_command
- data:
command: OK
device: '59741152'
entity_id: remote.harmony_hub
service: remote.send_command
- data:
entity_id: media_player.fire_tv
source: org.xbmc.kodi
service: media_player.select_source
Maybe this automation helps someone or someone can help me find a way to achieve what I’m trying to do.
To send that ADB command using the androidtv.adb_command service, just drop the “adb shell” prefix.
Currently, any output from that command will be recorded in HA’s log. Short of parsing the log, there’s no way to utilize that data. This could be improved, although I’m not sure what the best approach is. Perhaps the component could fire an event with that data?
I don’t think the ADB shell supports awk. At least, I’m pretty sure my generation 2 Fire TV sticks don’t.
I think the best approach for you is to mimic the turn_off command in the androidtv package. Instead of using Harmony to send the down and OK commands, use the androidtv.adb_command service with something like this:
See constants.py for more info about the key commands. That command will only send the down and center (OK) commands if “REQUIRED_TEXT” is found in the output of your command.
If you get it working, please share your solution!
- id: kodi_21_15_an
alias: Kodi 21:15 an
trigger:
- at: '21:15:00'
platform: time
condition:
condition: and
conditions:
- condition: state
entity_id: media_player.kodi
state: 'off'
- condition: or
conditions:
- condition: state
entity_id: device_tracker.google_maps_***********1
state: home
- condition: state
entity_id: device_tracker.google_maps_***********2
state: home
action:
- data:
activity: '37467008'
entity_id: remote.harmony_hub
service: remote.turn_on
- delay: 00:00:30
- data:
entity_id: media_player.fire_tv
source: com.bullbash.huestream
service: media_player.select_source
- delay: 00:00:05
- data:
command: dumpsys activity service com.bullbash.huestream/com.bullbash.entertainment.screenstatebroadcaster.ScreenBroadcastService | grep -q 'No services match' && input keyevent 20 && input keyevent 23
entity_id: media_player.fire_tv
service: androidtv.adb_command
- data:
entity_id: media_player.fire_tv
source: org.xbmc.kodi
service: media_player.select_source
Most of the time this should do the job.
Now I’m trying to figure out, how to only start the entire automation, if HueStream isn’t streaming and no one is watching anything else, like Netflix.
I don’t really understand how to do this, as there doesn’t seem to be an easy way to pass that data to a sensor, but if I ever find out, I’m gonna update my post.
In the next HA version, I added an adb_response attribute that will store the output, if any, of the last ADB command. So you could use that in a template:
@JeffLIrion How to know which is the correct syntax to launch Youtube TV on a fire TV?
Really cannot find the correct name of the youtube apk and the syntax.
How do I actually launch a video instead of just opening the app. Ex. When we wake up in the morning I would like to launch a youtube livestream link for ambiance.
I found it! This command worked on my new FireTV Cube to launch a youtube video. I used this with the ADB bridge addon. I will try next with the python method to see if I have the same results. Hope this helps!
entity_id: media_player.family_room_firetv_atv
command: am start -a android.intent.action.VIEW -c android.intent.category.BROWSABLE -d "https://www.youtube.com/watch?v=HGg77PwGJbY"
This does NOT work on a firetv cube. For one, the package name is different.
I have a Sony Bravia Android TV, have the below working well and changing to the channel:
am start -a android.intent.action.VIEW -d watch/{{channel_code}} -n com.google.android.youtube.tvunplugged/com.google.android.apps.youtube.tvunplugged.activity.MainActivity
I’ve been trying to do the same using the FireTV Cube we have in the bedroom. This will launch Youtube TV if it’s not running, but will NOT change to the channel given by {{channel_code}}.
am start -a android.intent.action.VIEW -d watch/{{channel_code}} -n com.amazon.firetv.youtube.tv/dev.cobalt.app.MainActivity
It does return the below in the adb attributes, so I’m guessing either the -d parameter isn’t correct or is getting ignored for some reason.
Warning: Activity not started, its current task has been brought to the front
Well, its over year since the start of the thread, but I was having a similar issue on my Sony Android TV and found a couple solutions I thought I should share.
I found this thread that has a command that worked for me:
I used this in my script that calls the “androidtv.adb_command” service.
command: >-
‘am start -c android.intent.category.LEANBACK_LAUNCHER -a
android.intent.action.VIEW -d http://www.netflix.com/watch/80992048 -f
0x10808000 -e source 30 com.netflix.ninja/.MainActivity’
Just swap the 80992048 for your show ID.
As well as I have an android TV, and it might be slightly different for a FireTV, my original inspiration came from this thread on Reddit that is about a FireTV.
Originally I dropped the last part as it seemed to be specific to amazon, but turned out it was the key to my Sony Android TV as well.
Did you know the command for Amazon Video? I am trying to do the same for Amazon Prime Videos with the specific show. Whenever I start the script, It should start the Specific Show.