strautomator / web

Strautomator Web / API
https://strautomator.com/
MIT License
30 stars 1 forks source link

Feature request: Add OR option to conditions #11

Closed costa-alex closed 1 year ago

costa-alex commented 2 years ago

Some of the conditions could have an OR option to allow more flexible automations.

Something like: Condition: GPS device / app name has TrainerRoad OR Zwift

igoramadas commented 2 years ago

Hi,

Initially I thought about adding OR / AND clauses, but that would make the existing implementation considerably more complex. Both on the backend as well as the frontend.

As not many people have requested that, I will keep it on the "maybe in the future" list (you're the second person to ask since the service launched more than 2 years ago).

Obrigado :-)

sevitz commented 1 year ago

+1 to that request.

Would be really useful to go ("If starting location is HOME" OR "if end location is home") AND activity is walk then Set GEAR to walking shoes)

Etc

mitchgibbstek commented 1 year ago

Just adding another vote for this. I can see how it would complicate things, but it would be handy. I've got a bunch of workouts from our Tonal smart gym that come through as weight training, but they're really other modalities. Unfortunately, the only thing I can do is create separate automations to recategorize each one by name. It would be handy if I could do something like "If name is x or y or z then change type to yoga". That would drop it to just a few automations.

I did have the insane thought that maybe if there were an option to allow RegEx, the highly motivated few could use it for more complicated scenarios without complicating things for the majority. However, the idea that RegEx simplifies anything makes my head spin :-)

igoramadas commented 1 year ago

Well that's 3 people now, so... I'll investigate how much work is needed to add a flag to change the operator from AND to OR on a given automation. Or to allow a single condition to have many fields to compare to (so OR on a single condition instead of the whole set of conditions).

It won't happen this week thou, as I'm currently on a cycling holidays and should be back only late next week.

@mitchgibbstek regex would open a whole can of worms. Way too many things to consider security and performance wise. I know it's technically possible, but that would be a very, very niche use case so keeping it out of scope for now.

sevitz commented 1 year ago

Ah thats great. Thanks for considering.

Have a great holiday. 🚲

mitchgibbstek commented 1 year ago

Wow! My vote may have pushed it over the threshold? See kids, every vote matters. 🤣 Enjoy your holiday and thanks both for looking at adding the feature and for creating such a useful tool. My friends thank you too since they are spared being spammed by my workouts ;-)

kampelmuehler commented 1 year ago

+1 for completeness

Knagie commented 1 year ago

I only just now discovered the Conditions area was AND and not OR. I have 8 different buildings I sometimes need to travel to, either at the start of the day or travel between them during the day. I added all of these as "End location is X" and was wondering why that didn't work. Is there an obvious way to know conditions is AND and not OR, without trying like I did?

I would love to have my commutes all covered in 1 automation instead of the 8 I would need to create now just for my morning commutes. As well as (yea I'm picky) the 8 for the commute home which might start at any of the 8 locations. With an OR option that could all be set in 1 automation instead of 16 duplicates with just a different start/end address :)

And just setting it to "End at home" wouldn't work as I also have other bike trips that end back at home.

So make that 6 people now looking for the feature? 😄

igoramadas commented 1 year ago

The problem with making automation recipes with ANDs and ORs, as stated before, is that it's quite clear for programmers and people with a technical background to understand it, but extremely confusing for everyone else. People will wonder what is the correct order, will an OR negate a previous AND, etc... And considering that I am a moron regarding UI and UX skills, I'm pretty sure the end result would suck.

I am thinking about making all action fields multi-valued (like it already happens for sport types and week days, for example). That way, you could say "if location end is X or Y or Z". Or "distance is A or B". This is easy to do, and pretty simple to explain / lay out on the UI. I'll get this done and publish it to the beta website for testing sometime next week (too busy at work these days, sorry).

@sevitz in your example, can't you simply use "Passes on location" instead of start / end? Unless your house is mid-way on some walk activities and you want to exclude those :-)

sevitz commented 1 year ago

Ah didn't see that was an option. Useful. Can use that for a bunch.

Think the modal might also solve a different bunch, which should reduce the need for a pure OR operator in a lot of cases (although as a (former) programmer I can still see a AND/OR option being useful)

igoramadas commented 1 year ago

Logical operators now available for testing: https://beta.strautomator.com/

PS: the beta environment is restricted to PRO users, and at the moment the UI is still not working with Google Maps (for example, when fetching a location for an automation condition). Maps will be enabled sometime this week.

Still need to do some polishing.

Preview

Knagie commented 1 year ago

That was really quick! Thanks for this, I'll mess about with it once I'm back home.

igoramadas commented 1 year ago

Made some tweaks to the UI today.

I'm planning to release this to production next weekend, so if anyone has suggestions or major feedback (like: it's awesome, or it completely sucks), you have 4 days to do so :-)

