Trying to set up a smart screen to keep the screen on when needed

194 views
Skip to first unread message

K CD

unread,
Apr 5, 2016, 8:29:50 PM4/5/16
to Tasker
I have already started work on it but am facing some problems with the motion detection.

Here's the idea:

Keep the screen alive:
1. If there is any motion detected while "face up"
2. When being charged "face up"
3. While in any orientation other than "face down" or "face up"
4. When the proximity sensor is swiped

Turn the screen off if the phone is: 
1 Placed face down on a flat surface
2 Placed face up on a flat surface without activity - activity being the usual as well as motion and proximity while the screen is still alive and without being charged. (this is the difficult part)

The screen set to on if it is not face up or face down is easy. Setting it to go to sleep when turned face down with the proximity sensor covered also easy. 

The difficulty is when it is face up. Making it sleep is easy, but under certain conditions it shouldn't - when charging and when motion is detected. The charging part is easy. It's the detection of motion that's giving me a hard time.

What I have done is set the screen to not turn off when placed face up and to turn off in 15s when motion is detected. The detection is high sensitivity so the screen stays on because when held face up motion will always be detected and the 15s is prolonged.. 

As soon as the phone is placed down the last event will be motion and it will turn off in 15s. That is all good - it works. Now here is the hard part. The motion detection event is only for when the screen is face up, as soon as it moves
into another orientation they are set to stop triggering an event to turn off the screen - the problem is there is so much motion that the events seem to carry through to the next orientation and over-ride the requirement that the screen stays on. Is there a way
to prevent this from happening - to reduce the time buffer between motion events to practically nothing and to set a little delay when the phone moves into the next orientation before that action - keeping the screen on - is triggered?

Rich D

unread,
Apr 5, 2016, 9:31:21 PM4/5/16
to Tasker Google Groups Post

Is there a way
> to prevent this from happening - to reduce the time buffer between motion events to practically nothing and to set a little delay when the phone moves into the next orientation before that action - keeping the screen on - is triggered?

It would be best if you could post all relevant profile and task descriptions.

To post your profile or task here...  Long press on the profile or task name / ( 3 dot menu with 4.0+ ) export / export "DESCRIPTION" to clipboard (not XML)

Any linked tasks will be exported with the profile they are linked to..

To be able to export, The beginner mode needs to be off and the profile needs to be named by you (Not the Tasker listed name.  Tasker will list your profile with the context name if you have not given it one).

- the problem is there is so much motion that the events seem to carry through to the next orientation

You should be able to figure out why this is happening from the run log. Menu / more / run log.

Are you using the %PACTIVE (profiles active) and the profiles active contexts?

Message has been deleted

K CD

unread,
Apr 5, 2016, 10:24:26 PM4/5/16
to Tasker
In case you saw my reply before I deleted it - it didn't post the complete project. Here it is again:

Profile: FaceDownOff (9)
Priority: 50
State: Orientation [ Is:Face Down ]
State: Proximity Sensor
Enter: 15s (2)
A1: Display Timeout [ Secs:15 Mins:0 Hours:0 ] 

Profile: ChargingOn (10)
Priority: 45
State: Power [ Source:Any ]
Enter: 10min ~FaceDownOff (6)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] If [ %PACTIVE !~ *,FaceDownOff,* ]

Profile: NotFaceUpDownOn (19)
Priority: 41
State: Not Orientation [ Is:Face Up ]
Enter: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Exit: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Profile: FaceUpOff (7)
Priority: 33
State: Orientation [ Is:Face Up ]
State: Display State [ Is:On ]
Enter: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Exit: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Profile: MotionOnUD (20)
Event: Shake [ Axis:Up-Down Sensitivity:Very High Duration:Medium ]
Enter: 15s UD (21)
A1: Display Timeout [ Secs:15 Mins:0 Hours:0 ] If [ %PACTIVE ~ *,FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]
A2: Flash [ Text:15s UD Long:Off ] If [ %PACTIVE ~ *,FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]

