Getting the image/art from media_player/androidtv as a generic camera

Tags: #<Tag:0x00007f7392aa1f38>

I’m using a media_player/androidtv integration, and it works fine. The nice thing is I get a screenshot of the tv screen as an album art for the component. I’d like to be able to expose this album art as a generic camera in home assistant (mostly to have a bigger visual feedback of what’s going on when using a virtual remote for navigation).

I was thinking of building a custom component that runs the necessary adb command to get a screenshot, but since the image is already in HA, maybe there is a simpler/more efficient way of doing things…

So, two questions:

  1. Is there a way to expose the image through configuration/automation? I don’t see anything in the media_player’s attributes, nor the services associated with media_player.
  2. If not and I create a custom component like a generic camera, am I allowed to access internal methods/variables from the media_player instance?

Are there better ways of doing this?
[email protected]

1 Like

I had the same idea as you. I ended up using the mini media player custom card (which as you’ll see the mini name is a bit of a misnomer) from HACS as you can set the card to have the album art just stretch the card. Then I get as much or as little media controls on the card as I want as well.

My card config looks like this

type: 'custom:mini-media-player'
entity: media_player.lounge_room_tv_adb
name: Lounge Room TV
icon: 'mdi:television'
artwork: full-cover
hide:
  volume: false
  source: true
  power_state: false
  info: true

Which looks like this

Of course I’m sure the custom card lets you turn off most if not all of its interface which essentially will make it act as a camera entity. also if I make a new tab in lovelace, set it to panel view and then have this card on it it scales that “album art” all the way up to fit whatever device I’m using it on and it seems to be a very high resolution. Which looks like this.


This is neat because I can watch my tv on another device at less than 1 fps but also concerning because I’m not sure how much network traffic this is creating and how much CPU time this is taking up on my TV and my Pi. I now wonder if I can actually turn it off haha. Lovelace: Mini Media Player

2 Likes

Thanks for the idea!

The reason I wanted it as a separate “virtual” camera was to expose it to appdaemon as well so I could view it on my appdaemon panel. Not sure if I can see lovelace items in the appdaemon dashboard.

fair enough! different use case :slight_smile:

I must have missed something! How do i get screenshots to work? I run it with adb server and if i set full-cover in mini media player i dont get an image like yours. Do i need to set som parameter in the config file to get this?

This is my full config:

media_player:
  - platform: androidtv
    name: TV Bedroom ATV
    host: 192.168.1.61
    device_class: androidtv

I seem to remember having to authorize ADB either from the host that runs HA or from inside the container on the TV (so a popup appears asking if I want to allow it). Also, enable ADB over network on your TV. Do other commands on the media player work? What version is your android TV? I’m using it with ATV 9 on a Philips TV.

I have done this in the past for other media players, it is definitely able to be done, let me dig up my code I’m not infront of pc atm I’ll come back to you.

Here you go.

Create a camera image with you details like below

  - platform: generic
    name: Android Now Playing
    still_image_url: http://10.0.20.3:8123{{ states.media_player.android_tv.attributes.entity_picture }}
2 Likes

Thank you for the tip!
Indeed, under the media player attributes I could find:

entity_picture: /api/media_player_proxy/media_player.tv_bedroom_atv?token=xxxxxxxxxxxxxxxxxxxxxx&

Than can be used directly with the HA URL to produce a picture that I can use under appdaemon (or anything else).

Thanks a bunch!

2 Likes

Got it to work after rebooting tv and HA. But the image blinks all the time…so its not static image in the mini media player.

Maybe it’s a network issue and it times out? Is your ATV connected over wifi? It may go into sleep more frequently. I’m running wired.

Running it Wired to.

could be to do with android bridge how are you running the bridge?

I run the adb addon like this:

For what its worth, I didnt use the ADB addon. I just use the built in python ADB implementation. Maybe they handle it differently?

Might test that then! Thanks for the input.

Did you manage to stop the blinking?

1 Like