How to run an automation within a scene?

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

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.

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.

1 Like

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.


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.

1 Like

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.

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.

1 Like

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

1 Like

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

1 Like

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

1 Like