Profile: MotionOnLR (22)
Event: Shake [ Axis:Left-Right Sensitivity:Very High Duration:Medium ]
Enter: 15s LR (23)
A1: Display Timeout [ Secs:15 Mins:0 Hours:0 ] If [ %PACTIVE ~ ,*FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]
A2: Flash [ Text:15s LR Long:Off ] If [ %PACTIVE ~ *,FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]

Profile: MotionOnBF (11)
Event: Shake [ Axis:Backwards-Forwards Sensitivity:Very High Duration:Medium ]
Enter: 15s BF (18)
A1: Display Timeout [ Secs:15 Mins:0 Hours:0 ] If [ %PACTIVE !~ *,FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]
A2: Flash [ Text:15s BF Long:Off ] If [ %PACTIVE ~ *,FaceUpOff,* & %PACTIVE !~ *,NotFaceUpDown,* ]

Profile: ProximityOn (8)
Priority: 34
State: Proximity Sensor
Enter: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Exit: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

Profile: DisplayOn (26)
Priority: 50
Event: Display On
Enter: 10min (16)
A1: Display Timeout [ Secs:0 Mins:10 Hours:0 ] 

K CD

unread,
Apr 5, 2016, 10:42:18 PM4/5/16
to Tasker
And the description

FaceDownOff turns the screen off if it is placed face down on a surface.

ChargingOn keeps the screen on if charging provided it is not place face down.

NotFaceUpDownOn keeps the screen on if it is not face up - the name is misleading because the screen is supposed to stay on while face down but not on a surface.

FaceUpOff is a state where the motion is detected - as long as motion is detected the screen will stay on in 15s increments. 15s after the phone is left the screen turns off as the event action
seems to take to priority over the state action which is to leave the screen on.

MotionOnUD, MotionOnLR, MotionOnBF are all the motion events - I put them all to increase sensitivity to all kinds of motion. These profiles are only active when the phone is in the face up state.

ProximityOn: This is for keeping the screen on when it is place face up when required.

