Acceleration debounce in RM?

Curious how you experts would structure this. I have a pill planner with an acceleration sensor glued to it and some rules and variables that count the number of times I move it to take medication and remind me if I forget, but only if I forget. Setting it up now so no idea if this will be an actual problem, but if the sensor reports "no movement" too soon, I could trigger it twice when taking one dose, thus incrementing the following dose as having been taken. Simpler apps like Notifications have a built in debounce of sorts (only once per x minutes option). RM can obviously implement the logic behind this natively in multiple ways, but what is the most efficient way of doing so? Preferably in one rule. It seems silly to create a whole global variable and new rule to set it, or an auto off virtual switch/device, but maybe that's the easiest most efficient way?

In shorthand the goal is:
Trigger: accelerometer active;
Actions:
If (accelerometer not active in last 5 minutes)
THEN
variable "pills"+1

That looks about right to me. One way you can actually get that "five minutes" thing is to do something like this:

Trigger: Accelerometer active

Actions:

Wait for events: elapsed time --> 0:05:00
Log: "Accelerometer last became active 5 minutes ago!"

(Instead of that "Log" action, do whatever you actually want to do, of course.)

This exploits a behavior of "Waits," which are cancelled any time the rule-retriggers. So, if you get to that next action, you know that either the accelerometer has stayed active for five constant minutes (unlikely, but techincally possible) or last became active 5 minutes ago (likely with an "inactive" event afterwards, which is not timed for here--but crucially, with no subsequent "active" events--which, again, would cause the wait [and everything after] to be cancelled if it's still within that 5 minutes and the rule actions to start over again).

1 Like

Awesome! Haven't tried setting it up yet but that seems like a great approach, thanks for your help. Running into this makes me think RM should have access to state/event history for purposes of building conditional rules so I could do "if last device event not within 5 minutes then..." while wait works great for my use case because I'm not going to consider taking meds twice within 5 minutes, the limitation of the Wait approach is...well, waiting. If I needed the action to happen immediately based on history rather than in 5 minutes based on now, I'd have to set up a much more complicated and less efficient rule where every activation starts a timer and the activation that increments the variable would have to check that that timer was greater than 5 minutes, or some other unnecessarily complicated approach.

Doesn't look like wait for events gives me an elapsed time option?

@giudicistefan It's the one after Dimmer

1 Like