Detect when Firestick or Android TV 'off'?

Hey guys. I have Firesticks and Android Tv sticks on all of my ‘dumb’ tvs. I would like to detect when the TV is turned off. Is there a way to monitor that state or perhaps even a way to detect when it has been idle for a while?

I am using ADB integration now but it seems the fire sticks will go from playing to idle even when nothing is happening on the device. Any advice is most appreciated.

Can you do it by checking the source of the programme? I use Android TV remote rather than the ADB integration:

# TV on
# Based on which channel the TV is tuned to. Home menus count as "on";
# standby counts as "off"

  - binary_sensor:
      - name: "tv on"
        unique_id: 19b0260a-cadf-4e72-bb47-a8f2fe91e3fc
        state: >
          {% if state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.mediatek.tv.freeviewplay' %}
            on
          {% elif state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.netflix.ninja' %}
            on
          {% elif state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.amazon.amazonvideo.livingroom' %}
            on
          {% elif state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.google.android.youtube.tv' %}
            on
          {% elif state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.apple.atve.androidtv.appletv' %}
            on
          {% elif state_attr('media_player.uk_2k_android_tv', 'app_id') == 'com.google.android.apps.mediashell' %}
            on
          {% else %}
            off
          {% endif %}
          
# BBC/ITV/C4 etc. com.mediatek.tv.freeviewplay
# Netflix com.netflix.ninja
# Amazon Prime com.amazon.amazonvideo.livingroom
# Youtube com.google.android.youtube.tv
# AppleTV com.apple.atve.androidtv.appletv
# Casting com.google.android.apps.mediashell

That seems to be the case for the ADB integration also when I’m not really playing any media, i.e. when I’m browsing for new content.

But when I turn it off, the state actually shows as being ‘off’:
image

It seems to show this is for the media_player entity, not for the remote one

image

Ah. I’m seeing the same. You can see at the top when I was actually watching the TV before bed. Then the power button is pressed on the remote and it shows turned off. I do get a ton of ‘Unavailable’ followed by ‘Turned off’ for unknown reasons but I can work with that.

My use case for this is to turn off the voice assistant display when the tv turns off so that the room can finally be darker.

Thanks to you all for the help!