D34DC3N73R 18 Posted March 22, 2020 Share Posted March 22, 2020 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? Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 22, 2020 Share Posted March 22, 2020 Hi. Exactly where is that information coming from? Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 22, 2020 Author Share Posted March 22, 2020 The screens show emby/plex dashboards on the left, and device states from the developer tools of home-assistant.io on the right. Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 22, 2020 Share Posted March 22, 2020 But where is that "device state" actually coming from is my question...? Any idea? Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 22, 2020 Author Share Posted March 22, 2020 It's coming from the Shield. Home assistant connects via adb to the shield and the device state is polled every 10 seconds. Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 22, 2020 Share Posted March 22, 2020 Right, but exactly where is that information coming from is the question... Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 22, 2020 Author Share Posted March 22, 2020 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. Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 22, 2020 Share Posted March 22, 2020 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. Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 22, 2020 Author Share Posted March 22, 2020 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. Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 23, 2020 Author Share Posted March 23, 2020 (edited) 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 March 23, 2020 by D34DC3N73R Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 23, 2020 Share Posted March 23, 2020 Thanks for the info. Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 23, 2020 Author Share Posted March 23, 2020 No problem. Any thoughts on setting a media_session_state in the emby atv app? 1 Link to comment Share on other sites More sharing options...
ebr 14910 Posted March 23, 2020 Share Posted March 23, 2020 No problem. Any thoughts on setting a media_session_state in the emby atv app? We'll look at it. Link to comment Share on other sites More sharing options...
seanbuff 840 Posted March 23, 2020 Share Posted March 23, 2020 I would also be interested in this, bring Emby inline with the other media apps. Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted March 25, 2020 Author Share Posted March 25, 2020 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. 1 Link to comment Share on other sites More sharing options...
MRobi 159 Posted May 21, 2020 Share Posted May 21, 2020 @@D34DC3N73R what are you using to test the device states? I'd like to set this up with TiViMate for when I'm watching IPTV. Also, have you checked out HA's emby integration? https://www.home-assistant.io/integrations/emby/ It creates an entity for each emby device and you can use the play states as triggers. It would require adding a second trigger to your existing automation or just adding a second automation just for emby. This is how I've implemented it in Node-Red, does exactly what you're looking to do and has been flawless for me. https://emby.media/community/index.php?/topic/81794-home-assistant-0104/?p=882114 Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted May 22, 2020 Author Share Posted May 22, 2020 Yes I have seen the emby integration, but it seems to take longer than the default Android TV integration to recognize pauses. I'd prefer that media_session_state be integrated into the app to avoid a bunch of duplicate or conditional automations, and to conform to other media app standards. To get device states you can use developer tools > services tab in home assistant. You'll want to use the androidtv.adb_command service, and select the androidtv entity you'll be testing. That will autofill the entity_id in service data, and then you'll want to issue the adb command GET_PROPERTIES. entity_id: media_player.your_androidtv_device command: GET_PROPERTIESAfter calling the service, check the states tab, find the device and look at the adb_response. You'll have to capture devices states for play, pause, and standby and then compare the properties audio_state, wake_lock_size, and media_session_state. Link to comment Share on other sites More sharing options...
MRobi 159 Posted May 22, 2020 Share Posted May 22, 2020 (edited) Yes I have seen the emby integration, but it seems to take longer than the default Android TV integration to recognize pauses. I'd prefer that media_session_state be integrated into the app to avoid a bunch of duplicate or conditional automations, and to conform to other media app standards. That's interesting. I find the emby integration to be the fastest I've used on any home automation platform. Including faster than the androidtv integration which seems to poll the state instead of receiving it. With the emby integration, my finger is still pressed down on the button and it's already firing the automation. Your method to pull states works. Interestingly TiviMate, probably the most popular IPTV app on Android TV, also doesn't use media_session_state. It just says "None". Edited May 22, 2020 by MRobi Link to comment Share on other sites More sharing options...
ebr 14910 Posted May 24, 2020 Share Posted May 24, 2020 Very interested in if the latest beta shows you this status now. Thanks. 2 Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted May 25, 2020 Author Share Posted May 25, 2020 Emby idle 'audio_state': 'paused', 'wake_lock_size': 0, 'current_app': 'tv.emby.embyatv', 'media_session_state': 0 Emby paused 'audio_state': 'paused', 'wake_lock_size': 1, 'current_app': 'tv.emby.embyatv', 'media_session_state': 2 Emby playing 'audio_state': 'paused', 'wake_lock_size': 2, 'current_app': 'tv.emby.embyatv', 'media_session_state': 3 Looks good! I'll update my automations and test it out some more when the sun sets. Thanks for taking the time to implement this! 1 Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted May 26, 2020 Author Share Posted May 26, 2020 Update: Working great with updated custom state detection rules. Also, seems to be working just fine with no custom state detection rules, although I haven't tested it this way quite as long. Link to comment Share on other sites More sharing options...
ebr 14910 Posted May 26, 2020 Share Posted May 26, 2020 This will change again in the next beta so you'll want to re-test then. Thanks. Link to comment Share on other sites More sharing options...
ebr 14910 Posted May 30, 2020 Share Posted May 30, 2020 Okay, there is a new beta (.06). Please test that these are still working for you. Thanks. Link to comment Share on other sites More sharing options...
D34DC3N73R 18 Posted June 2, 2020 Author Share Posted June 2, 2020 Here's what I got with the latest beta (1.8.07) emby idle 'audio_state': 'paused', 'wake_lock_size': 2, 'current_app': 'tv.emby.embyatv', 'media_session_state': 0 emby paused 'audio_state': 'paused', 'wake_lock_size': 3, 'current_app': 'tv.emby.embyatv', 'media_session_state': 3 emby playing 'audio_state': 'paused', 'wake_lock_size': 4, 'current_app': 'tv.emby.embyatv', 'media_session_state': 3 Without using custom state detection rules, it's enough for Home Assistant to determine the difference between idle and playing, but not enough to determine the difference between playing and paused. With that said, it would be better if media_session_state had a different value for playing vs paused. Thanks again for taking the time to look into this. Link to comment Share on other sites More sharing options...
ebr 14910 Posted June 2, 2020 Share Posted June 2, 2020 Here's what I got with the latest beta (1.8.07) emby idle 'audio_state': 'paused', 'wake_lock_size': 2, 'current_app': 'tv.emby.embyatv', 'media_session_state': 0 emby paused 'audio_state': 'paused', 'wake_lock_size': 3, 'current_app': 'tv.emby.embyatv', 'media_session_state': 3 emby playing 'audio_state': 'paused', 'wake_lock_size': 4, 'current_app': 'tv.emby.embyatv', 'media_session_state': 3 Without using custom state detection rules, it's enough for Home Assistant to determine the difference between idle and playing, but not enough to determine the difference between playing and paused. With that said, it would be better if media_session_state had a different value for playing vs paused. Thanks again for taking the time to look into this. That was just an oversight. Should get fixed with the next one. Thanks for testing. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now