mitchgibbstek commented 1 year ago

I'm testing it out, creating an automation with two triggers conditions of different types (word exists in Name or Description) with OR with actions to change the sport type, mute, and stop further processing. It won't let me save it. It acts like I haven't clicked the button. Not sure if that's intentional. I've tried a couple of times and tried simplifying the criteria and actions but I get the same result.

The Logical Operators make sense to me and seem like a good compromise, but I could imagine them potentialy confusing some people. The visual, after you've selected one or both of the options, makes it very clear to me what it's going to do though,

igoramadas commented 1 year ago

@mitchgibbstek can you please press F12 (or open your browser's dev tool) and check if there are any Javascript or network errors on the console? I just tried a few random automations now using my account, but had no issues, so I need to know how to replicate this.

mitchgibbstek commented 1 year ago

@igoramadas It looks like it's CORS.

Access to XMLHttpRequest at 'https://strautomator.com/api/users/10969429/recipes' from origin 'https://beta.strautomator.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
489a54e.js:1 

       AutomationEdit.save o
(anonymous) @ 489a54e.js:1
strautomator.com/api/users/10969429/recipes:1 
igoramadas commented 1 year ago

@mitchgibbstek can you please try again? I have changed the build process to properly set the axios URLs now.

mitchgibbstek commented 1 year ago

@igoramadas Yep! It's working now.

I created an automation with multiple criteria of the same type (Name has). I ran it against several Strava activities that, I think, it should match. It worked for two where the names matched exactly.

For another, I think it should do a partial match - it's looking for "Day of Focus" and the activity's name is "Day Of Focus: Wave" but it didn't pick it up when I fed the URL to the automation. If I misunderstand how it works and that it has to be exact matches, "is" or "equals" might be clearer than "has". If partial matches are okay, then "contains" feels more consistent with how this sort of thing shows in other applications. Just my opinion though.

I also noticed different behavior when choosing Conditions or Actions allowing me to type part of the entry. It works much better than how it's working for me in production.

Thanks!

igoramadas commented 1 year ago

@mitchgibbstek thanks for the feedback. I will consider rephrasing some things to make sure everything is crystal clear.

You are correct: with so many conditions and actions now, I switched to an autocomplete box where users can type what they want. Production is still using the old style (simple select box).

igoramadas commented 1 year ago

Version 23.97.11555 is going live today. Beta testing was quite limited (only 7 users), so I don't think all possible use cases were tested, but I'll keep the existing instances running in parallel so if anything goes wrong I can quickly switch back. Otherwise, feedback is always appreciated.

Knagie commented 1 year ago

It works great for me, though it's so far only limited to my above use case. It does safe 15 automations so that's great. Probably also saves computing time as I can let it stop after marking it through my commute options instead of going through every automation.

UI was pretty clear to me, the AND and OR options change at the top as well if you change both so it clearly displays how it should work. And testing it with a manual activity is great to see if it works as intended.