Perform actions on LAST volume change in series

Dee

New member
Hi,

I'm trying to create a macro to perform actions when the volume changes. I've added the triggers "Volume Up" and "Volume Down".

The problem I'm having is that when I press the volume button repeatedly within a few seconds (in order to change the volume by several steps), the macro actions are performed for EVERY press of the button. For example, if I press the "Volume Down" button four times in a row, the actions are performed four times.

How can I make the actions be performed only ONCE, after the LAST volume change?

Thanks in advance for any help. :)
 

420

Active member
you could simply add a "macro not invoked for 5 seconds" constraint to the triggers/macro, that way it won't run 4 times, but that also means the actions will run on the first volume change, not on the last, i don't know if that is a big problem?
 
  • Like
Reactions: Dee

Dee

New member
you could simply add a "macro not invoked for 5 seconds" constraint to the triggers/macro, that way it won't run 4 times, but that also means the actions will run on the first volume change, not on the last, i don't know if that is a big problem?
Thanks for that suggestion, 420. I tried something similar, but it didn't do what I wanted because I do need the actions to run on the LAST volume change.
 

420

Active member
Thanks for that suggestion, 420. I tried something similar, but it didn't do what I wanted because I do need the actions to run on the LAST volume change.
hmm, you could use "reset&restart stopwatch" actions, and then add triggers for the stopwatches being at a couple seconds to run your actions.

this does mean that there will always be a couple second delay though, from the last volume change untill your actions run.

i can't really think of another way to do it at the moment...
 
  • Like
Reactions: Dee

Dee

New member
hmm, you could use "reset&restart stopwatch" actions, and then add triggers for the stopwatches being at a couple seconds to run your actions.

this does mean that there will always be a couple second delay though, from the last volume change untill your actions run.

That works. But the delay is longer than expected — about 8 seconds after only two presses of the "Volume Down" button! (One press to open the volume dialog, and a second press to reduce the volume by one step.)

Here's what I have so far:

Screenshot_20210610-210613.png
 

420

Active member
That works. But the delay is longer than expected — about 8 seconds after only two presses of the "Volume Down" button! (One press to open the volume dialog, and a second press to reduce the volume by one step.)

Here's what I have so far:

View attachment 502
what you created is an endless loop,the stopwatch keeps resetting itself every 2 seconds.

you should add an else to the if clause and move the reset&restart action to there.

if trigger fired stopwatch
set variable
macro run
else
reset&restart
end if
 
  • Like
Reactions: Dee

Dee

New member
what you created is an endless loop,the stopwatch keeps resetting itself every 2 seconds.

Ahh, thanks for that — that would explain why MacroDroid was getting laggy! :oops:

Unfortunately, I'm still getting a delay of 8 seconds after pressing the volume button twice (and an even longer delay if I press the volume button more than two times).


Screenshot_20210610-215533.png
 

420

Active member
It's not ideal, but it's the only solution that works so far, so thank you @420 for getting me this far. :)
i'm also getting a delay for the volume up/down triggers, i don't know why that is, but i found something else you can try, it seems a bit faster.

triggers

volume up
volume down

actions

wait 1 second
if macro (this macro) not invoked in 2 seconds
set variable
run macro
end if

i would recommend you create this in a new macro, and disable the old one while testing this one, incase the old one worked better.
 
  • Like
Reactions: Dee

dsnz

Well-known member
it must be a bug with the timer trigger for short timeouts and must depend on phone/android or the way timer is implemented

I tried same macro (as in last screenshot)
with just one volume event
and with various timeouts from 2 to 20 sec with extra logging and also examined the system log at the same time and the timer trigger fired at 2x timeout time (twice) when timeout was 3 sec or less

for timeout of 4 sec I got 5 sec delay
and for timeout of 5 sec or above I got exact delay
 
  • Like
Reactions: Dee

Dee

New member
i'm also getting a delay for the volume up/down triggers, i don't know why that is, but i found something else you can try, it seems a bit faster. …

@420, thanks for this new suggestion. I tried it and the delay decreased from 8 to 6 seconds, so a slight improvement. :)
 

Dee

New member
it must be a bug with the timer trigger for short timeouts and must depend on phone/android or the way timer is implemented

I tried same macro (as in last screenshot) …

Thanks @dsnz, I appreciate that you tested it out. 👍

I think you might be right that there's a bug. The delay has been very consistent for me.
 

MacroDroidDev

Administrator
Staff member
One thing to note is that the wait before next action has different implementations for below 5 seconds and above 5 seconds. If you can use report a bug with your macro and the description of the delay you are seeing I can try and recreate on my device.
 

dsnz

Well-known member
find attached a demo code for investigating whether it's a bug

you just configure the stopwatch timeout to various value between 1 and 20 and then press once the floating button and watch the user log and the timestamps
(stopwatch is named: test)

for 2 sec timeout I get a 5 sec trigger !
BUT
on first try (and only on first try) I got a correct 2 sec response
this is something I noticed now and perhaps can help in debugging

there is no "wait before next action" option for any action in this macro
 

Attachments

  • stopwatch_bug.macro
    2.3 KB · Views: 2
  • Love
Reactions: Dee

dsnz

Well-known member
unfortunately I have no idea about these settings and where they are located

the macro behavior is the same if volume up/down trigger is used instead of floating button, I have not tried other trigger mechanism
 

MacroDroidDev

Administrator
Staff member
Thanks, I can see what the issue here is. It seems the stopwatch trigger has not had an option to use alarm like many of the other time based trigger. This is essential on many devices to wake up at the correct time (especially if scheduling near in the future). I will add this as an option and make it default in the next update.
 

Alan Eaton

New member
Please make the default configurable (an option in Macrodroid settings).

Do the same for the wait action. I always disable use-alarm so that I don't get the clock icon in the status bar.
 

Jacob L

Moderator (Lawsonator)
Please make the default configurable (an option in Macrodroid settings).

Do the same for the wait action. I always disable use-alarm so that I don't get the clock icon in the status bar.
That icon comes from your clock application not MacroDroid
 

Alan Eaton

New member
That icon comes from your clock application not MacroDroid
Irrelevant.

If I add a wait action of 5 or more seconds and enable use-alarm then the icon appears when the action is executed and persists until the wait period has elapsed.

This happens on my Pixel 4XL.
It does not happen on my Galaxy Tab S5e.
If I recall correctly, it was happening on my old GS9 and then stopped happening.

It seems to be a vendor specific thing.
 
Top