how to debounce a state context?

233 views
Skip to first unread message

Mike T

unread,
Feb 9, 2017, 7:42:46 PM2/9/17
to Tasker
I use Tasker to launch some tasks when it sees me arrive near my home wifi, and others when it sees me leave.  The problem I'd like to solve is sometimes it loses the detection for a second or two and then sees it come back.

In hardware the classic solution to this is a debounce circuit.  I looked in the archive for Tasker and the closest answer I can find is a suggestion to add "Cooldown" to the profile.  But that isn't really what I want.  That will prevent a task from firing more frequently then the period specified.  But what I really want is a debounce; don't fire at ALL unless the condition is true at the start and end of some period.

As a workaround I have set up 2 profiles. One (call it A)  has the context set up to trigger when wifi loss is detected, sets a variable Hysteresis to 1, delays a few seconds, then sets it to 0.  The 2nd profile (call it B)  is the one I actually want to run when I leave. That has a context that checks that wifi is absent AND that the variable Hysteresis is 0.  When wifi is lost then as long as the Hysteresis variable gets to 1 before this profile triggers then I inhibit B from running for a few seconds.  If I have really left home I don't mind the delay of a few seconds in triggering B.

But you can see the problem.  There is a race condition here.  If B evaluates its context before A then the Hysteresis variable will not be a 1 yet.  I don't see a way to enforce order between profile evaluation.  Task Priority is another dial, but that doesn't help here.  I want to prevent the task called by B from running at all.  Interleaving it with the task from A doesn't really help.

So a 2-part question/request:
1) what have other people done to create a debounce?
2) as an enhancement, it would be nice to have a state context with an optional debounce built into Tasker; when it first sees the state become true then it waits the specified delay and makes sure it is still true, otherwise goes back to its initial state

Rich D

unread,
Feb 9, 2017, 8:04:31 PM2/9/17
to Tasker Google Groups Post


> In hardware the classic solution to this is a debounce circuit.

To debounce in tasker--- you can search this group for other approaches but this is the one I use. It will stop both the enter task and exit task from running when the context bounces. This example uses a context : state: Cell near.  This will work with any state context.

Profile: Cell on
Context: cell near
Enter Task: Start
1. Enter task stuff

<put the following actions as the first actions in your exit task>

Exit task:stop
1. Wait 5 sec <whatever time you need>
2. Stop  <enter task> ;Start
3 Stop if %PACTIVE ~ *,Cell on,*
4. Rest of exit task !

Rich D

unread,
Feb 10, 2017, 5:10:32 AM2/10/17
to Tasker Google Groups Post
This post has some information on what makes  this approach work. 


Jim Becker

unread,
Feb 10, 2017, 11:57:36 AM2/10/17
to Tasker
A variation on what Rich has done which eliminates ExitErr messages in the Tasker log file.

<first lines in the Exit task>

Exit Task
Set OffDelayWait to TRUE
Wait 5 Seconds
Set OffDelayWait to FALSE
rest of exit task

Add a state context for Variable Value OffDelayWait ~ FALSE to the Profile Cell On


Rich D

unread,
Feb 10, 2017, 7:13:09 PM2/10/17
to Tasker Google Groups Post

<first lines in the Exit task>

Exit Task
Set OffDelayWait to TRUE
Wait 5 Seconds
Set OffDelayWait to FALSE
rest of exit task

Add a state context for Variable Value OffDelayWait ~ FALSE to the Profile Cell On


I see 2 issues with this approach.

1. There is no check to see if the profile is still active after the wait so the ' rest of exit task' will aways run

2. The profile can go inactive then active again before the exit task even runs. Context status and profile status have priority over  task actions. 


>>which eliminates ExitErr messages in the Tasker log file.

Why would you need to eliminate that?
Reply all
Reply to author
Forward
0 new messages