Android TV HDMI

I am trying to change the HDMI input on my android TV

Most of of the key commands work except the ones for HDMI, which is quite important to me.

It doesn’t work from sending an HDMI command is it is possible to do it from the “select source” component?

What type of tv and what command are you currently trying? The built-in “HDMI1, HDMI2” ?

It’s a Philips 70PUS9005/12. 2020 Model.

Yes HDMI1, HDMI2 ect. There is no dedicated HDMI button so i have to scroll through a menu each time.

I’m sure Android would be able to do it, because I can switch to any HDMI connection using the TVs Google assistant.

You might be able to modify constants.py (in the androidtv component) to contain the command you need, but I don’t know enough about it/python programming to know if having a non-numerical value in one of those would affect anything…

What about

action:
  service: androidtv.adb_command
  data:
    entity_id: media_player.androidtv_tv_living_room
    command: "KEY_HDMI1"

I believe the component is simply using KEY_HDMI1, KEY_HDMI2, etc for the associated HDMI1, HDMI2…

from constants.py:

        "HDMI1": KEY_HDMI1,
        "HDMI2": KEY_HDMI2,
        "HDMI3": KEY_HDMI3,
        "HDMI4": KEY_HDMI4,

which then goes to…

KEY_HDMI1 = 243
KEY_HDMI2 = 244
KEY_HDMI3 = 245
KEY_HDMI4 = 246

the regular key_event

Yes the docs here https://www.home-assistant.io/integrations/androidtv/#androidtvadb_command refer to a list of keys here https://github.com/JeffLIrion/python-androidtv/blob/748d6b71cad611c624ef7526d9928431167531a3/androidtv/constants.py#L189-L233

These are the ones that aren’t working sadly.

Things like up down home and power work ok

I have tried:

command: “KEY_HDMI1”
command: “HDMI1”
command: “input keyevent KEYCODE_F1”
command: “KEYCODE_TV_INPUT_HDMI_1” (From android developers page)

Could this be because i am using the python method rather than an ADB server?

Thank you all for your help so far

Edit: could any of these be possible workarounds?

An App installed on the TV that I could send intents too?

Sending a search query to Google Assistant for example “search… HDMI 1”

Is the a way to listen to what actions Google assistant is carrying out when I do a voice search for HDMI1?

Python ADB vs. ADB server won’t make a difference.

Look at the ADB key event codes on this page: https://developer.android.com/reference/android/view/KeyEvent

Call the androidtv.adb_command service with a command of the form input keyevent x, where x is an integer from that page. Try anything that looks like it might be relevant.

You can also try this: https://www.home-assistant.io/integrations/androidtv/#androidtvlearn_sendevent-for-faster-adb-commands

I have tried input key event with no luck, keyevents for up down back ect work, but not for HDMI :frowning:

I Also can’t see the option for learn send even in the developer options :frowning:

What version of HA are you running? Also, any chance you loaded a custom component for android tv and it’s using that instead of the current version?

I updated HA Core and i now have learn send event, but the behaviour is exactly the same as before.

Learn send event only captures the button press on the remote, not the action that happened. There are no dedicated HDMI Buttons on the remote.

What’s even more annoying is that i cant even setup a sequence of button presses, because the last used HDMI Device goes to the top of the sources list, so the list of HDMI devices is in a different order each time.

I tried a USB keyboard, and pressed all the Function keys and none of them worked, it’s looked like the function keys have been locked out on the TV.

The only way i can get it to go directly to an HDMI Input is with a Google Voice command.

Is there a way to directly send a voice command?

Or better, get a log of what actions it’s performing when I do a voice command?

Have you tried this? Android TV HDMI

I have tired those, and the the input keyevents from the android developers page

Right so what does the log say? Have you turned logging up to max?

The HA log? Nothing appears there, i will set it to max and try again.

But if i misstype it i get an error in the log

??? have you?

Here? https://www.home-assistant.io/integrations/system_log/

I can’t see a way to see set that too max

Sorry you need here :slight_smile: https://www.home-assistant.io/integrations/logger/

debug should get (way) more info.

Ok, so i ran two commands from Androidtv.adb in dev tools

The 1st was “VOLUME_DOWN” which worked

The 2nd was “HDMI1” which didn’t work

Both look like they sent correctly? These are the entries in the log

Volume Down

2020-10-12 10:01:39 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140224019611120] Sending {"id": 2, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "media_player.android_tv_1", "old_state": {"entity_id": "media_player.android_tv_1", "state": "idle", "attributes": {"source_list": ["STREAM_NOTIFICATION:", "com.android.systemui", "org.droidtv.upnp", "com.google.android.tv.remote.service", "dialserver", "com.google.android.gms.persistent", "org.droidtv.ambihue", "ord.droidtv.eum", "org.droidtv.nettvregistration", "com.google.android.katniss:interactor", "com.ndcsolution.androidtv.leankeykeyboard", "com.google.android.apps.nbu.smartconnect.tv", "com.google.android.tvrecommendations", "com.google.android.katniss:search", "com.google.process.gservices", "com.google.android.gms", "org.droidtv.userlogger", "org.droidtv.ambiair", "org.droidtv.ambihue.common", "org.droidtv.philipstvdrawer", "Netflix", "Google Cast", "org.droidtv.amazonalexa", "org.droidtv.eum.demome", "org.droidtv.nettv.market", "org.droidtv.nettvapps", "org.droidtv.eum.sticker", "uk.co.freeview.mdsclient", "com.google.process.gapps", "uk.co.freeview.fvpconfigauth", "com.google.android.partnersetup", "com.google.android.videos", "com.android.vending", "com.android.providers.calendar", "YouTube", "com.disney.disneyplus", "com.android.vending:download_service", "uk.co.freeview.onnow", "uk.co.freeview.tifbridge", "com.android.defcontainer"], "volume_level": 0.0, "is_volume_muted": false, "app_id": "org.droidtv.playtv", "app_name": "org.droidtv.playtv", "source": "org.droidtv.playtv", "adb_response": null, "friendly_name": "Android TV 1", "entity_picture": "/api/media_player_proxy/media_player.android_tv_1?token=cc03c8815a8bc40eec724d517aa367c9c71845421a3f2c95266dab9469f21268&cache=1602493289.926554", "supported_features": 23997}, "last_changed": "2020-10-12T08:57:29.980407+00:00", "last_updated": "2020-10-12T09:01:29.926626+00:00", "context": {"id": "8483dddb0c6911ebbdad174cb0d60a2f", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "media_player.android_tv_1", "state": "idle", "attributes": {"source_list": ["STREAM_NOTIFICATION:", "com.android.systemui", "org.droidtv.upnp", "com.google.android.tv.remote.service", "dialserver", "com.google.android.gms.persistent", "org.droidtv.ambihue", "ord.droidtv.eum", "org.droidtv.nettvregistration", "com.google.android.katniss:interactor", "com.ndcsolution.androidtv.leankeykeyboard", "com.google.android.apps.nbu.smartconnect.tv", "com.google.android.tvrecommendations", "com.google.android.katniss:search", "com.google.process.gservices", "com.google.android.gms", "org.droidtv.userlogger", "org.droidtv.ambiair", "org.droidtv.ambihue.common", "org.droidtv.philipstvdrawer", "Netflix", "Google Cast", "org.droidtv.amazonalexa", "org.droidtv.eum.demome", "org.droidtv.nettv.market", "org.droidtv.nettvapps", "org.droidtv.eum.sticker", "uk.co.freeview.mdsclient", "com.google.process.gapps", "uk.co.freeview.fvpconfigauth", "com.google.android.partnersetup", "com.google.android.videos", "com.android.vending", "com.android.providers.calendar", "YouTube", "com.disney.disneyplus", "com.android.vending:download_service", "uk.co.freeview.onnow", "uk.co.freeview.tifbridge", "com.android.defcontainer"], "volume_level": 0.0, "is_volume_muted": false, "app_id": "org.droidtv.playtv", "app_name": "org.droidtv.playtv", "source": "org.droidtv.playtv", "adb_response": null, "friendly_name": "Android TV 1", "entity_picture": "/api/media_player_proxy/media_player.android_tv_1?token=cc03c8815a8bc40eec724d517aa367c9c71845421a3f2c95266dab9469f21268&cache=1602493299.941363", "supported_features": 23997}, "last_changed": "2020-10-12T08:57:29.980407+00:00", "last_updated": "2020-10-12T09:01:39.941457+00:00", "context": {"id": "8a7c01e20c6911eb95801bccd4aa3f28", "parent_id": null, "user_id": null}}}, "origin": "LOCAL", "time_fired": "2020-10-12T09:01:39.941481+00:00", "context": {"id": "8a7c01e20c6911eb95801bccd4aa3f28", "parent_id": null, "user_id": null}}}

HDMI1

