Getting Started with Groovy for Hubitat

I'm working on getting started on doing some Groovy programming for my hubitat environment. Any getting started tips are apreciated....

I've already been reviewing all the links provided on the Hubitat documentation site, I'm looking for some best practices on...

  1. How do you set up your development environment... Do you have a test hub, or are you able to set up a java/groovy dev environment locally on a computer, etc...

  2. Any other tools/environments you use/setup go assist in your work

  3. Best syntax aware editors?

  4. Anything else I should know?

I'm planning on working on a project to do the following:

  1. Create an outbound API call which will allow reading of an external calendar (ical, or other calendar type). The use case here is that I own two short term rental properties, and I want to build other automation based on the rental calendar.

  2. Based on the calendar work in #1, work with modes (i.e. - manage away vs other modes so that based on the calendar set lights, thermostats, et al appropriate to the status of the house)

  3. EIther extend, or create a new version of lock code manager. Allow the data in an external calendar/application (lodgify, Airbnb, VRBO) to drive enabled lock codes on doors.

Thanks in advance for any pointers as I start work on this.


Some people use their primary (or only) hub. I eventually got a test/development hub for this kind of thing, but there's no need to. However, it may make things easier if you know that all log entries came from your app or driver, for example.

While you can test out general Groovy syntax on your own computer (can be handy if you just want to see things like how various List or Map operations work--if your API uses JSON, these are probably objects you'll be working with a lot), there is no way to re-create the Hubitat app or driver "sandbox" on your own computer. You'll need a hub to actually test execution at some point.

For me, not really besides the hub and the below (an editor). But for a large LAN integration I have that contains multiple app, driver, and library files, I did find and modify a small script (from here) to more easily upload these files to my hub without having to do them myself one-by-one. For apps or drivers that just have one file or maybe one or two more, it might be easier just to manually copy/paste the code.

Perhaps not "best," but some people here recommended VSCode (with Groovy syntax extensions installed) a while back, and it's good enough for me -- syntax highlighting, something vaguely resembling autocomplete (really just remembering things you've typed before, and not always in contexts when they're valid, so you need to sue a bit of your own brain, too), etc. It's also pretty lightweight and loads fairly fast (despite being an Electron app; I'm comparing this to things like IntelliJ or pretty much any "full" IDE).

(EDIT: I'll add that the built-in code editor on the hub works fine, too, and then you really don't have to worry about this question or the previous. But some people want an editor with more options, or maybe the ability to save something without needing to save necessarily valid code to the hub, which other things may provide.)

As long as this API offers a way to communicate over HTTP(S) in a way that fetches data you can parse (JSON and XML are both pretty easy in Groovy), this should be possible, but it's hard to say more without knowing how the API works. If you just need to fetch data from an HTTP(S) endpoint, the async HTTP methods (e.g., asynchttpGet) would probably be the best starting point. This can work in an app or driver, but it seems like an app would be best for the goals you want (apps can set hub mode and run commands like setCode() on a lock).

1 Like

If you use vscode, this plugin is super handy for automatically pushing to the hub. You can add a hotkey for running the push command.


In principle it is possible. It isn't complete at all (and not completely correct) but something like this idea
HubitatDrivers/src/test/groovy/HubitatEmulator.groovy at main · JasperVanLeeuwen/HubitatDrivers · GitHub would emulate a hubitat driver environment.

And you could use it for example in a test ( HubitatDrivers/src/test/groovy/TestMelDriver.groovy at main · JasperVanLeeuwen/HubitatDrivers · GitHub )

Thanks for all the great advise!