Detect when/if a media_player is able to be turned on in HA

Hi,

I have a Philips TV connected via the Philips TV integration.
A while after I turn off the TV the power on option in HA disappears but the device is still “Available”.
This is not optimal but I found out if I send the Wake on LAN magic package the power button appears again, but it does not turn on the TV however.

My script works if I wait 15 seconds after sending Wake on LAN until I then send the media_player.turn_on command.

Sometimes the power button is “available” again earlier than the 15 seconds so I am looking for a way to detect when/if a media_player is able to be turned on?

I believe this should be possible since I can see the power button appear (and disappear) in the Controls tab on the Device info in HA. There is no visible state change on the device itself, other than the button appearing and disappearing from the controls tab.

You should open an issue here: Issues · home-assistant/core · GitHub

One of these seems back-to-front:

Do you mean you send the WoL packet 15 seconds after turning on, so the button appears again?

Here is my script:

Initial state: TV has the status “off” but no turn on button is available and calling media_player.turn_on does nothing.

Step 1: Send Wake on LAN

this activates something in the TV but does not turn it on

Step 2: Wait 15 seconds

Now the power on button is visible in the HA UI

Step 3: Send media_player.turn_on

This turns on the TV

I tried turning on all options to keep the TV on standby after turning it off, disabled eco mode, turn on WoL, etc.

This works but it is slow, my only idea to increase the speed is to be able to detect when I am able to send media_player.turn_on and then send it immediately instead of always waiting 15 seconds.

Ah right. Now I see. Sorry, I misread your first post. The power button disappears when the TV has been off for a while, not when it has been on for a while. That makes more sense.

So it sounds like the TV network card is going to sleep to save power. If you have tried all the TV setting options then yeah an automation or script will have to do.

Try this:

Step 1: Send Wake on LAN

Step 2: Wait a second

Step 3: Run the update entity service for the TV media player entity

*Step 4: Send media_player.turn_on

Increase the wait time until the TV turns on reliably. This should only be as long as your TV network card takes to wake up and connect. The update entity service will overcome any polling time for the media player integration to recognise this.

If this time delay is still too long, the other option is to write an automation to always keep the network card awake, as it does not turn on the TV you can do this:

Time pattern trigger, just shorter the time it takes for the button to disappear when you turn the TV off, e.g.

trigger:
  - platform: time_pattern
    seconds: "/30"  # triggers every 30 seconds

Action: send your WoL packet.

The third option is to send an infra-red on command instead. This is what I have to do with my TV. The network card is powered down completely when the TV is off and WoL does not work. It is the only IR command I have in all of my many controlled devices (all the other TV commands are via LAN once the TV is on). Of course this requires you have an IR transmitter connected to Home Assistant. You can build a cheap one with ESPHome.

Awesome! Thank you. I will try this tonight and post the results.

Neither technique seems super consistent unfortunately.
I ended up trying the Time pattern trigger sending a magic package every 20 seconds if someone is home and the TV is off. Hopefully it is consistent enough to work most of the time.