Can I include required expressions in custom apps

Hello, I've looked for an answer to this, but can't seem to find anything related. I use required expressions for a lot of my rules and would like to include this option for apps that I create. Is there a way I can do this?

Thanks

If you're writing the app you can write it any way you like.

1 Like

Sure, but aren't required expressions a special case where it doesn't even run the app/trigger if the conditions aren't met?

Can you clarify what you mean by "customer apps"? Do you mean custom Groovy code you are writing yourself under Apps Code? If so, yes, as mentioned above, you can use regular expressions anywhere Groovy supports them.

Custom apps, however, don't have "triggers" or "conditions," so it's not clear to me if this is what you mean. Do you mean Rule Machine rules? Those are terms invented by that app. In a custom app, you could create a similar outcome, but the app will only do whatever you coded it to do--these are not some constructs or terms inherent to the platform.

More information might be helpful.

2 Likes

Sorry, that was a typo (will update title). Yes "custom" apps written in Groovy.

I see. I was hoping required expressions were part of the hubitat platform and I wouldn't have to rebuild the complex logic that allows a user to define whatever expression they wanted.

For context, I have this app that I use to schedule when various switches should turn on/off. I've built in mode functionality and the ability to only run if a certain switch is set, however I would prefer to have it more general and allow users to be able to enter any expression they desire.

OK, I misread "required expressions" as "regular expressions." The above is all still true, but I'm thinking Rule-Machine-like expressions are, in fact, what you mean. There are no built-in app/driver code features to do anything like this -- you'll have to use the same hub UI constructs and Groovy code features that are available to any developer, whether you or the RM author, who created and has tweaked over the years through what I imagine is no small undertaking.

If you're writing a custom app, doing this in the code and providing only the minimal UI you need to actually select the devices if often an easier approach -- and the fact that you can do this is one advantage of writing custom apps in the first place. The more you try to make it one-size-fits-all, the more your app will turn into something resembling more complex apps or even RM, but there's nothing stopping anyone from doing exactly that if they want to. :slight_smile:

No, these are just part of Rule Machine, specifically its child app Rule 5.1.

As to trying to code these yourself, no bueno -- this is a difficult problem involving recursion, frequent page refreshes, and the interplay of the logic and ui. I was actually just working on an aspect of expressions (editing them), and the code around this stuff is way difficult.

You could possibly get close to a solution using a rule as a gatekeeper for your custom app, where the rule would have a Required Expression, the same triggering events that would have been in your app, and a way to fire your app (e.g., a Hub Variable, or virtual switch set by the rule fires the app).

2 Likes

Thanks @bertabcd1234 and @bravenel. I was worried this would turn into a complex endeavor which I didn't want to take on. It'd be cool if one day required expressions was a sort of component that could be implemented in apps, but I'm sure that's a large undertaking. In the meantime I'll just stick to adding my known use cases such as "only run during selected modes".