Jump to content


Photo

Nvidia Shield + Home Assistant (home-assistant.io)


  • Please log in to reply
14 replies to this topic

#1 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 03:42 AM

This is a minor annoyance, but still seems worth reporting. I've recently got a bunch of smart lights that I'm using with home-assistant.io. One of my favorite automations is dimming the living room lights when a movie or show is playing after sunset. The way I have my automations set up is by reading the play state of the nvidia shield. On pause, idle, or standby, the lights brighten. When playing, the lights dim. Unfortunately, when using emby, the state changes to "paused" just when opening the app, and continues to stay "paused" even when content is playing. I've attached some screen shots from the dev tools of home assistant for reference. Can the app be updated to correctly report play states on the shield?

Attached Files



#2 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 22 March 2020 - 10:40 AM

Hi. Exactly where is that information coming from?



#3 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 01:17 PM

The screens show emby/plex dashboards on the left, and device states from the developer tools of home-assistant.io on the right.



#4 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 22 March 2020 - 02:21 PM

But where is that "device state" actually coming from is my question...?  Any idea?



#5 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 02:43 PM

It's coming from the Shield. Home assistant connects via adb to the shield and the device state is polled every 10 seconds.



#6 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 22 March 2020 - 02:46 PM

Right, but exactly where is that information coming from is the question...



#7 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 03:32 PM

I've got a thread open in the home assistant forums as well to see if I can find more information. I just thought it may be a problem with the emby app, because every other app on the shield reports play states correctly.



#8 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 22 March 2020 - 03:41 PM

I know of no adb command that will get you a general "playback status" from the device.  They have to be querying something specific - perhaps from the built in media player which we don't use. However, neither does Plex so... I'm just not sure at this point.  Please let us know what you find out.



#9 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 06:50 PM

Ok, So it looks like their androidtv package polls 3 properties to determine the device state.
 

 

Unfortunately, there is no standard API for determining the state of the device to which all apps adhere. Instead, the backend androidtv package uses three of the properties that it collects to determine the state: audio_state, media_session_state, and wake_lock_size.

 

I've figured out how to issue the adb command GET_PROPERTIES from HA and how to read the adb response. So now I'll just have to do some testing to figure out the difference between plex and emby in these 3 parameters during different device states. They also have implemented custom state detection. So I should be able to get this working without any changes in the emby app. But (I think), if it was possible to set these parameters to match plex/netflix/etc then this type of customization wouldn't be required for future users of HA + emby.



#10 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 22 March 2020 - 11:10 PM

Here's what got from testing devices states in various apps

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 me to the following config for the Nvidia Shield

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

In my initial testing it seems to be working fine, but I haven't tested thoroughly. I'm guessing emby has trouble because media_session_state is always 'None', and paused and idle have the same wake_lock_size. I dealt with this by just removing the paused state for emby. I'll follow up if I notice and issues.


Edited by D34DC3N73R, 23 March 2020 - 01:50 AM.


#11 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 23 March 2020 - 12:04 PM

Thanks for the info.



#12 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 23 March 2020 - 12:27 PM

No problem. Any thoughts on setting a media_session_state in the emby atv app?


  • seanbuff likes this

#13 ebr OFFLINE  

ebr

    Chief Bottle Washer

  • Administrators
  • 50827 posts
  • Local time: 09:35 PM

Posted 23 March 2020 - 01:34 PM

No problem. Any thoughts on setting a media_session_state in the emby atv app?

 

We'll look at it.



#14 seanbuff OFFLINE  

seanbuff

    Advanced Member

  • Members
  • 258 posts
  • Local time: 11:35 AM
  • LocationSydney, Australia

Posted 23 March 2020 - 07:45 PM

I would also be interested in this, bring Emby inline with the other media apps.



#15 D34DC3N73R OFFLINE  

D34DC3N73R

    Advanced Member

  • Members
  • 107 posts
  • Local time: 06:35 PM

Posted 25 March 2020 - 07:40 PM

Just an update on this, the way I have it currently set up isn't without fail. A couple times throughout a movie, the lights would brighten when content was still playing and dim back down a second or two later. So, while what I have is much better than not working at all, I'd still really appreciate media_session_state being added to the app.


  • seanbuff likes this




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users