FAQ: Getting Started with the new Rules API

It you extended Routines to support a sequence of nested if-then-else groups, each with nested and-or condition, plus a sleep action, you’d pretty much have the current functionality of the Rules API. Actually you’d have more because Routines have access to as yet undocumented Rules.

No loops, no variables, no functions and none of the TCP/TSP/TEP cleverness.

WebCoRE pistons are effectively event handling scripts. Indeed I think webCoRE functionality would best be reproduced by writing SmartApps in a general purpose programming language, though you wouldn’t get the local execution (but you don’t have it now).

To me Rules feel more like a mesh of binary operations that are constantly being updated with the result bubbling up to the top and a ‘trigger’ just meaning that the conditional actions are activated at that point. Something like Smart Lighting on steroids. If you have ever watched the live logs for that you can see the restrictions are constantly being updated even though there haven’t been any trigger events.

That’s just how it feels to me. It is likely drivel.

Rules can be activated by an HTTP request.

thanks!
So I think that I ll wait to see because I like ST but I I think that I wont be able to do nothing after the lost of groovy and the chance are that I leave to hubitat… Pretty frustrating that something that works flawlessly is being updated with something that offer no flexibility… I was thinking of a both local and cloud system where all functionallity would be there and you try to transfer all of that local through time to be able to stop the cloud… kind of desapointing!

is anyone know if it would be possible to install webcore elsewhere (rasberry pi or something) and then link it to devices ?

The easiest way I think would be to run webcore on Hubitat and then use something, maybe MQTT, to connect back to smartthings if that’s what you want.

Webcore has its own forum, you can check there to see what people are planning to do.

And here’s a new project which will provide MQTT integration with the new smartthings architecture.

Integration Solutions using MQTT

I know where to make the WebCore pistons but I have no idea where the rules api code goes. Where is a simple explanation for how to put a rules api function into my hub.

I cannot believe that I cannot find this. Why?

Please post the links.

Introduction to RulesAPI
Create Automations via computer - Apps & Clients / Features & Feedback - SmartThings Community

Thanks for pointing me to something that will work. But yikes, there is no GUI like we have now to review our code and update it? And it looks like that is a community built CLI. What?

This was announced very close to THREE years ago and there is not a better implementation? Wow. Is this why Adrian (WebCore guy) left?

Thanks again TapioX.

1 Like

There is. Routines in the mobile app is a GUI for the Rules API. Limited? Yes, but still a GUI. What we haven’t seen is a complex rule building GUI for Rules API.

In the Community forum Developer Programs > Tutorials you can find step-by-step guides to create several things, for example, an Edge driver, ST Schema, Rules and others:

edge:drivers

I’ll create a report so those links are included in the developer documentation.

1 Like

I think that is ok and please do it. What would be more helpful is a dedicated page that says, “You used to use WebCore, this is how you use the Rules API”. This page would have all the basics to get going. A short tutorial on setting up the environment (e.g. community (very weird) CLI and VS Code and etc) and how to get your code to work in a similar manner. For example, 1_ This is how to turn on a light when a switch is turned on. 2_ This is how to make something happen when it is 22 minutes before sunset. ← maybe these would be links to examples that exist.

I have code that goes out to a URL and parses the return to then call VoiceMonkey (another external site). If you could do a sample like that; bonus.

I do not see many people that haven’t used WebCore now deciding they are going to ramp up on Lua. Maybe later.

The thing I was missing in a big way was how do I get the code into the hub but I am sure I will find other obstacles that have already been figured out but are all over the place.

Thanks

1 Like

There’s also a repository where there are several Rule examples just for you to copy, replace the corresponding IDs and save them.

Where there’s another tutorial using Postman (which avoids the usage of a text editor), the CLI is a tool that helps you interact with the ST API from the console, but, you can send direct commands to the API, this means you can create them from other integrations that you develop, you would only need to make the corresponding HTTP requests.

Creating an app to consume the ST API directly would help you solve your issue with the requests to the URL because currently, the Rules API doesn’t support requests to URLs.
Or, as WebCore already lets you make calls to external URLs, depending on your automation, you could send the corresponding commands to your ST devices, but, that integration would be hosted in the Cloud. For this you would only need:

  1. A Personal Access Token that you’ll need to use in the authorization header of the HTTP request
  2. Point to the correct ST API endpoint. For example, this is the URL to send a command:
https://api.smartthings.com/v1/devices/deviceID/commands

**Body:

{
    "commands": [
        {
            "component": "main",
            "capability": "switch",
            "command": "on",
            "arguments": []
        }
    ]
}

Lua (Edge drivers) is for device integrations, not automations. If you create a device using the driver, you can set up certain schedules, actions that help you automate its behavior but it won’t allow you to modify the one of external devices.

As you can see, I have not been keeping up with this change as it didn’t seem to be coming soon.

Thanks for the information you have provided so far and please make a page for the many people that will be coming from WebCore to Rules API and ST API soon.

1 Like

I think it would benefit non developers to have a more straight forward step by step tutorial with more basic instructions than having to click link after link and getting confused. I’m sure the documentation is easy enough for people who know what all the terminology means but for those who want more powerful rules but are not developers it is just overwhelming confusing!

6 Likes

I’ve always preferred to use automated APIs because they are simpler and more understandable. Maybe it is not really professional, but that makes my work easier and helps me solve the tasks I was assigned faster.

Does anybody have a quick solution for doing a rules api condition of between two times? For example, I want to have the IF use BETWEEN for 5am to 30 minutes after Sunrise. I know that BETWEEN uses “VALUE”, “START” and “END” but i’m not sure how to put the TIME object in that sequence. Normally you would specify the value you want in the END and then just use a string or integer in the other two, but i’m not sure how that would work when dealing with time objects. Thoughts?

In YAML it would look like:

        - between:
            value:
              time:
                reference: Now
            start:
              time:
                reference: Noon
                offset:
                  value:
                    integer: -7
                  unit: Hour
            end:
              time:
                reference: Sunrise
                offset:
                  value:
                    integer: 30
                  unit: Minute
1 Like

Interesting. Why the NOW reference in the between section?

A between is testing if value is between start and end. In this case we are dealing with times and in Rules times are defined in terms of a reference and an offset. As we are interested in comparing the current time at the moment the Rule is executed the appropriate reference is Now. As an aside you could apply an offset so you could effectively say ‘ten minutes ago it was between …’ or ‘in thirty seconds time it will be between …’. It probably doesn’t gain you anything but it is fun.

You might like to keep an eye on the sunrise time if your rule runs in the cloud. For the last year I’ve had a bug with sunrise and sunset not updating daily in cloud based rules.

Got ya. Simple answer- comparing current time to beginning and start times of condition. Thanks!!

Indeed, so I thought I’d dress it up a bit for those who haven’t encountered the Rules way of handling times.

2 Likes