2020-10-12 10:01:39 DEBUG (MainThread) [homeassistant.components.websocket_api.http.connection.140224058484816] Sending {"id": 12, "type": "event", "event": {"event_type": "state_changed", "data": {"entity_id": "media_player.android_tv_1", "old_state": {"entity_id": "media_player.android_tv_1", "state": "idle", "attributes": {"source_list": ["STREAM_NOTIFICATION:", "com.android.systemui", "org.droidtv.upnp", "com.google.android.tv.remote.service", "dialserver", "com.google.android.gms.persistent", "org.droidtv.ambihue", "ord.droidtv.eum", "org.droidtv.nettvregistration", "com.google.android.katniss:interactor", "com.ndcsolution.androidtv.leankeykeyboard", "com.google.android.apps.nbu.smartconnect.tv", "com.google.android.tvrecommendations", "com.google.android.katniss:search", "com.google.process.gservices", "com.google.android.gms", "org.droidtv.userlogger", "org.droidtv.ambiair", "org.droidtv.ambihue.common", "org.droidtv.philipstvdrawer", "Netflix", "Google Cast", "org.droidtv.amazonalexa", "org.droidtv.eum.demome", "org.droidtv.nettv.market", "org.droidtv.nettvapps", "org.droidtv.eum.sticker", "uk.co.freeview.mdsclient", "com.google.process.gapps", "uk.co.freeview.fvpconfigauth", "com.google.android.partnersetup", "com.google.android.videos", "com.android.vending", "com.android.providers.calendar", "YouTube", "com.disney.disneyplus", "com.android.vending:download_service", "uk.co.freeview.onnow", "uk.co.freeview.tifbridge", "com.android.defcontainer"], "volume_level": 0.0, "is_volume_muted": false, "app_id": "org.droidtv.playtv", "app_name": "org.droidtv.playtv", "source": "org.droidtv.playtv", "adb_response": null, "friendly_name": "Android TV 1", "entity_picture": "/api/media_player_proxy/media_player.android_tv_1?token=cc03c8815a8bc40eec724d517aa367c9c71845421a3f2c95266dab9469f21268&cache=1602493289.926554", "supported_features": 23997}, "last_changed": "2020-10-12T08:57:29.980407+00:00", "last_updated": "2020-10-12T09:01:29.926626+00:00", "context": {"id": "8483dddb0c6911ebbdad174cb0d60a2f", "parent_id": null, "user_id": null}}, "new_state": {"entity_id": "media_player.android_tv_1", "state": "idle", "attributes": {"source_list": ["STREAM_NOTIFICATION:", "com.android.systemui", "org.droidtv.upnp", "com.google.android.tv.remote.service", "dialserver", "com.google.android.gms.persistent", "org.droidtv.ambihue", "ord.droidtv.eum", "org.droidtv.nettvregistration", "com.google.android.katniss:interactor", "com.ndcsolution.androidtv.leankeykeyboard", "com.google.android.apps.nbu.smartconnect.tv", "com.google.android.tvrecommendations", "com.google.android.katniss:search", "com.google.process.gservices", "com.google.android.gms", "org.droidtv.userlogger", "org.droidtv.ambiair", "org.droidtv.ambihue.common", "org.droidtv.philipstvdrawer", "Netflix", "Google Cast", "org.droidtv.amazonalexa", "org.droidtv.eum.demome", "org.droidtv.nettv.market", "org.droidtv.nettvapps", "org.droidtv.eum.sticker", "uk.co.freeview.mdsclient", "com.google.process.gapps", "uk.co.freeview.fvpconfigauth", "com.google.android.partnersetup", "com.google.android.videos", "com.android.vending", "com.android.providers.calendar", "YouTube", "com.disney.disneyplus", "com.android.vending:download_service", "uk.co.freeview.onnow", "uk.co.freeview.tifbridge", "com.android.defcontainer"], "volume_level": 0.0, "is_volume_muted": false, "app_id": "org.droidtv.playtv", "app_name": "org.droidtv.playtv", "source": "org.droidtv.playtv", "adb_response": null, "friendly_name": "Android TV 1", "entity_picture": "/api/media_player_proxy/media_player.android_tv_1?token=cc03c8815a8bc40eec724d517aa367c9c71845421a3f2c95266dab9469f21268&cache=1602493299.941363", "supported_features": 23997}, "last_changed": "2020-10-12T08:57:29.980407+00:00", "last_updated": "2020-10-12T09:01:39.941457+00:00", "context": {"id": "8a7c01e20c6911eb95801bccd4aa3f28", "parent_id": null, "user_id": null}}}, "origin": "LOCAL", "time_fired": "2020-10-12T09:01:39.941481+00:00", "context": {"id": "8a7c01e20c6911eb95801bccd4aa3f28", "parent_id": null, "user_id": null}}}