DisplayOn: When the phone is picked up and the screen turned on the NotFaceUpDownOn profile action doesn't happen - tasker hasn't recognized that the phone has entered this state because it was already in that state when the screen was
turned on. So Dis[playOn is the event which keeps the screen on in trhe case.

Rich D

unread,
Apr 5, 2016, 10:56:42 PM4/5/16
to Tasker Google Groups Post


Have you viewed the run log to see where the conflict could be?

K CD

unread,
Apr 5, 2016, 11:12:15 PM4/5/16
to Tasker
Yes. That was very helpful - I am new to Tasker if you didn't guess already. I did a test where only FaceUpOff and MotionOnUD were active. The logs shows that the MotionOnUD is active even when the screen is not face up.
I used %PACTIVE to make sure it is only active when the FaceUpOff is active but that isn't happening. I was using flash messages to see what was going on - but the log is obviously better for this. Interestingly the flash
messages don't popup when the screen is not face up even though they are showing in the log. 

K CD

unread,
Apr 5, 2016, 11:15:50 PM4/5/16
to Tasker

Is there any obvious mistake in the profiles? Particularly the MotionOnUD and the FaceUpOff.

Rich D

unread,
Apr 5, 2016, 11:19:55 PM4/5/16
to Tasker Google Groups Post


I do have some suggestions but its getting late, I will have to reply tomorow.....

K CD

unread,
Apr 5, 2016, 11:21:36 PM4/5/16
to Tasker
Okay. Thanks. Have a good night.

K CD

unread,
Apr 6, 2016, 3:02:33 AM4/6/16
to Tasker

Here's another update: 

Although the log shows that the MotionOnUD profile is triggered in the not face up state, it actually isn't - the screen timeout isn't set to 15s by that profile. So something is wrong with the logs? In any case it seems
that some of the MotionOnUD profiles are triggered (only for a short while) when exiting the not face up state because the flash messages keep on coming.
And there is another problem I've been trying to figure out - when the screen is placed in the face up state it sometimes goes off immediately. When I had the FaceUpOff profile set to 15s instead of 10min I noticed that if say 10s was spent in face up state, upon exiting
and re-entering that state the timeout counter wasn't reset to 15s but continued with the remaining 5s. I've tried messing with the "Restore settings" for the profile but that didn't help. 

K CD

unread,
Apr 6, 2016, 4:56:20 AM4/6/16
to Tasker
Okay I think I'll not waste any more time on this - it's too glitchy. I wanted to replicate the features of the app Gravity Screen and thought it would be easy enough to replicate it in Tasker - and I needed some project to inspire me to
learn the basic features of Tasker which it has. The app Gravity Screen works really well with no glitches whatsoever - perhaps I will use Tasker to add some features. Thanks for your time and input Rich

Rich D

unread,
Apr 6, 2016, 7:08:40 AM4/6/16
to Tasker Google Groups Post

- and I needed some project to inspire me to
> learn the basic features of Tasker which it has.

Well..?  It appears you certainly can understand the actions and the logic for the actions however the way you designed this along with a few of your comments lead me to believe your understanding of relationship of profiles and tasks as well the difference in a state and event context could be improved.

I would start with something a bit more basic then once you have a full understanding of how it works you should be able to make this project work.

This cannot be explained in one post and I am not sure of your level of understanding so I will just start with the basics.

Profile: screen time out
Context: state/ power on: any
Task: set time out
1. Set time out tom10 min

It is best to think of a task as it own separate entity.  It is simply a grouping of actions.  There are many ways to start a task IE profile, from another task with a 'prefrom task action', a home screen short cut, a scene.. ect..  once a task has started has been started it runs independent from whatever started it (for the most part)  and once the task has finished its actions. Example: set screen time out to 10 min)  it will not run again until it is started again. So  your screen time out can now be changed by another task or manually. And even though the profile that started the task is still active it will not prevent or reset the screen time out to 10 min.

Sorry a bit short on time this morning, I will post more when I get a chance.


K CD

unread,
Apr 6, 2016, 8:22:09 AM4/6/16
to Tasker
Thanks for your patience. Perhaps I should not give up so easily. While you were sleeping I carefully read the basic tutorials explaining profiles, contexts (states and events), tasks, actions, variables and projects. As you have pointed out my terminology was a bit rough, but on retrospect most the application of the principles was okay (I think) - because many parts of the screen project do work as they should. The screen project looks complicated but its really a lot of basic profiles put together.  I am not sure how I am going to find out what's causing the glitches though if the log is not giving the correct information. That's why I kind of backed off. Unless I am missing something here?

If I am going to get serious about Tasker I do need to get more familiar with contexts and variables. I am going to have to find some other useful Tasker projects but my life is so simple that I am a bit stumped as to what these might be. 

Rich D

unread,
Apr 6, 2016, 8:33:31 AM4/6/16
to Tasker Google Groups Post


> Thanks for your patience. Perhaps I should not give up so easily. While you were sleeping I carefully read the basic tutorials explaining profiles, contexts (states and events), tasks, actions, variables and projects. As you have pointed out my terminology was a bit rough, but on retrospect most the application of the principles was okay (I think)

Correct..

- because many parts of the screen project do work as they should. The screen project looks complicated but its really a lot of basic profiles put together.

Correct.   It is how these profiles and tasks are colliding that is most of the issue I believe. 

 I am not sure how I am going to find out what's causing the glitches though if the log is not giving the correct information.

I would highly doubt the log is incorrect. My guess is you are misinterpreting it.

> If I am going to get serious about Tasker I do need to get more familiar with contexts and variables. I am going to have to find some other useful Tasker projects but my life is so simple that I am a bit stumped as to what these might be. 

Oh don't worry...  those will come as soon as you see how much Tasker can actually do... :)
>

Again, not much time just now but one example would be you have 3 of your motion event profiles firing three separate tasks that do the same thing. You can link all of these profile to the same task. Then you can set what will happen if the task is still running and another profile tries to start it again,  in the task collision settings.  If you are in the task edit screen it is the three button slider icon in the lower right for task properties.

Rich D

unread,
Apr 6, 2016, 8:57:04 AM4/6/16
to Tasker Google Groups Post


One more suggestion to get you going would be to try to this with one task.  So whenever profile  goes active (state) or fires (event) it will start this one task. Then within the task use the %PACTIVE variable to test which profiles are currently active and decide what to set from that information.  %PACTIVE will only be good for the state context but I believe all of your event contexts were all doing the same thing within the task so it should not matter. If you do find the need to know what event context has fired the task (from within the task) this information is in the array %caller.

If you want to find info on such things as %caller from the guide the best way is to use the menu / 'search Tasker' option

Rich D

unread,
Apr 6, 2016, 8:59:09 AM4/6/16
to Tasker Google Groups Post


On Apr 6, 2016 8:57 AM, ricp...@gmail.com wrote:
>
>
> One more suggestion to get you going would be to try to this with one task. 

The advantage to this is you only have one task running, not 10 different tasks all stepping on each other. .. 

K CD

unread,
Apr 7, 2016, 1:44:17 AM4/7/16
to Tasker
I can see where I am going wrong here - I assumed that an event which set the screen timeout would reset the counter of the timeout - that only happens when the new screen timeout has a different value than the existing one. What is keeping the screen on is the pop ups - when I remove these and use one task for three motion event contexts the screen does not stay on. 

The idea behind having the motion events causing a 15s timeout instead of 10min is that when the phone is put down the last event will be motion and the timeout will be 15s. 

Now I will have to re-think this but as you have suggested minimize the tasks to avoid conflict.

Rich D

unread,
Apr 7, 2016, 6:21:41 AM4/7/16
to Tasker Google Groups Post


> Now I will have to re-think this but as you have suggested minimize the tasks to avoid conflict.

With root you could just emulate a screen tap in a unused part of the screen. I think I used 1x1 before with no issues.

Without root I would suggest staying with your approach and just toggle the time,

-Variable add %Toggle +1 wrap around 2
- set time out to 15 : if %Toggle = 0
- set time out to 16 : if %Toggle =1



K CD

unread,
Apr 7, 2016, 8:44:31 AM4/7/16
to Tasker
Okay thats a nice trick. I already tried with only two tasks with two different timeouts  (15s and 30s - sticking with two options on my phone timeout setting) and the screen didn't stay on. But now I'll try this toggle method and let you know what happens. 

K CD

unread,
Apr 7, 2016, 9:25:41 AM4/7/16
to Tasker
I've made a profile - 

Context event - shake Left Right

The task has three parts

1 Variable Add

Name %Toggle
Value +1
Wrap around 2

2  Display Timeout
Secs 16
If %Toggle ~ 1

3 Dispay Timeout
Secs 17
If %Toggle ~ 0

No other profiles running. The screen still times out. I've used 15s and 30s since these are settings on my phone - same result. It may be an MIUI rom compatibility issue? 

The root method I've not grasped. Thanks for the imput.

Rich D

unread,
Apr 7, 2016, 10:30:17 AM4/7/16
to Tasker Google Groups Post


> I've made a profile - 

It is always best to post your exported profile description

To post your profile or task here...  Long press on the profile or task name / ( 3 dot menu with 4.0+ ) export / export "DESCRIPTION" to clipboard (not XML)

Any linked tasks will be exported with the profile they are linked to..

To be able to export, The beginner mode needs to be off and the profile needs to be named by you (Not the Tasker listed name.  Tasker will list your profile with the context name if you have not given it one).


> Context event - shake Left Right
>

No other profiles running. The screen still times out. I've used 15s and 30s since these are settings on my phone - same result. It may be an MIUI rom compatibility issue? 

Strange, I have tested this and it does work on my device. 

I have a rooted Motorola Droid 4 / Stock ROM   / Tasker  /  Version:  4.8m / Android version 4.1.2

Did do check the run log?
Did you de-select the 'restore settings' option for the profile?

You will see the settings being restored in the run log as a system task that has a negative ID number.

>
> The root method I've not grasped. Thanks for the input.
>
> --

Use a  action  / code / run shell

command: input tap 1 1

Rich D

unread,
Apr 7, 2016, 11:40:57 AM4/7/16
to Tasker Google Groups Post


Your project intrigued me so I made one.. :)

Here is my version.  It has some debug stuff in that should be apparent.  You can open your notify bar and watch as the different phases are implemented.

When you download you just need to make sure the file ends up in
/storage/sdcard0/Tasker/projects/
Then you can import it by long pressing any project tab.

Profile: Prox Swipe (762)
State: Proximity Sensor
Enter: Motion On (756)
Abort Existing Task

Profile: Face Up (755)
Restore: no


State: Orientation [ Is:Face Up ]

Enter: Motion On (756)
Abort Existing Task

Profile: Face Down (758)
Restore: no


State: Orientation [ Is:Face Down ]

Enter: Motion On (756)
Abort Existing Task

Profile: Power (759)
Restore: no
State: Power [ Source:Any ]
Enter: Motion On (756)
Abort Existing Task



Profile: Moving Face Up (757)


Event: Shake [ Axis:Left-Right Sensitivity:Very High Duration:Medium ]

State: Orientation [ Is:Face Up ]

Enter: Motion On (756)
Abort Existing Task

Profile: Moving Face Up (760)


Event: Shake [ Axis:Up-Down Sensitivity:Very High Duration:Medium ]

State: Orientation [ Is:Face Up ]

Enter: Motion On (756)
Abort Existing Task

Profile: Moving Face Up (761)


Event: Shake [ Axis:Backwards-Forwards Sensitivity:Very High Duration:Medium ]

State: Orientation [ Is:Face Up ]

Enter: Motion On (756)
Abort Existing Task

Motion On (756)
Abort Existing Task
<face up and moving>
A1: Anchor
A2: If [ %caller() ~ *Moving Face Up* ]
A3: Variable Add [ Name:%Mot_toggle Value:1 Wrap Around:2 ]
A4: Display Timeout [ Secs:15 Mins:0 Hours:0 ] If [ %Mot_toggle ~ 1 ]
A5: Display Timeout [ Secs:16 Mins:0 Hours:0 ] If [ %Mot_toggle ~ 0 ]
A6: Notify [ Title:Face Up Text:Face up loop  on 15
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]
A7: [X] Flash [ Text:%caller() Long:On ]
A8: Wait [ MS:0 Seconds:10 Minutes:0 Hours:0 Days:0 ]
A9: End If
<prox swipe>
A10: Anchor
A11: If [ %caller() ~ *Prox Swipe* ]
A12: Display Timeout [ Secs:0 Mins:59 Hours:0 ]
A13: Notify [ Title:Face Up Text:Prox swipe
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]
A14: Stop [ With Error:Off Task: ]
A15: End If
<face up power on>
A16: Anchor
A17: If [ %PACTIVE ~ *,Face Up,* & %PACTIVE ~ *,Power,* ]
A18: Display Timeout [ Secs:0 Mins:59 Hours:0 ]
A19: Notify [ Title:Face Up Text:Face up and power
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]
A20: Stop [ With Error:Off Task: ]
A21: End If
<face up>
A22: Anchor
A23: If [ %PACTIVE ~ *,Face Up,* ]
A24: Display Timeout [ Secs:15 Mins:0 Hours:0 ]
A25: Say [ Text:Face up shutting off Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]
A26: Notify [ Title:Face Up Text:Face up no activity shut off
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]
A27: Stop [ With Error:Off Task: ]
A28: End If
<face down>
A29: Anchor
A30: If [ %PACTIVE ~ *,Face Down,* ]
A31: Display Timeout [ Secs:0 Mins:59 Hours:0 ] If [ %Mot_toggle ~ 0 ]
A32: Say [ Text:Face down shutting off Engine:Voice:default:default Stream:3 Pitch:5 Speed:5 Respect Audio Focus:On Network:Off Continue Task Immediately:Off ]
A33: Notify [ Title:Face Up Text:Face down set to 15
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]
A34: End If
<any other position>
A35: Anchor
A36: Display Timeout [ Secs:0 Mins:59 Hours:0 ]
A37: Notify [ Title:Face Up Text:Any other
%DTOUT Icon:null Number:0 Permanent:Off Priority:3 ]

