How to detect if the phone (or tablet) is off?

If I switch off my phone all states freeze and it appears as it’s on.
Looking through the sensors, I can’t find any that I could rely on to give me a “yes it’s on”.
Sure I could look at batterylevel and see that it has been frozen for x hours, that is a clue.
Same with light sensor, or steps counter, or IP. But all could be still.
I could have my phone on the desk (like now) and I would assume the light sensor won’t change much.
Steps won’t change, and IP may or may not change. Battery could take an hour before I actually know for sure.

Anyone have a suggestion?

We can try to register for the shut down intent but even Android API says no guarantees data will be sent out. We also won’t be able to detect if you lose cell phone data. Your best bet is to make use of last_updated attribute and notify you if the updates hasn’t shown up in a certain time period. Also you can use something like nmap or bluetooth tracking to determine if it’s on at home.

I can try but as I said sometimes nothing actually changes. That means there is no new values.
Perhaps if I check all sensors at the same time.

try the device tracker as it should be reporting quite often if you go by last_updated the timestamp there should be helpful. i’d say a few hours will be telling.

Edit: I see what you mean…you need something that would update often…I think this may need to be a core feature request to do it properly.

Has anybody found a reliable way to tell if an Android phone is on or off? Especially if it’s only on battery. Doing some searching and this is the only thread that talks about it. All of these solutions don’t work reliably.
I also tried the ping sensor but when the phone goes on stand-by, ping stops working even though the phone is on.
I’m also thinking of using the mobile_app_notification_received event, and sending periodic notifications to the phone (which has a persistent socket, to the Home Assitant server, enabled through the Android companion app). But it’s hard to know which exact notification I sent is being received, especially since older notifications can be delivered after the phone was off and was just turned on.
Anyway, any suggestions? I’m also open to using Tasker if that makes any difference.