TCL Roku TV turns off twice every time; need workaround

I have an automation to turn on some lights after I turn off my TCL Roku TV. The automation works fine except that it always fires twice because the TCL Roku TV reports to HA as having turned off twice: once when I hit the power button on the remote and then again 13 minutes later, every time.

This is annoying if I have already turned off one of those lights and few minutes later it turns on again because the TV just turned off for the second time. My hunch is that this has something to do with the TV’s quick start/standby mode. Which I don’t really want to disable. So I need a clever workaround.

How would you set up the automation so that the lights turn on when the TV turns off the first time but nothing happens when the TV turns off the second time?

If anyone stumbles across this looking for a solution to the same/similar problem, here’s what I did: I added a Template to the conditions with the following script

{{ is_state('media_player.65_tcl_roku_tv', 'off')
   and (as_timestamp(now()) - as_timestamp(states['media_player.65_tcl_roku_tv'].last_changed)) < 60 }}

The Template condition passes if the TV has been off for less than 60 seconds. So when the TV changes state again 13 minutes after turning off, it won’t trigger the automation again.

Another option is to use your iPhone’s CarPlay or Bluetooth connection as a trigger in Home Assistant. You could create a template binary sensor that turns on when your phone connects to the car’s Bluetooth, then use that in your automation instead of relying solely on the activity sensor. Works pretty reliably for me.

I think you replied to the wrong thread. This issue is not related to CarPlay or Bluetooth.