Detecting when the display turns off automatically, and *only* in that case?

164 views
Skip to first unread message

Soudane GMTA

unread,
Dec 20, 2021, 7:36:44 PM12/20/21
to Tasker
I know how to use the "Display" context to detect when the display is turning on and turning off.

However, I'm wondering whether there is a way to detect when the display turns off *only* because of the "Sleep after X minutes" item in the Settings, and not for any other reason.

In other words, I want to be able to distinguish between the display turning off because of a button click and the display turning off automatically due to this inactivity timeout having been reached.

Is this possible in Tasker?

Thank you in advance.

jmjc...@gmail.com

unread,
Dec 20, 2021, 9:38:35 PM12/20/21
to Tasker
Yes. Use the Logcat Event context. The two events you described create different logs in the system. Look at logs with the PowerManagerService (your device may be different) component.

Dave W

unread,
Dec 20, 2021, 9:40:40 PM12/20/21
to Tasker

There are a lot of "about to's" I wish Tasker would give me the ability to detect.  So I'm hoping to to get some new information from responses to your post.  Still.  The power button will probably always be the grim reaper.

Soudane GMTA

unread,
Dec 21, 2021, 10:35:45 AM12/21/21
to Tasker
Thank you! I forgot about Logcat Event. That should do the job for me. I'll try that and report my findings a little later.

Soudane GMTA

unread,
Dec 21, 2021, 1:22:25 PM12/21/21
to Tasker
Yes, the Logcat Event indeed works for me.

I use it with its Grep Filter to trigger a task whenever PowerManagerService log messages appear. In that triggered task, I then check for %lc_text matching (via regex) sleep  *due  *to  *timeout for the timeout case and sleep  *due  *to  *power for the power-button case. I am now successfully distinguishing those two cases.

Dave W

unread,
Dec 21, 2021, 1:35:57 PM12/21/21
to Tasker

Thanks.  Very helpful.  I've archived your findings for future reference.  However, based on my experience, I believe that often special permissions, force stops, needing to  know that the power button was pressed, etc, etc are ways to avoid finding and solving an underlying problem. 😀😀😀😀

Soudane GMTA

unread,
Dec 21, 2021, 1:40:04 PM12/21/21
to Tasker
PS: I'm deliberately using space-space-asterisk as grep's whitespace separator, above, instead of space-plus-sign. This is because there are different versions of grep floating around the Android world, and some of them might only handle the ancient, stone-age grep regex syntax which didn't support the plus sign to mean "one or more occurrences". Back in those days, grep only used to support asterisk to mean "zero or more occurrences".

If you are sure that your Android instance's grep can handle the plus sign in regexes, then those two patterns, above, can use space-plus-sign as the whitespace separator.

Soudane GMTA

unread,
Dec 21, 2021, 1:43:50 PM12/21/21
to Tasker
Agreed. And this Logcat Event mechanism can easily check for all those cases, as well.

For me, I have a specical case where I want to know specifically when sleep timeout has been automatically initiated. Now, I can know this.

Dave W

unread,
Dec 21, 2021, 2:17:50 PM12/21/21
to Tasker

I hope you didn't take offense to my comment.  If you did, I apologize.  How big are one of the logcat files?  Can you delete them?

Soudane GMTA

unread,
Dec 21, 2021, 3:04:52 PM12/21/21
to Tasker

No offense at all. The idea of "offense" never even occurred to me. You were just making a point. But thank you for checking.

"logcat" is a long-standing Android construct. Those logs are always kept internally. The OS takes care of managing them, deleting them, etc. Tasker has a way to monitor them, via the Logcat Event context.

There are a number of apps which can be used to view and query logcat entries. Just do a search for "logcat" in the Play Store.

Also, from the Android shell, you can utilize the logcat command. Just type logcat -h from the ADB shell to see all of the options.


Dave W, BSEE,MSCE,OOP

unread,
Dec 21, 2021, 7:57:00 PM12/21/21
to Tasker

Thanks for sharing all that info.  But in 10 years of using Tasker, I've never needed to root my phone nor required special permissions.  I guess I don't use Tasker to do anything particularly special LOL.That and I'm really good at coming up with work arounds and tricks.  So it's a big step for me to use special permissions.  Right now I'm leaning toward not using them.
Reply all
Reply to author
Forward
0 new messages