How to execute a scene from a rule?

I found quite a number of examples how to create a JSON rule to run a command on a device which basically looks like that

        "command": {
           "devices": [
              "GUID"
           ],
           "commands": [{
              "component": "main",
              "capability": "switch",
              "command": "off"
           }]
        }

How to execute a scene instead?

Hi, @alex.49.98!
Up to now, it is not possible to execute scenes using the Rules API but remember that ā€œthenā€ is an array so it can include several instructions to execute.

Can you still use the old trick of having the rules API recipe turn on a virtual switch, and then having an automation activate the scene whenever that virtual switch comes on? :thinking:

Obviously itā€™s more steps, but is it doable?

Yes, it is possible. You can use the Edge device of the Hello World sample to do so

1 Like

Or if you are using the Android app, you could just use the virtual switch creator in smartthings labs to create a virtual switch, yes? That would be quite a bit easier for people who are not using Edge Drivers yet. :sunglasses: but I donā€™t believe thatā€™s available in the iOS version at this time.

Hereā€™s a good third-party video on that process:

I know this thread is a little dated at this point, but is it still not possible to use Scenes in the Rules API? I see it listed in the documentation as an operand but I donā€™t see any examples of it.

If it isnā€™t possible still (dumbfounding) then what is the best way to set the colorTemperature of a hue light? I see that the capability and command are both colorTemperature but wasnā€™t sure if you needed to just use the command: {{ temp in K }} or do something different. These two questions are tied together because I have scenes that are already doing the setting of the temperature, but iā€™m not finding any examples of how to set the temperature via the API/Rules API.

2 Likes

Thereā€™s a new community created edge driver which has many different types of virtual devices, just in case you decide you want to use that method without using groovy:

I know it would be better if you could just activate a scene from the rules API, I just donā€™t know if you can. :thinking:

Thanks @JDRoberts . I started using that this week, actually. Was running into issues with the old Groovy virtual switches and had to switch over almost all of them. Now iā€™m working on slowly killing old WebCore pistons and trying to use the Rules API as much as possible.

I did find an example where you can use setColorTemperature, so now iā€™m going to try some API calls to figure out the exact format of the JSON. Thinking that if it works in the API it might work in a Rule as well.

1 Like

Scenes are similar to Routines in that they are basically Rules that are only maintained by the mobile apps. However, unlike Routines, Scenes are recognised as separate entities in the developer docs and have their own API endpoint. I suspect that is a historical thing and that ideally theyā€™d be quietly forgotten about outside the mobile apps.

Curiously, there isnā€™t a way to execute another Rule from a Rule, or at least not one that I know about. If there was Iā€™d drop all my Scenes in seconds for the same reason I barely use Routines.

So is there a way to execute a Scene in Rules? Of course there is as Routines are doing it. Can it be used by the rest of us? Yes. Do I know what it is? Yes. Am I going to tell you what it is? Not in a public thread Iā€™m not as there may be a reason it isnā€™t documented for public release and I donā€™t want to do anything to undermine Rules development.

I am looking for the same thingā€¦ how to call Scenes from a Rules APIā€¦ I am wondering why there is such ā€œdisconnectionā€ between the same platformā€¦

1 Like

I donā€™t know how new/old this is, but there is a ā€œproposedā€ capability for executing a scene. Once that goes live it looks like that might be the solution?

If it is the one I think you mean, I believe that is simply a capability to allow developers to handle their own concept of ā€˜scenesā€™ in a generic sense. Same as there is one for ā€˜modesā€™.

When it comes to executing Scenes in Rules, the solution is really ridiculously trivial and exactly what youā€™d guess it to be. However there may be a reason why it isnā€™t published in the API yet, especially as Scenes seem to have one solid foot in the toy department of the mobile app alongside Routines, and a toe in the developer docs and the API alongside Rules, which is all rather inconsistent. Curiously the developer docs says ā€˜A previously created Scene can be activated from within a Ruleā€™ but lists that as an operand.

1 Like

Reopening the old thread.

Can Scenes be used in Rules?

Per documentation in Smartthings Scenes Doc

Scenes do not have triggers; Rules do. However, a Scene can be used as a part of a Rule. See Scenes in the SmartThings app.

But the provided link is broken!

So, can you include Scenes in Rules or not?

1 Like

You mention YAML. While the cli seems to imply that a .yml file can be input, the API and the API Browser seem to only support JSON.

Do you simply convert your .yml rule to JSON, or is there a facility in API Browser that I was not aware of?

YAML is a superset of JSON and the CLI uses a YAML library for input and output, handling the translation to and from JSON for the API automatically. I use the CLI to manage my Rules and, having been presented with the choice, I prefer to use YAML.

Iā€™ve pondered whether writing the Rules in another language would be worthwhile but it wouldnā€™t really gain me a lot as Iā€™ve been using the same Rules for a couple of years or more now.

As far as I know, and thatā€™s not much, the YAML format can be used only in CLI. As I find, as a non programmer the CLI interface too intimidating, thatā€™s not an option for me. Thanks to @TAustin for the fantastic API browser which enables people like me to play with templates and adapt routines to make rules. Maybe the rules API will be made more accessible in the future, so at least I could see the rules from the app.