Help with media player and HomeKit control

Hello @barns102!

You need to set this on customize.yaml:

media_player.your_media_player:
  device_class: tv

And then on homekit config:

entity_config:
  media_player.your_media_player:
    name: "TV"
    feature_list:
      - feature: on_off
      - feature: play_pause
      - feature: play_stop
      - feature: toggle_mute

You will get something like this:

Including source select, very neat!

2 Likes

Hurrah, you’re a Star!!!

Thank you so much, that certainly worked, in that I can now see a media player tool in my HomeKit App. But there are still some problems.

1 - I can’t turn the TV on, I toggle the switch on, and nothing happen although the App says its on. Then if I toggle it off the TV comes on. I guess it’s sending the off command (which is the same as on??)

2 - I can’t control the volume

3 - I have an input select feature, but no inputs show up so I can’t select any.

Do you have any more suggestions.

Thank You - Thank You - Thanks You!!! :slight_smile:

Hello sir! I am glad I could help.

What media player TV component do you use? Since I use LG WebOS, there is a separate turn on command that I can send using a Broadlink RM Mini. To turn off it is simple internal command to the WebOS.

I’m also unable to set the volume of my TV from the Home App, not sure why but it seems tricky.

I’ve found that this solves the problem, you might need to remove this media_player entity that you have set on HomeKit, restart HA, add this to your customize.yaml, add back again the device to HomeKit and restart HA:

media_player.your_media_player:
  device_class: tv
  source_list: [DTV,HDMI 1,HDMI 2,HDMI 3,HDMI 4]

You need to check on your dev_state the available sources and add them as the code above. You don’t need to enable all of them, I’ve only exposed the sources I want to show on the Home App (there were dozens of them, they were all apps installed on my TV). Here is my entity properties as for now (using the smart_ir media player custom component since that’s a “dumb” TV):

Good luck!

3 Likes

Hi @Schneider

You mentioned being able to set up this media player HomeKit button to send commands using your broadlink RM. Could you possibly paste that element of your configuration? Thank you

Edit: @barns102 were you able to get that tv icon in HomeKit to send broadlink commandsv

There are 2 things you need (possibly 3 depending on what your HomeKit config is)

Firstly setup the SamrtIR config, here’s mine:

switch 4:

  • platform: broadlink
    host: !secret lounge_rm_host
    mac: !secret loung_rm_mac

media_player 2:

  • platform: smartir
    name: Barns TV
    unique_id: barns_tv
    device_code: 0
    controller_data: !secret lounge_rm_host

Secondly you need to make sure that you have the following in your customise.yaml

media_player.barns_tv:
device_class: tv

If you include and exclude devices to HomeKit, then of course you need to make sure your media_player is exposed.

Does this make sense?

Hello!

@barns102 got it right, just follow his steps.

My config is a little different, since I don’t need all my sources exposed on the Home app:

Customize:

media_player.tv_dinamica:
  device_class: tv
  source_list: [TV,HDMI 1,HDMI 2,HDMI 3,HDMI 4]

Media Player:

- platform: smartir
  name: "TV Dinâmica"
  unique_id: "tv_dinamica"
  device_code: 1040
  controller_data: 192.168.1.41
  power_sensor: binary_sensor.energia_tv_dinamica

HomeKit:

filter:
  include_entities:
    - media_player.tv_dinamica
entity_config:
  media_player.tv_dinamica:
    name: "TV dinâmica"
    feature_list:
      - feature: on_off
      - feature: play_pause
      - feature: play_stop
      - feature: toggle_mute

If you are using broadlink to control a “dumb” TV, as my example above, you will need to have this:

Broadlink switch:

- platform: broadlink
  host: 192.168.1.41
  mac: '34:5A:3A:7F:6B:01'
  timeout: 15
  friendly_name: "RM Mini sala 303"
  type: rm_mini

SmartIR component that you can find it here: https://github.com/smartHomeHub/SmartIR/blob/f4e87f7f3e0ed2f1b1cceda149a6797dc902cbe3/docs/MEDIA_PLAYER.md

