Emby and Nvidia Shield device states

I have an automation that dims lights in my living room when content is playing on my living room nvidia shield, and brightens lights when the state is paused, idle, or standby. This works great in plex. But the device state when using emby is reported as “paused”, even when the app is just opened and continues to stay that way even content is playing in the app. I have a thread on the emby forums, but don’t know much about how the device state is set, why it works in plex, and why it doesn’t in emby. Any tips or links to device state documentation would be appreciated.

1 Like

That is strange, my emby media player shows all the states, what the content type is, user, and the playing content. I use it to automate lights. This is the emby theater on my pc:

Sure you have the right entity ?

Yes it’s my living room Nvidia Shield. Play states work for every other app I’ve tried. Plex, Netflix, Prime, etc.

Here’s an example of plex playing

Oh I see, I use the direct link to emby:

Ok, I set that up and the entity state works with the emby integration. I was just hoping to use the the media_player platform so I don’t have to duplicate every automation just for emby. Is there a reason every other app works with the media_player platform but emby doesn’t?

No idea sorry, couldn’t you just add the extra triggers to your automations ?

As I’m thinking about this more, I’ll still have a problem because of conflicting entity states. If I add the emby integration entity_id to my current automations as a trigger, the media_player entitty_id will still read as paused when emby is playing. The same would be true for a completely separate automation. So, right now I’m stuck with either emby working, or every other app working, but not both.

Maybe use a condition in the automations to check the app_id attribute of the shield and only enable the emby automation if it is tv.emby.embyatv and the other to check if it is not. Does that make sense ? just thinking on the fly, can’t test

As I’m reading more about this, I’m thinking it’s likely emby needs custom state detection. So far, I’ve figured out how to issue the ADB command GET_PROPERTIES, and read the adb_response. However, I’m a little lost on how to implement custom state detection rules.

So, after testing device states on various apps these were my results

Netflix playing
'audio_state': 'paused', 'wake_lock_size': 2, 'current_app': 'com.netflix.ninja', 'media_session_state': 3

Netflix paused
'audio_state': 'paused', 'wake_lock_size': 0, 'current_app': 'com.netflix.ninja', 'media_session_state': 2

netflix idle
'audio_state': 'paused', 'wake_lock_size': 0, 'current_app': 'com.netflix.ninja', 'media_session_state': 1

netflix preview
'audio_state': 'paused', 'wake_lock_size': 2, 'current_app': 'com.netflix.ninja', 'media_session_state': 3


Android TV Launcher
'audio_state': 'paused', 'wake_lock_size': 0, 'current_app': 'com.google.android.tvlauncher', 'media_session_state': None


Plex idle
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'com.plexapp.android', 'media_session_state': None

Plex paused
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'com.plexapp.android', 'media_session_state': 2

Plex playing
'audio_state': 'paused', 'wake_lock_size': 3, 'current_app': 'com.plexapp.android', 'media_session_state': 3


Emby idle
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'tv.emby.embyatv', 'media_session_state': None

Emby paused
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'tv.emby.embyatv', 'media_session_state': None

Emby playing
'audio_state': 'paused', 'wake_lock_size': 3, 'current_app': 'tv.emby.embyatv', 'media_session_state': None


YouTube idle
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'com.google.android.youtube.tv', 'media_session_state': 0

Youtube paused
'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'com.google.android.youtube.tv', 'media_session_state': 2

Youtube playing
'audio_state': 'paused', 'wake_lock_size': 3, 'current_app': 'com.google.android.youtube.tv', 'media_session_state': 3

This led to my config

media_player:
  - platform: androidtv
    name: Shield
    host: 192.168.0.152
    apps:
      tv.emby.embyatv: "Emby"
      com.netflix.ninja: "Netflix"
      com.google.android.tvlauncher: "Android TV Launcher"
      com.plexapp.android: "Plex"
      com.google.android.youtube.tv: "YouTube"
    state_detection_rules:
      'tv.emby.embyatv':
        - 'playing':
            'wake_lock_size': 3
        - 'standby':
            'wake_lock_size': 1
      'com.netflix.ninja':
        - 'playing':
            'media_session_state': 3
            'wake_lock_size': 2
        - 'paused':
            'media_session_state': 2
            'wake_lock_size': 0
        - 'standby':
            'media_session_state': 1
            'wake_lock_size': 0
      'com.google.android.tvlauncher':
        - 'standby':
            'wake_lock_size': 0
      'com.plexapp.android':
        - 'playing':
            'media_session_state': 3
            'wake_lock_size': 3
        - 'paused':
            'media_session_state': 2
            'wake_lock_size': 1
        - 'standby':
            'wake_lock_size': 1
      'com.google.android.youtube.tv':
        - 'playing':
            'media_session_state': 3
            'wake_lock_size': 3
        - 'paused':
            'media_session_state': 2
            'wake_lock_size': 1
        - 'standby':
            'media_session_state': 0
            'wake_lock_size': 1

I haven’t tested thoroughly but it worked with a brief run-through. I’ll follow up if I notice any issues.

2 Likes

For anyone who happens to come across this, these emby settings don’t work without fail. I’ve had my lights brighten and dim a few seconds later a couple times during a movie. I’m trying to get the emby devs to add media_session_state to their app to more reliably determine the device play state.

Out of curiosity how did you setup your integration? I did not see references to adb_server_ip or port in yours so was curious. Just a reference to the shield IP.

I’m just using the default values so they’re not specified in the yaml.

Thanks, I have another topic with my setup and issues, however when you have:

    apps:
      tv.emby.embyatv: "Emby"
      com.netflix.ninja: "Netflix"
      com.google.android.tvlauncher: "Android TV Launcher"
      com.plexapp.android: "Plex"
      com.google.android.youtube.tv: "YouTube"

Do you find if you select the pulldown for the media_player ONLY those items show? Also does the TV Launcher actually work for you? When I select it nothing happens and doesn’t go back to the main screen. Also YouTube doesn’t show on the list either so have some weirdness. I also have it set to only show those apps but I get other things that I didn’t add in that apps list.

No, there are plenty of other items in the pull down and the apps listed in the yaml config aren’t necessarily in that list. I only have those since it matched the examples I found for custom state detection. That section may not even be required for custom state detection to work.

Which makes sense as you do not use the exclude_unnamed_apps. For me I do but still get apps not in the list. When you select if you have “Android TV Launcher” does it go to the home page?

No, it doesn’t but I don’t really use the cards and rarely log into the interface. Not sure exactly what you’re trying to do, but you might have to use the adb_command service to issue a home command.

Do your automations work quickly? For me the playing and stopping work great but the pause usually doesn’t report back for about 15 seconds or so and then it shows ‘paused’ and so the transition to turning lights back on if you pause doesn’t really work that great with the Emby integration for myself.

Not sure about the emby integration specifically, but using the android tv integration with custom state detection works as fast as any other app on my shield.

After you plug in your custom states, how are you triggering light automations off of that? Maybe I’m over thinking it but I’m not following how you do that piece.

I went through to verify those items with the adb get_properties but I dont see where it’s helping anything really.

Regular media players you just set based on the state it’s reporting but if I used my shield as the media player to trigger it, I would imagine I’d have to have it check if it’s Emby and then do the lower/raising of lights.

For me it would be triggering the lights off the android tv and if the app is Jellyfin (which is a fork of Emby, so the Emby integration works)… not just if the Android TV is playing anything.