Action to close/restart an app and power off the device

Qarboz

Well-known member
What is the sense of that? Why would i want to power off my device while my screen is on? My wish is to auto power-off the device when the screen stays switched-off for a long time, for example for mor than 3 hours
Because the UI interaction works only with the screen on and unlocked; and it makes sense that it does, since this action simulates the person's finger.
 

cska133

Member
Because the UI interaction works only with the screen on and unlocked; and it makes sense that it does, since this action simulates the person's finger.
ah, you mean that before executing the MD Action the device will get unlocked and the screen on, and after that the action (device power off) will start?
 

Qarboz

Well-known member
ah, you mean that before executing the MD Action the device will get unlocked and the screen on, and after that the action (device power off) will start?
No, the Android Shortcuts action does not unlock the device; it roughly needs to:
Action turns on the screen
UI Gesture upward action to bring up the unlock screen
Series of UI Interaction (X,Y) to tap the PIN entry numbers
Android Shortcuts -> Power Options Action
UI Interaction (X,Y) action
Or... phone rooted
 

dhj49er

Well-known member
What is the sense of that? Why would i want to power off my device while my screen is on? My wish is to auto power-off the device when the screen stays switched-off for a long time, for example for mor than 3 hours
Why are you powering off the phone when the screen has been off for more than, your example, 3 hours?

No calls, no messages, no notifications & nobody can contact you in an emergency.

Surely you are not trying to preserve battery life over having a working phone?

Makes no sense to me.
 

Endercraft

Moderator (& bug finder :D)
Why are you powering off the phone when the screen has been off for more than, your example, 3 hours?

No calls, no messages, no notifications & nobody can contact you in an emergency.

Surely you are not trying to preserve battery life over having a working phone?

Makes no sense to me.
It could be anything, for example a phone you leave at home that's not your main phone.
You might think the probability of someone doing that is low but we are so many it's pretty much 100%.
 

cska133

Member
No, the Android Shortcuts action does not unlock the device; it roughly needs to:
Action turns on the screen
UI Gesture upward action to bring up the unlock screen
Series of UI Interaction (X,Y) to tap the PIN entry numbers
Android Shortcuts -> Power Options Action
UI Interaction (X,Y) action
Or... phone rooted
Oh my god, i dont get this, sorry. Can you somehow give me concret examples of these all actions and UI Interactions. What changes if i dont use Pin but pattern?

Why are you powering off the phone when the screen has been off for more than, your example, 3 hours?

No calls, no messages, no notifications & nobody can contact you in an emergency.

Surely you are not trying to preserve battery life over having a working phone?

Makes no sense to me.
It is a tablet. My child often doemt not turned if off and forget it, and it stays for a long time on. Then the battery is empty. That all drives me crazy. Thatsway i want to automate the powering off
 

dhj49er

Well-known member
Because the UI interaction works only with the screen on and unlocked; and it makes sense that it does, since this action simulates the person's finger.
Are you sure that UI interaction only works with the screen on and unlocked?

If so, unlocking the phone using UI interaction actions wouldn't work ..but it does.

In my experience UI interaction works with the screen on irrespective of the lock/unlock state. But what a macro can do on the lock screen is limited - unlocking and enabling the status bar/Quick settings & clicking items, depending on the phone/tablet and Android version.
 
Last edited:

Qarboz

Well-known member
Oh my god, i dont get this, sorry. Can you somehow give me concret examples of these all actions and UI Interactions. What changes if i dont use Pin but pattern?
I think it can also work with pattern.
For the other actions it has already been discussed in the forum, if you search you should find solutions. Or the template store
 

Qarboz

Well-known member
Are you sure that UI interaction only works with the screen on and unlocked?

If so, unlocking the phone using UI interaction actions wouldn't work ..but it does.

In my experience UI interaction works with the screen on irrespective of the lock/unlock state. But what a macro can do on the lock screen is limited - unlocking and enabling the status bar/Quick settings & clicking items, depending on the phone/tablet and Android version.
By screen on and unlocked I mean for interacting with apps or objects on the screen, such as in this case the android shortcut -> power options. That UI interaction works on the unlock screen I am aware of, in fact I suggested using it to unlock the device.
 

dhj49er

Well-known member
By screen on and unlocked I mean for interacting with apps or objects on the screen, such as in this case the android shortcut -> power options. That UI interaction works on the unlock screen I am aware of, in fact I suggested using it to unlock the device.
It also works on the locked screen.

The attached macro powers off the phone when the screen has been off for 3 hours.

Wether the macro will work will depend on the phone/tablet and android version.

The macro works on my Sony 5v on Android 14.
 

Attachments

  • Screenshot_20240218-004843.png
    Screenshot_20240218-004843.png
    205.6 KB · Views: 22
  • Screenshot_20240218-010026.png
    Screenshot_20240218-010026.png
    216.6 KB · Views: 22

Qarboz

Well-known member
what exactly should I search for in the forum, sorry I got confused. So many words... interactions, actions, Ui, shortcuts🤕
Search unlock

what and where is this?
In MacroDroid app

It also works on the locked screen.

The attached macro powers off the phone when the screen has been off for 3 hours.

Wether the macro will work will depend on the phone/tablet and android version.

The macro works on my Sony 5v on Android 14.
I did not know about this possibility, but I think it does not apply to all devices. OP can try it if it works for him.
 

mapriex

Active member
It also works on the locked screen.

The attached macro powers off the phone when the screen has been off for 3 hours.

Wether the macro will work will depend on the phone/tablet and android version.

The macro works on my Sony 5v on Android 14.
i like your sleeptimer idea. 3hrs is long enough for most movies. maybe an addition if its really needed: something the user can reject in the last 10 mins the shutoff without interfering the current activity drastically. or a smart sleeptimer that reads activity actions and reset the 3hrs timer till no activity from a user happened.
 

dhj49er

Well-known member
i like your sleeptimer idea. 3hrs is long enough for most movies. maybe an addition if its really needed: something the user can reject in the last 10 mins the shutoff without interfering the current activity drastically. or a smart sleeptimer that reads activity actions and reset the 3hrs timer till no activity from a user happened.
I produced the macro as an example of actions that work on a locked screen. I used what the OP wanted to achieve. He wanted a macro to power off his son's tablet when the screen had been off for a while. He suggested 3 hours as an example.

The macro has a type of smart sleep timer function that you mention. Should the screen be turned on inside the 3 hours, the timer is reset.
 
Last edited:

cska133

Member
@dhj49er
thank you for testing it. Now I have to test it on my child's tablet, it is Android 7. Maybe @Qarboz is right, and it will not work there. Will see...

But can you explain me the entries in your macro. As trigger SCREEN OFF is ok, but why also SCREEN ON? And what about the MD Variables PowerOff=false/true?
In the action field you also have Set Variable PowerOff:true and then false. What do these Variable items do, what for you implement them? And what will be if the macro is without the Variables. For example: if Screen goes OFF ->wait 180 min ->then power Screen ON, ->1sek ->Android shortcut (power options) -> UI Interaction (click power off) ?

You posted 2 screenshots, after Cancel This Macro action is there something else? I thing there is another IF ? Or this the ende of the macro? Could you post the screenshot till the ende of the macro please
 

dhj49er

Well-known member
@dhj49er
thank you for testing it. Now I have to test it on my child's tablet, it is Android 7. Maybe @Qarboz is right, and it will not work there. Will see...

But can you explain me the entries in your macro. As trigger SCREEN OFF is ok, but why also SCREEN ON? And what about the MD Variables PowerOff=false/true?
In the action field you also have Set Variable PowerOff:true and then false. What do these Variable items do, what for you implement them? And what will be if the macro is without the Variables. For example: if Screen goes OFF ->wait 180 min ->then power Screen ON, ->1sek ->Android shortcut (power options) -> UI Interaction (click power off) ?

You posted 2 screenshots, after Cancel This Macro action is there something else? I thing there is another IF ? Or this the ende of the macro? Could you post the screenshot till the ende of the macro please
The second screenshot shows the complete macro. The last action is end if.

I wouldn't expect the macro to work on your tablet, unless the power options action produces an identical screen to my phone. This will not be the case and the UI action will need to be changed for the tablet.

Screen ON trigger is there for the following reason. Whenever the tablet screen goes off the macro will run, leading to multiple instances of the macro running, if the tablet screen is turned on within the 180 minutes. The Screen On trigger prevents multiple instances of the macro running.

If your son never lets the screen go off when he's using it and the screen never comes on in the 180 minutes, then the screen on trigger can be removed, along with the else if and the actions after the else if. I recommend keeping the screen on trigger.

The variable is essential with screen on trigger. Remove that trigger and the variable is not required.

You seem not to understand how variables work. I suggest you use the MD Wiki for help.
I have attached a screenshot of the relevant page on variables
 

Attachments

  • Screenshot_20240219-074012.png
    Screenshot_20240219-074012.png
    217.2 KB · Views: 9

cska133

Member
I wouldn't expect the macro to work on your tablet, unless the power options action produces an identical screen to my phone. This will not be the case and the UI action will need to be changed for the tablet.
Which changes do you suggest?
 
Top