If you have a meda player compatible TV, as one of mines LG WebOS, you can add it as a native media_player component and follow the instructions above.

Good luck!

1 Like

Hi @Schneider!

Thank you for replying, I wish that I has this sorted out in my head as well as you do!

I tried patching together what you posted but my HA collapsed and my config file hates me :(:nauseated_face: I was wondering if you could take a look at what I have, and tell me how far from working code? I’m trying to control a ‘dumb as a rock tv’ with the broadlink IR device sending commands but looking like a HomeKit tv.

here’s the nightmare franked-code for your amusement!

homekit:
  auto_start: false
  filter:
   include_entities:
     - media_player.tv_bedroom
    exclude_entities:
      - automation.start_homekit
      - sensor.illumination_7811dcb7d9e9
      - input_boolean.xiaomi_vacuum_cleaner
    
entity_config:
  media_player.tv_bedroom:
    name: "TVbedroom"
    feature_list:
      - feature: on_off
      - feature: volume_up
      - feature: volume_down

- platform: broadlink
    host: 10.0.0.22
    mac: 'XXX:Secret?:XX'
    type: 'rm_mini'
    switches:
      tv:
        friendly_name: "tv_bedroom"
        command_on: 'JgAsAQADiJ6anpkABOwAA4yemp6ZAAdhAAOMnpmemgAE6wADjZ6Zn5kAB2AAA4yemZ+ZAATrAAOOnZqemQAHXwADjp2anpkABOsAA4+dmZ6aAAdfAAOOnZqemQAE6wADjZ6anpkAB18AA4+dmaGXAATrAAONnpmemgAHXwADjZ6anpoABOoAA4+cmp6ZAAdhAAOMn5iemgAE7AADjJ6ZnpoAB2EAA4yemZ6ZAATwAAOLnpeemQAHYQADjJ6ZnpoABOsAA46dmZ6aAAdfAAONnpqemQAE7QADjpyZnpkAB2AAA46dmZ6aAATrAAOPnJqdmgAHYAADjpyanpkABOwAA46cmp6ZAAdhAAOMnpmemgAE7AADjJ6anpkAB2AAA4yemp6ZAATsAAONnpmemQANBQAAAAAAAAAAAAAAAA=='
        command_off: 'JgAwAAAEH5+YAAE/mQADqwAEJp2YAAE/mQAGIQAEJJ6YAAFAmAADrAAEI5+ZAAE/mAANBQAAAAAAAAAA=='
        volume_up: 'placeholderIRcode!'
        volume_down: 'placeholderIRcode!'

Hello sir!

I am sorry to hear that you are still having problems with that :frowning:

As I can see on your configs, you don’t actually have a media_player entity configured, just the broadlink switch (tv). This will not do the trick, you need a media_player in order to work.

I also have a dumb TV, you just need to use the custom component SmartIR first. Have you managed to make it work?

Thanks.

I’m also looking for a little help controlling my Sony Bravia TV. HA can see and control the TV fine but I can’t seem to expose this to Homekit.

media_player:

  • platform: braviatv
    host: 192.168.1.186

homekit:
filter:
include_entities:
- switch.kitchen_blind
- switch.heat_pump
- light.tv_backlight
- light.bedroom_bed_light
- light.lh_bedside_lamp
- light.rh_bedside_lamp
- sony_bravia_tv
entity_config:
media_player.sony_bravia_tv:
name: “TV”
feature_list:
- feature: on_off
- feature: play_pause
- feature: play_stop
- feature: toggle_mute

homeassistant:
customize: !include customize.yaml

In the customize.yaml I have the following

media_player.sony_bravia_tv:
device_class: tv

I think this should be correct???

Hello!

It seems that you misspelled the entity ID on include_entities. You wrote - sony_bravia_tv instead of - media_player.sony_bravia_tv.

1 Like

Second pair eyes for the win!!! Thank you sir

1 Like

I am having the same issue with a smartir media_player being controlled from Google Assistant (via Nabu Casa). Volume control doesn’t work from Google. My Google Home Hub shows volume buttons for the device but they do nothing. Voice commands have no effect.

I’m confused by what you said above… you said you’re unable to set the volume, but follow up saying that removing the media_player, editing customize.yaml, and then adding the media_player back works. I tried that (syncing devices to Google in between each step) but still no luck.

media_player:
  # Yamaha Surround (old)
  - platform: smartir
    name: Living Room Receiver
    unique_id: living_room_receiver
    device_code: 1120
    controller_data: 192.168.86.48
media_player.living_room_receiver:
  device_class: speaker

Hello!

Volume control still does not work using SmartIR or even the WebOS media player components.

In the previous message I was trying to help Douganator to simply show the media player as a TV on HomeKit, not controlling the volume. He was having trouble with that.

Thanks.

Thanks for the clarification!

I found a related issue about this on GitHub and it sounds like the problem is that Google Assistant (and I guess HomeKit) volume control only works for entities that have absolute volume and not relative volume. Although there’s a slim chance that a semi-recent change in HA could change that. And if not, I had an idea that might work to allow relative volume control while reporting absolute volumes to Google/HomeKit, so I suggested it to the smartir author.

1 Like

This won’t help with HomeKit, but I figured out how to make it work in Google Assistant and opened a Pull Request: https://github.com/home-assistant/home-assistant/pull/26585

I’m sure the logic will be very similar for HomeKit, if someone was inclined to try and fix it.

Great job! That’s really useful! Thanks a lot.

Hi, I am very new to home assistant. I am trying to integrate my Android TV with Apple Home.

I tried the following:

configuration.yaml

# Configure a default setup of Home Assistant (frontend, api, etc)
default_config:
homeassistant:
  customize: !include customize.yaml
  homekit: !include homekit.yaml
# Text to speech
tts:
  - platform: google_translate
group: !include groups.yaml
automation: !include automations.yaml
script: !include scripts.yaml
scene: !include scenes.yaml
media_player:
  # Use the Python ADB implementation with a user-provided key to setup an
  # Android TV device. Provide some app names and don't display other apps
  # in the sources menu. Override the default turn on/off commands, and
  # provide custom state detection rules.
  - platform: androidtv
    name: Android TV
    device_class: androidtv
    host: 10.0.0.26
    adbkey: "/config/android/androidtv_adbkey"
    turn_on_command: "input keyevent 3"
    turn_off_command: "input keyevent 223"

customize.yaml

media_player.android_tv:
  device_class: tv

homekit.yaml

filter:
  include_entities:
    - media_player.android_tv
entity_config:
  media_player.android_tv:
    name: "TV"
    feature_list:
      - feature: on_off
      - feature: play_pause
      - feature: play_stop
      - feature: toggle_mute

Yet when I try to reboot I get this error:
[139780283081920] The system cannot restart because the configuration is not valid: extra keys not allowed @ data[‘homekit’]

What did I do wrong?

Did you ever get this figured out to connect your android TV to HomeKit? Trying to do the same with a google Chromecast with Google TV and running into the same issues.
I started a separate post about it but no one chimed in to help.
https://community.home-assistant.io/t/connect-google-chromecast-with-google-tv-to-homekit-via-bridge-with-proper-tv-controls/564534

I’ve had a similar issue with android tv and Apple TV connected to it. I wanted one tv in HomeKit that can control both of them through one HomeKit remote turn on and off both of them and as well have apps from both of them in one source list.

But now to get to a possible solution.
First install media_player_template integration through hacs and configure it so it can control your chromecast ( following the template modify to what you’d like to accomplish with it). Then using universal media player integration create a new media player whose child entity is the media player template one and android tv one ( or if you’ve configured the app list in the media player template leave out android tv from children list). Turn on and off goes for both entities and volume up and down can be either of them or both of them. Once you’ve configured the universal media player, add the device_class: tv at the end. In home assistant HomeKit add this universal media player as an accessory. Once that is done, you should be able to control them both. Just remember, to get them both to work together in HomeKit you should also get the states for on and off and make an automation that can turn on and off either depending on which one is on or off.

Just pointing you to a direction I took, might help

just stumpled across and your intention for homekit is wron should be the same level than homassistant: and tts: