Determine ShieldTV / AndroidTV app as a condition?

Hello, I’m trying to set up an automation that simply turns off lights when the NVdia Shield is playing Netflix or YouTube.

The basics work:

- id: '1576862696029'
  alias: Dim Lights when Netflix
  description: ''
  trigger:
  - entity_id: media_player.nvidia_shield
    from: idle
    platform: state
    to: playing
  action:
  - device_id: 051620551ed94880be6aad00f85e8560
    domain: light
    entity_id: light.dinner_light
    type: turn_off
  - device_id: 855887417535466ca22f0c9229b3d8d3
    domain: light
    entity_id: light.hue_play_3
    type: turn_off
  - device_id: 8ba80a321da74d82814448e6f675d2e3
    domain: light
    entity_id: light.color_bulb
    type: turn_off
  - device_id: ce5781fad318478e93abed9d901c58a6
    domain: light
    entity_id: light.hue_play_2
    type: turn_off
  - device_id: caa3b06d28eb496cadeb8eadd28a7e75
    domain: light
    entity_id: light.closet_light
    type: turn_off
  - device_id: d0a835fc416f4fd7945346da34d7933d
    domain: light
    entity_id: light.desk_lamp
    type: turn_off
  - device_id: ea83c6a4d8664e3c9edc9d5107bb21bc
    domain: light
    entity_id: light.hue_play_1
    type: turn_off
  - device_id: 79cd4906eab243368fad6b0bab17d55e
    domain: light
    entity_id: light.couch_light
    type: turn_off

but now I’m trying to do this only for Netflix and YouTube (maybe Plex)

But I can’t find a condition that would check for the current app :confused:

What would be the best approach? I saw this cool approach by binascii here Updated 22/9/19 - Android/Nvidia Shield - Application based Automation (watching netflix turns off lights) but I’d like to keep it “within” the default tools if that makes sense?

Hello and welcome to the forum. I am not a professional and unfortunately I cannot help directly. But maybe that will help you … Go to “Developer Tools” then to “Events” now enter “state_changed” in the field “Event to subscribe to” and press “Start Listening”. Now you start Netflix. An entry would then have to be created here. Maybe this will help you, if not someone who has already set up will get in touch soon …
Have fun continuing to set up HA …

3 Likes

Interesting Idea! I’ll give it a shot later

So in the end i didnt manage to figure out a way to “check which app” is running :frowning: But I managed to find the correct states to switch between the lights.

- id: '1576862696029'
  alias: ShieldTV Lights Off
  description: ''
  trigger:
  - entity_id: media_player.nvidia_shield
    from: standby
    platform: state
    to: playing
  - entity_id: media_player.nvidia_shield
    from: paused
    platform: state
    to: playing
  condition: []
  action:
  - device_id: 051620551ed94880be6aad00f85e8560
    domain: light
    entity_id: light.dinner_light
    type: turn_off

- id: '1576865173829'
  alias: ShieldTV Lights On
  description: ''
  trigger:
  - entity_id: media_player.nvidia_shield
    from: playing
    platform: state
    to: standby
  - entity_id: media_player.nvidia_shield
    from: playing
    platform: state
    to: paused
  condition: []
  action:
  - device_id: 051620551ed94880be6aad00f85e8560
    domain: light
    entity_id: light.dinner_light
    type: turn_on

(excuse the amount of bulbs)
my old used “idle” term didnt work and i had to use “standby”.

I’ll keep looking for a way to determine the apps tho, that’d be really helpful.

I’m not at home right now to test, but I belive that the currently running app is represented as an attribute and can be tested with a template. If you go into Developer Tools->States and find your Shield, you should see an attribute with a long string indicating the current app if one is active. For YouTube TV, for instance, you’ll see something like “com.google.android.youtube.tvunplugged”. Strings for other apps can be found here.

You can either use a template trigger or condition to check it. I used to have an automation that did exactly this, but I found that a better way to do what I needed to do and got rid of it.

@rccoleman seeing the app used on a Shield is only possible if you use the Android TV integration and set up an ADB Server. I have that set up and and it works well. I am able to detect whatever app is running on my shield and create automations around them.

Hey millsx2 could you provide 1 or 2 examples on how you detect / automate them? :slight_smile:

Nope, that seems to have changed with 0.101. I have it setup with the Python implementation, and it shows the actually running app as an attribute of the media player entry. :slight_smile:

@rccoleman Would you mind sharing your better solution? :slight_smile:

I was using a condition in a script to check if an ADB command had actually launched an app because it was not working reliably. It turned out that I had a race condition causing the instability, so I fixed that and removed the extra checks and redundant actions.

1 Like

Let me know if you find a better method, my solution was always a bit of a rube goldberg machine with a few too many moving parts.

Rube Goldberg is sometimes the best approach :smiley: I swapped to your method actually it works pretty good. ADB sometimes seems a bit “slow” and light-dimming only happens after like 10-20seconds but hey if it works, it works!

1 Like

If you lower the

scan_interval: 10 to
scan_interval: 5

it might pick up the change more quickly. I haven’t tested it though. I was unable to find a better way to control lights based on running app but I also stopped when I found that adb method.

Cheers

1 Like