Need Help Automating AirPlay Source Change With An LG TV

I have an LG C1 TV that I have been using through HomeKit for over a year and it works perfectly to turn the TV on, off & to change inputs using the native HomeKit implementation (the tv directly into the home app, not via HA).

When I first setup HA, I left the TV in HK native, and used the LG webOS TV integration to get the TV into HA & this worked very well. The only issue was that HA could not tell when the TV was on the AirPlay source because the LG integration just doesn’t recognize AirPlay as the current source (even though it recognizes airplay as the current app ID in the diagnostic data).

Since I want to trigger a script whenever the source changes to airplay, I figured the only way to do this was to remove the TV from the home app (HomeKit native) and add it to HA using the HomeKit (device) Controller integration (since HomeKit can see when airplay is the source). I would then re-expose this TV to HomeKit using the bridge integration.

This is where my problems come in. Adding the TV to HA using HK Controller worked for my airplay script, but HA cannot turn the TV on using it (the HomeKit TV through HA becomes unavailable when the TV is off -this doesn’t happen when in the home app natively). If I try to use the native LG integration’s TV, it can turn the TV on, but not off.

Summary of problems:

  1. LG webOS TV Integration is unaware of “AirPlay” as a source
  2. LG webOS TV Integration cannot turn TV “on” or “off”
  3. Native HK Integration (through HA) cannot turn TV “on”
  4. Native HK Integration TV device goes unavailable in HA when TV is off

It seems like my options are (1) go back to exposing the TV to HomeKit natively to have a fully working TV with on & off, but no airplay script automation since the LG integration can’t tell when the source is AirPlay (HA won’t know source is AirPlay & home app cannot use source changes as triggers), or (2) figure out another way to turn the TV on or off, or another way to automate the airplay source.

I tried to make a script that calls the turn_on service of the LG integration TV when the HomeKit TV is turned on (I also tried using the command service), but this doesn’t work because the HomeKit TV keeps going unavailable whenever it is turned off (as soon as I turn the actual TV back on it becomes available).

I filed a bug report on GitHub about the AirPlay source/input, because it would solve all of my issues if HA would just see it, but it has been weeks without a response. I figure I’ll have to find another way if I want to make this work.

I was hoping someone out there with this TV would have an idea for me or has already figured this out. Both the TV & the HA Pi are hard wired to the router & all mobile app & WOL options of the TV are on. I am at a loss as to why the LG integration can’t turn it off and why the native HomeKit can’t turn it on…

Edit: For now I have found that I can use the Homebridge LG webOS TV plugin to expose an “app button” for airplay. This seems to be working but is less than ideal. I am trying to eliminate Homebridge, not rely on it more heavily.