How to code a routine that works?

I found this thread with code and i wonder how to create it myself to work in smartthings, or where to view my own created routines in the app, in code like that.

Help would be appriciated, thanks!

That is webcore which used to be the most powerful scripting tool for SmartThings. It ran as a smartapp inside your groovy shard (tenant) in SmartThings.

Unfortunately it and the rest of the groovy infrastructure is on its way out. At this point only a few months left.

All the automation in ST is now based on the rules api you can access the rules api directly instead of the rule editor. See here for more information.

No rules you created in the UI are not available for editing by RulesAPI and vice versa (ST design decision). No there’s no visual editor for the rules api. Instead they are directing people to the IDE of thier choice in concert with a CLI for SmartThings (you’ll see it in the thread)

SharpTools also has an advanced automation editor available but i have not used it and cannot speak to its features.

@goosetapo feel free to tag me if you have any questions about SharpTools.

Looking at the post you linked, HTTP Triggers are available in SharpTools rules and Math/Date expressions are available publicly in our labs environment and available as a native feature in beta as of today. :slight_smile:


:tada:Update: Math and Date Expressions are now available in SharpTools!

Here’s a quick example of some of the neat things you can do with expressions. I was moving pretty quick to keep it under a minute so feel free to pause as needed, but the video includes some basic math with variables, date manipulation, logic and more!

We’ve also started stubbing out the documentation here:

I am using zigbee/z-wave switches for what i want. When i use sharptools, i suppose that a permanent internet connection is suddenly needed to make the routines i program in sharptools work?

Yes, I guess I’m confused on the context though. The post you linked to was for an HTTP Trigger which would fundamentally require cloud connectivity. :thinking:

If you’re just looking to use general lighting routines, you can create them in the SmartThings mobile app. Many of those will run locally nowadays. There’s not a way to view those as a line-by-line code like UI though.

Sad but thank you for the help!

In SmartThings, “routine” is a term used specifically for the instructions you can create inside the SmartThings app. You don’t get to see the code for those, just the user interface in the app. So I think the term you are looking for is “automations.”

There are two kinds of automations you can create where you can see all the details, but neither will show up in the SmartThings app. They use a backend connection to the platform.

1. Use a Custom Smartapp to Access the SmartThings API

SmartThings only recently began offering a standard REST API. You access this through the cloud. You can write whatever code you like using whatever programming language you like, and host that code yourself wherever you like—but the access point to SmartThings is in the cloud. This is how most third party integrations are written now.

  1. Use the official Rules API

The Rules API is one endpoint on the SmartThings API that lets you upload rules to your account. The rules will use what is essentially a scripting language for the SmartThings platform. You can write the payload in either JSON or YAML. It is unique in that you do NOT have to host the automation yourself. The automations will run on the ST platform after you have uploaded them whenever the conditions that you specified are met. Right now that means they run inside the ST cloud, but the publicly stated intent is that eventually many rules will be able to run locally on your own hub,

This was originally intended as the substitute for Webcore, but partway in they dropped the part of the project that would have created a visual front end for it.

Instead, you will have to download the CLI tool (command level interface) and the new ST SDK onto a pc/laptop.

Then you will write your own code for your rules (which ST calls “recipes” when they are added to your account through the rules API, as opposed to “routines,” which are added through the smartthings app.). Once you have written your recipe, you upload it to your account in the ST cloud, and then it can run based on the conditions you specify. Right now that is in the cloud, but eventually it might be local.

So you will always need the internet to add new recipes to your account. But maybe some day they will be able to run locally. (No promises, though.)

To be honest, I don’t know the exact process for getting a recipe from your pc to your ST account, but others can help with that.

As @nathancu said, there’s a whole section of the forum dedicated to the Rules API—you can ask further questions there.

3. An Unofficial Alternative: Use MQTT

If you really want your custom automations to run locally now, there’s a third alternative. Set up an MQTT broker on a local server and use the following project to integrate with ST locally. It still won’t show up in the ST app, but you do get local operation and the ability to write custom rules.

Integration Solutions using MQTT

That said, logically if you’re considering option 3 the question would have to be asked why you don’t just consider Home Assistant instead of SmartThings? It’s free, it’s local, you control the code. It’s too hard for many non programmers, but with your coding background it does seem like a candidate.

Hopefully someone who knows more about this stuff will correct me if I’ve gotten anything wrong. I’ve been following the architecture discussions but haven’t used the tools myself. :sunglasses:

@scottinpollock @Automated_House

1 Like

We should also note that Webcore itself, which you referenced in the first post, was, like all custom groovy code in SmartThings, cloud based, so required a permanent Internet connection to work. That’s why so many people see SharpTools as a good postgroovy alternative. SharpTools doesn’t run local, but neither did Webcore.

In the old architecture, the only stuff that ran locally were the routines that you created through the smartthings app, and only some of those.

In the new architecture, because of the option of using an edge driver to communicate to a local server, you do have the additional local choice of using MQTT, for example. But that’s way too technically complex for the typical smartthings user.

Every system has pluses and minuses, and a nice app is one of the big pluses that smartthings has. But that app requires an active Internet connection, even if the phone is on the same LAN as the hub. They didn’t have to design it that way, but they did.

1 Like

And hopefully they change that, especially if they want to reduce hosting costs (which seems high on their checklist).

Philips HUE has done a wonderful job with their app. With an internet connection I can control my lights from anywhere… but if that connection goes down, I can control everything on my local bridge via a WiFi connection to my LAN… flawlessly.

3 Likes