Using Groovy in Rule Machine

The Rule Machine GUI is a nice tool for "clicking together" some behaviour... :wink:
But (after creating the first 15 rules) I would prefer to write "real code" (my fingers are usualy faster than the mouse)... :grin:

So my question is:
Is there a way to use pure Groovy to define rules?

BTW: I've started using Hubitat only a week ago. Please excuse me when I've missed something in this forum and/or documentation.

1 Like

Well, yes, write an app. There are templates in the community GitHub.

2 Likes

Maybe I didn't explained well my wish:
I don't want to write completely new apps, I want to use groovy code instead of the action block in rules.

maybe look at webcore its interface is much more similiar to writing code.

Not possible -- somewhere over a bridge too far as a practical matter.

1 Like

An β€œapp” is only a few more lines of code.. It’s not complicated to make simple apps to replace rules.. I do it all the time, I start off in RM but when they start getting more complex, I prefer groovy.

Easier for my programming brain to wrap my head around.

5 Likes

I have seen this mentioned a couple of times, but are there any practical examples of app as a rule you could point people to?

1 Like

here is my app that i use to control my roof coil outlet.. it turns on based on a date range and temperature. range.. could easily do i n rule machine now.. but written in smartthings before we had rule machine. i still ported tohubitat and use it.

there are a couple of other apps in my github you can look at ..
colorcastweather which flashes lights based on different weather conditions and alerts.

also gardenhue for turning on colored light strings sunset to sunrise and changing fixed or random colors at various time intervals.

2 Likes

Thanx a lot for the example!

But is there any documentation about the API for such kind of apps?

The most important parts of Developer Documentation - Hubitat Documentation aren't documented. :disappointed_relieved:

Its not the best answer but the smartthings documentation is a great reference for writing apps and I've used it a number of times. As well as looking at existing apps to understand how they all work. Classic smartthings apps and HE apps are very similar so most of the documentation is relevant.

Some of the key things to read about are the definition section (which defines the app) and preference section (which is the main interface to the app). After that the key methods are installed, updated, initialize where your app will mainly kick off when you click on done.

After that you can create any methons etc to subscribe to events and handle events of devices you may have selected in the preferences section.

It will seem daunting at first but over time you get the hang of it and creating a new app is a lot of cut and paste with some tweaks.