Run shortcut (from iOS personal automation) at most once daily?

Semi-noob here, sorry if this is a basic question! But I have a personal automation on iOS set to trigger a shortcut that runs my robot vacuum whenever I leave home.

However, I’m not sure how to handle the situation where I might be running a bunch of errands some day, and hence go in and out of home a lot. I really would only want it to run once on a day like that.

Ideally there would be some way to put a rule on the automation or the underlying shortcut that specifies that it can’t be run more than once a day, but I can’t find anywhere in the app to do that.

Alternatively, I guess I could edit the shortcut to put some kind of conditional before initiating the vacuum. But I’m not sure how to express “this shortcut hasn’t been run before” in a conditional. That doesn’t seem to be an option in the if action… and I don’t seem to see any kind of way to keep persistent state across runs to do things like set a variable if the shortcut has been run today.

Does anyone know if this is possible some way? Thanks!

(Edit: I suppose if I wanted to go completely nuts I could spin up a web server and use that to persist state/have the shortcut call up there to get the last run date before deciding whether to run the vacuum. But I gotta admit, this seems like extreme overkill. Though I guess if it’s the only option I’ll try it…)

You need to store some data to indicate when the automation was last triggered. You can then use the conditional check you wondered about.

There are several options for using persistent data, but using the Data Jar app is probably the most widely used approach and is easy to implement.

When the shortcut is triggered, it checks a persistent variable in Data Jar in which you can store the last run date. If the date is not today, update the variable and continue ith the automation. If the date is today, then don’t run the automation.

Hope that helps

You can save the current date to a file when you run the vacuum, and use the file to check if you already ran it today:

1 Like

Thank you! I’m having a little bit of trouble figuring out how to get the file actions to work, however. In my version of shortcuts, the file action doesn’t seem to have any “as” option to read it as a date. Also, the file save action does t seem to give me any option to specify the contents of the file (?!) … see screenshots. Am I using the wrong action?

Thank you!!

(Additional screenshot because it will only let me post one)

And one more sorry

This should help.

Out of interest, any particular reason you have opted not to use Data Jar and use files instead?


Thank you! I think the most confusing thing about shortcuts is the… I guess you could call it a type system? But the fact that there aren’t obvious rules or any consistency in when you can replace a file or a url or whatever with its contents and how to (for lack of a better term, stealing an idea from type systems again) cast one to the other. It’s sort of like JavaScript where sometimes you can just seamlessly treat an X as a Y and sometimes it fails.

And re why not DataJar, honestly I just figured on trying the simpler approach first that didn’t require an additional app.

As suggested by @sylumer, Data Jar provides a simple way to implement this. The Data Jar app is also free and allows lots of information to be stored simply for different uses.

Sample Shortcut using Data Jar

Hope this helps.

1 Like