Trying to create lights that follow a simulated switch


#1

1) Give a description of the problem
I’ve created a piston that turns a group of lights on and off when a simulated switch is activated.

2) What is the expected behavior?
I would like the simulated switch to turn off when I turn off the lights manually (or with another piston)

3) What is happening/not happening?
I think due to some sort of race condition, the lights turn on and then immediately off.

4) Post a Green Snapshot of the pistonimage

So what am I doing wrong?


#2

You could try doing something like to simplify the on and off.

On events from {metaSwitch} switch
Using {lightSet}
set switch to {metaSwitch}
End on event

Then to keep them in sync when turning them off

If any of {lightSet} switch changes to off
And
{metaSwitch} is on
Then
Using {metaSwitch}
Turn off
End if


#3

Wow, your simplification is pretty sweet!

However, its running into the same issue. Lights turn on, then immediately off. I’m assuming its because for a brief moment, the metaSwitch is on and the lightSet is off? I thought about putting some sort of timer in there, but that seems like a hack.


#4

In the second condition you can change

and
{metaSwitch} is on

To

and
{metaSwitch} was on for at least xx seconds

Find the sweet spot so that it doesn’t run into the race condition


#5

Nailed it. Didn’t know about ‘was on for xxxx’ either. Thanks!


#6

Hey, i have a similar set up. Can you please share how many seconds you used? im still having some issues i think i might need to create a new topic in the design piston help :man_shrugging: thanks


#7

This is what I ended up with.


#8

For what it’s worth I’m adding my template. I use this for all the virtual dimmers in the house.


#9

No one would be able to use your template because you shared the one that says do not share on it.


#10

Here’s the template with the correct snapshot :slight_smile:


#11

I know there’s already a solution for this post, but just giving my 2 cents. As much as I love using pistons for everything, there’s actually already a SmartApp available that works awesome for this, so why reinvent the wheel.

It’s called TrendSetter. I have it set up for a few spots on my house.

You set up a new device in the app and it auto creates the virtual device for you (the smart app also comes with a few virtual device handlers you have to install). And it does all the things you’re asking for and more.


#12

Personally, I had a couple occasions where I didn’t know which smartapp was doing something that I didn’t want it to do. Took me way longer to track down then I wanted it to. So for that reason alone, I’d much rather have all my automations in one place, webcore.


#13

How do you get the “On Events From” trigger? I’ve been looking all over and haven’t found anything.


#14

Have a little look here. https://wiki.webcore.co/#The_execute_section


#15

This opens up so many more possibilities! Thank you so much!