"Time since last trigger" but for a distinct automation?

Hi!

So I use this app every time I use my mac. Love it.

Yesterday I tried setting it up to run an Apple Shortcut when i wake my macbook. It's simple, and I managed to get it working like a charm.
However, its enough if I run the Automation once a day, so triggering every time I wake my macbook is overkill. So I set the Trigger Condition "seconds_since_last_trigger" to 86400s, i.e. one day.
Today I noticed it didn't run the Automation like expected, because the "seconds_since_last_trigger"-Condition looks for any trigger done by BTT, not just the action its assigned to. And since I use BTT for many other things, the condition is likely never met.

I can see the usecase for the existing "seconds_since_last_trigger", but wanted to ask how you would feel about implementing an additional variable "seconds_since_last_trigger_of_this_action", or something like that? Or alternatively, if my automation-"cooldown" can be implemented in other ways?

Thanks in advance and I'd be happy to elaborate if something is not clear, english isn't my mother language. Have a good day :slight_smile:

"Fine, I'll do it myself"

In case anyone else ever has this problem:
Instead of using advanced condition, I just scripted the whole thing myself using with the "Run Real JavaScript" action. Here, I saved the datetime as a permanent variable which gets compared to the current datetime when triggered.

Here's the code:

(async () => {
  const currentTime = Date.now().toString();
  let lastExecutionTime = await get_string_variable({ variable_name: 'lastExecutionTime' });

  if (lastExecutionTime === null || lastExecutionTime === undefined) {
    await set_persistent_string_variable({ variable_name: 'lastExecutionTime', to: currentTime });
    returnToBTT( < insert desired action here > )
  }

  const timeDifference = Number(currentTime) - Number(lastExecutionTime);
  const hoursPassed = timeDifference / (1000 * 60 * 60);

  if (hoursPassed > 24) {
    await set_persistent_string_variable({ variable_name: 'lastExecutionTime', to: currentTime });
	returnToBTT( < insert desired action here > )
  } else {
    returnToBTT(hoursPassed);
  }
})();
1 Like