# How to run an automation within a scene?

**URL:** <https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600>\
**Category:** webCoRE\
**Created:** [July 28, 2020, 9:38pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600 "2020-07-28T21:38:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lukemclachlan](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lukemclachlan](https://community.smartthings.com/u/lukemclachlan)\
**Post date:** [July 28, 2020, 9:38pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/1 "2020-07-28T21:38:57Z")

</div>

I’ve spent a great deal of time investigating how I can run an automation within a scene, specifically how I can toggle the state of two hall lights when I say to google home “toggle the hall lights”. I know that I can run a scene within an automation and it’s well documented, but not visa-versa.

so for example:  
“ok google toggle the hall lights”  
if (main lights = on && cupboard lights == off) { turn off main lights && turn on cupboard lights) }  
else if (main lights = off && cupboard lights == on) { turn on main lights && turn off cupboard lights) }

Does anyone know how I can run such an automation within a scene using the latest smartthings app, or with webcore/postman. Many thanks / Luke

---

<div class="post-metadata">

**Author:** ![JDRoberts](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jdroberts/32/56577_2.png) [@JDRoberts](https://community.smartthings.com/u/JDRoberts)\
**Post date:** [July 28, 2020, 9:49pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/2 "2020-07-28T21:49:50Z")

</div>

If All you wanted was to run an automation that you would create with the normal “add automation“ option in the new V3 app, then you would have that automation run when a virtual switch came on, and put turning the virtual switch into your scene.

However, what you have described is not a standard Automation created in that way because of the else condition.

For that, you need to use either webcore or the rules API.

I’m still not quite sure why you would want to trigger that from a scene, but if you did, you could then use the same method of making one of the trigger conditions a virtual switch.

> [@How to Get Started Creating Complex Rules in SmartThings](https://community.smartthings.com/t/how-to-get-started-creating-complex-rules-in-smartthings/110612):
>
> (This is a wiki post: feel free to edit it or add to it as needed. Also, I can’t take any screenshots since I can’t use the app at this time due to its incompatibility with voiceover, so feel free to add screenshots where they would be helpful.) At one point, one of the biggest advantages of using the SmartThings platform was the wide variety of devices that it supported. However, by the end of 2017 several competing platforms had caught up in that regard. Where SmartThings still holds a significant advantage over some of the other low-cost home automation solutions is in the ability to really build really complex rules in a fairly simple manner. You won’t have to be a programmer, but you may need the help of other community members to get the logic constructed just right. Also, you …

---

<div class="post-metadata">

**Author:** ![nathancu](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/nathancu/32/45410_2.png) [@nathancu](https://community.smartthings.com/u/nathancu)\
**Post date:** [July 28, 2020, 9:59pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/3 "2020-07-28T21:59:33Z")

</div>

Third option:  
Two separate and distinct automations:

First automation:  
if (NEW VIRTUAL SWITCH == on && main lights = on && cupboard lights == off) then { turn off main lights && turn on cupboard lights && turn off NEW VIRTUAL SWITCH) }

Second Automation:  
if (NEW VIRTUAL SWITCH == on && main lights = off && cupboard lights == on) then { turn on main lights && turn off cupboard lights && turn off NEW VIRTUAL SWITCH) }

Should work anytime the virtual switch is turned on now that they’ve eased the restrictions on having the same device in the IF and THEN, Same effect as the if / elseif - just WAY more cumbersome to setup. It’d work, but I’d still do WebCoRE though.

---

<div class="post-metadata">

**Author:** ![orangebucket](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/orangebucket/32/81590_2.png) [@orangebucket](https://community.smartthings.com/u/orangebucket)\
**Post date:** [July 28, 2020, 10:40pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/4 "2020-07-28T22:40:39Z")

</div>

> [@lukemclachlan](#):
>
> if (main lights = on && cupboard lights == off) { turn off main lights && turn on cupboard lights) }  
> else if (main lights = off && cupboard lights == on) { turn on main lights && turn off cupboard lights) }

I’d like to add to the wise words of @JDRoberts and @nathancu by pointing out that your pseudo code would describe an infinite loop if implemented in an automation app that triggered on changes to device attributes. A virtual switch, which seems to be the best tool for the job at the moment, would also protect you from that danger but not without the risk of a race condition giving you undesirable results if a new automation was triggered before the virtual switch was disabled.

This is probably a job for webCoRE as that makes it easy to use just the virtual switch to trigger the piston with the status of the lights just being additional conditions.

---

<div class="post-metadata">

**Author:** ![lukemclachlan](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lukemclachlan](https://community.smartthings.com/u/lukemclachlan)\
**Post date:** [July 29, 2020, 7:47pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/5 "2020-07-29T19:47:14Z")

</div>

> [@JDRoberts](#):
>
> I’m still not quite sure why you would want to trigger that from a scene, but if you did, you could then use the same method of making one of the trigger conditions a virtual switch.

I thought about triggering it from a scene because I thought that was what scenes were about, but that was before I knew anything about virtual switches. I’ve only today managed to set up a virtual switch via webcore, been a little crazy, I’ll go ahead and play around a little more thanks to your suggestions.

---

<div class="post-metadata">

**Author:** ![JDRoberts](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/jdroberts/32/56577_2.png) [@JDRoberts](https://community.smartthings.com/u/JDRoberts)\
**Post date:** [July 29, 2020, 7:52pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/6 "2020-07-29T19:52:01Z")

</div>

A scene is just a snapshot in time of the settings for a specific set of devices.

To use the scene you have to activate it. Where you may have gotten confused is that you can activate scenes from a voice assistant like echo or Google home.

But more typically, you activate a scene by including it in an automation, rather than the other way around. So usually you would get to the point in an automation where you can select either devices and/or scenes to be controlled.

 ![image](https://global.discourse-cdn.com/smartthings/original/3X/4/e/4e7523aa4b398b564308a0893d70e8f276cf07c6.png)

---

<div class="post-metadata">

**Author:** ![lukemclachlan](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lukemclachlan](https://community.smartthings.com/u/lukemclachlan)\
**Post date:** [July 29, 2020, 7:53pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/7 "2020-07-29T19:53:00Z")

</div>

now after reading around I can see what you mean about the infinite loop with automations, initially I thought that an automation triggered only once but how wrong I was. Virtual switch has been created and I’ll test it out tomrrow, many thanks.

---

<div class="post-metadata">

**Author:** ![lukemclachlan](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lukemclachlan](https://community.smartthings.com/u/lukemclachlan)\
**Post date:** [July 29, 2020, 7:55pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/8 "2020-07-29T19:55:48Z")

</div>

> [@JDRoberts](#):
>
> you may have gotten confused is th

you’re a wise chap, google assistant did in fact lead me down that path 🙂

---

<div class="post-metadata">

**Author:** ![lukemclachlan](https://avatars.discourse-cdn.com/v4/letter/l/c68b51/32.png) [@lukemclachlan](https://community.smartthings.com/u/lukemclachlan)\
**Post date:** [July 29, 2020, 7:56pm UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/9 "2020-07-29T19:56:29Z")

</div>

let me give that a try tomorrow and I’ll get back to you, many thanks nathancu!

---

<div class="post-metadata">

**Author:** ![greenstuff](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/greenstuff/32/122991_2.png) [@greenstuff](https://community.smartthings.com/u/greenstuff)\
**Post date:** [July 30, 2020, 4:01am UTC](https://community.smartthings.com/t/how-to-run-an-automation-within-a-scene/200600/10 "2020-07-30T04:01:14Z")

</div>

Think of automations as a “state of being” especially for unpredictable moments… when it rains, when motion stops, when sunset happens… low battery… and multiple things and/or… then you can ask the system to “watch” for these states and whenever it happens, however often, run a list of your things. That list can be grouped as a Scene. Scenes are like button triggers… group around a widget or a real button… press and go. When to press? Run it from the automation. So I’d suggest make a scene or two grouping the lights you want on and off at a button press then add those as the action to your automations
