[Testers needed!] Custom state detection rules for Android TV / Fire TV

Has this made it into the official releases?

Yes

1 Like

More of a heads up. I noticed Plex updated their media player in the last week or so for Android TV.

This is now my current config which seems to catch the new states correctly.

Playing seems to almost always be:

wake_lock_size: 3
media_session_state: 3

(Sometimes the wake_lock_size changes to a 4 or something else)

Paused always seems almost to always be:

wake_lock_size: 1
media_session_state: 2

(Sometimes the wake_lock_size isn’t always one like when scrubbing through)

Since there are a lot of transient states mentioned above I’ve changed my config to this.

media_player:
  - platform: androidtv
    name: Shield
    device_class: androidtv    
    host: 10.0.0.10
    adb_server_ip: 10.0.0.9
    apps:
      com.plexapp.android: "Plex"
    state_detection_rules:
      'com.plexapp.android':
        - 'playing':
            'media_session_state': 3
        - 'paused':
            'media_session_state': 2 
        - 'standby'
1 Like

It’s not working properly for me. When something is running, media_session_state seems to stay at 3 but wake_lock_size moves between 3, 4 and 5. Pausing Plex (just pause not going “away” from the movie) leaves media_session_state at 3 and sets wake_lock_size down to 2 (but up again randomly, for a few seconds at a time). So there is no absolute way to differentiate, I think.

The following works to have playing always correct. But pause/standby randomly gets set to playing for an instant and then back. For simplicity I removed “paused” altogether.

state_detection_rules:
      "com.plexapp.android":
        - "playing":
            "media_session_state": 3
            "wake_lock_size": 3
        - "playing":
            "media_session_state": 3
            "wake_lock_size": 4
        - "playing":
            "media_session_state": 3
            "wake_lock_size": 5
        - "standby"

Is there anyway to set a range, so I don’t have to repeat all those lines?

I think I’ve change some things around since an update to the Plex app shifted the states around again (when they rolled out the new UI). I do remember experiencing the random paused -> play state trigger. But I can’t recall the last time it happened. This is what my config is now.

media_player:
  - platform: androidtv
    name: Shield
    device_class: androidtv    
    host: X.X.X.X
    adb_server_ip: X.X.X.X
    apps:
      com.plexapp.android: "Plex"
    state_detection_rules:
      'com.plexapp.android':
        - 'playing':
            'media_session_state': 3
        - 'paused':
            'media_session_state': 2 
        - 'standby'
1 Like

I know this was posted like 3 years ago, but thank you for this! I couldn’t figure out what to do about Hulu. Found this, worked instantly. THANK YOU.

Hi @Pronown

Did you maintain these state detection rules through the UI or configuration file? I have setup the integration using the UI and it has generated a UI, however depending on the app, I’m getting inaccurate states - hence I would like to lean on the work done in this thread.

My only issue, there is no documentation on how to maintain these in the UI despite the feature being available. If you could provide some guidance, that would be awesome!

Thanks

1 Like

Well, I’m no expert, but I did manage using this and the official documentation to get Hulu showing “playing” and “paused” via the below method. I couldn’t get “standby” nor “idle” but I’m using it for an automation that turns off my OLED to avoid burn in. If it notices the interactive sensor on my phone isn’t being used at certain times (30 min intervals) it will pause the firetv, then it will wait 5 minutes, then check to see if the firetv has been paused for 4.5 minutes, if so, it shuts down the whole bedroom and flips my switch made in helpers to track what time I fell asleep.

Anywho:
Add the device via IP in the Android TV integration, IDK if it matters, but I chose firetv specifically instead of auto to try to ensure it would work properly.
After it is added choose configure.


At the bottom, choose New Rule then Submit.

Then add

com.hulu.plus

&&

[{"playing": {"media_session_state": 3}}, {"paused": {"media_session_state": 2}}]


Press submit.
Enjoy!

Let me know if you figure out the other states, I don’t really need them, but if I can make something better, then I like to. That and who knows, maybe I’ll find a use in them one day? I originally had it in my config, and removed it on accident. Lost the state detection and couldnt figure out why. I actually switched to Chromecast for 2 weeks before returning them because their functions were pointless. If I asked for a show to play on Hulu, I was still required to press the enter button on the remote to make it play, so I switched back. Finally found this post and decided to try state detection, problems solved.

3 Likes

Thanks, this has helped - I wasn’t clear on the format for the List of State Rules field. Appreciate the guidance!

1 Like

this is great. i want to automate something by reading which app is opened.
say if netflix is opened i want to turn of lights like that.
is their any way to read which app is being currently opened and implement that in automation?

Is anyone please able to help with the custom state settings for Peacock?
I’m currently watching a stream, using default settings, but my Fire Stick shows as paused.

So I’ve noticed a few years have gone by since this topic was first written. Does anyone have an updated config that they’re willing to share?

For Paramount+:

Application ID:

com.cbs.ott

List of states:

[{"playing": {"wake_lock_size": 5}}, {"paused": {"wake_lock_size": 4}}]

hi It seems that I can’t save the custom rules. Is there anything more specific than clicking on “Submit”?

Also, where is this config in yaml ? I mean in which file ? Thanks :slight_smile:

I noticed this module is no longer maintained.
Can it still be used and should I remove official Android TV integration?

/edit
Nevermind, figured it out already.
Great work.

It would be great if someone can post an up-to-date version of this. As been through this whole thread and tried every solution, unforuntately when using Netflix on Android TV it still responds at “idle” and not showing netflix as an ID.