Let me know if you have any questions.. 

Motion.prj.xml

Rich D

unread,
Apr 7, 2016, 11:53:43 AM4/7/16
to Tasker Google Groups Post


Not sure why it printed that way, this should be easier to read..

And I realized I did not de-select 'restore settings' for the Prox Swipe profile.   You should do this..

Task: Motion On (756)

K CD

unread,
Apr 7, 2016, 11:54:09 AM4/7/16
to Tasker
I checked the log - with the profile triggering every second the screen still times out. 

Mi note 3 running MIUI 7 6.3.31 Android 5.0.5 and Tasker 4.7

Okay the next step is the root method. 




K CD

unread,
Apr 7, 2016, 12:14:48 PM4/7/16
to Tasker
I tested yours, de-selected 'restore settings' for the Prox Swipe profile - checked the log to confirm that the profile was being triggered (it was every second or so) and it still times out. Maybe a conflict with the MIUI rom? Yet the Gravity Screen App works like a charm. 

Not sure if it's worth rooting to make it work. I have rooted before 

Rich D

unread,
Apr 7, 2016, 12:21:28 PM4/7/16
to Tasker Google Groups Post


> I tested yours, de-selected 'restore settings' for the Prox Swipe profile - checked the log to confirm that the profile was being triggered (it was every second or so) and it still times out. Maybe a conflict with the MIUI rom? Yet the Gravity Screen App works like a charm. 
>
> Not sure if it's worth rooting to make it work. I have rooted before 
>

Oh, I thought you need root to get a custom ROM?

Is that a custom ROM?

We must be missing a non rooted way to keep the screen awake. Perhaps it can be done with a java function?    You could try googling for a java solution.

K CD

unread,
Apr 7, 2016, 12:30:15 PM4/7/16
to Tasker
No its an Mi note 3 - it came with that ROM. Um - the java solution - I'm not a programmer ;)

Rich D

unread,
Apr 7, 2016, 12:56:55 PM4/7/16
to Tasker Google Groups Post


> No its an Mi note 3 - it came with that ROM. Um - the java solution - I'm not a programmer ;)

Nor am I. :( 

I did some googling.   It appears a java solution "might work".
android:keepScreenOn="true"

However I do not know java and it would most likely take some time for me to get that to work.

The plug in 'secure settings' will do this without root. I believe it is a free app and you need to install its helper app as well.

K CD

unread,
Apr 7, 2016, 1:10:12 PM4/7/16
to Tasker
I actually have the plug in already - just didn't get round to trying it. But perhaps the rooted method might work better. Using Kingroot is a pretty painless way to root.


Rich D

unread,
Apr 7, 2016, 1:16:40 PM4/7/16
to Tasker Google Groups Post


> I actually have the plug in already - just didn't get round to trying it. But perhaps the rooted method might work better. Using Kingroot is a pretty painless way to root.

If I recall correctly secure settings does work fine but if you do root - -I know the input tap will work. No guarantees on finding a place on the screen to tap that will not affect any app. I do remember using 1 1 and not having a issue.  

K CD

unread,
Apr 7, 2016, 7:41:16 PM4/7/16
to Tasker
Thanks I'll try that. You've been a great help.
Reply all
Reply to author
Forward
0 new messages