Rules, Scripts and Schedule

Hi, I have a design question, What is the intention of these 3 options? Rule, script and Schedule.
Rule I undestand. Script (if i undestand correctly are script that can only be run manually?) and schedule is a rule but with schedule tag. What are their intended purpose? Can I run the script from the script section from another rule? o put triggers in them? Is Schedule for organization purpose only?
Thanks

Type Purpose How it can be used
Rule Runs in response to an event, includes at least one trigger and one action. Can optionally include a condition. These will be used to drive your automation as the rules run in response to events.
Schedule This is just a rule with at least one time base trigger (cron, time of day, etc) and the Schedule tag. By tagging these rules with Schedule you can see when they are scheduled to run on the Calendar in the Schedule view. If you create a Rule from the Schedule page, it will have the Schedule tag added for you.
Script A rule that only has a single Script Action; no triggers, no conditions, only one action and has the Script tag. Can be called from other rules or run manually.

Yes, that’s what the “Other Rules” actions do.

No, then it wouldn’t be a Script, it would be a Rule.

For now yes.

Personally, I like to keep a bunch of Scripts that show examples for how to do various things in Script Actions like creating a Timer and such. The -Scratchpad- Script is nice and can be quickly accessed from the developer sideboard where you can quickly experiment with some code or issue some updates and commands. If you have scenes or something like that, one way to implement them would be to put each scene into a Script and then create Rules that call those Script rules.

Note that the Schedule page does not work with Ephemeris, Astro or other time based things that could trigger a Rule. Only cron and time of day type triggers and day of the week (not Ephemeris), time of day type conditions.

thank you very much your answers are always very useful. One personal question. what language do you prefere for the rules? why?

I don’t really have a preference. I don’t like Rules DSL a whole lot because it doesn’t have access to a lot of services and features that can be accessed from the other languages and it doesn’t support loading libraries.

As a language I like Python and recoded all of my rules into Python in OH 2.5. But those depended on the Helper Libraries which only recently has a PR submitted to upgrade it to support OH 3. If I were writing text rules instead of in the UI, I’d probably still be using Python.

JavaScript comes out of box and most of what makes it’s not fun to work with in text files goes away in the UI so I’ve been using it for now without any libraries except my own. I want my rules_tools to have as few external dependencies as possible. Since Python requires an add-on and the Helper Libraries I’ve been moving to JavaScript slowly but surely.

There is nothing that says you have to stick to only one language also. You can mix languages even in one Rule, just not in one Script Action or Script Condition.

1 Like