How to detect an "On" when the switch is already On?


#1

I have set up a virtual switch which controls 2 devices which are discrete On and Discrete off for an x10 light switch. i am trying to use the virtual switch to combine the two discrete on and discrete off switch to become 1 switch.
I created a virtual switch (using Alexa Virtual Switch Creator) called Theater Light Virtual.

I created 2 Core pistons:

The first is Theater On:
If Theater Light Virtual changes to On, Then Turn on Theater Light On.

Second one is Theater Off:
If Theater Light Virtual changes to off, then Turn on Theater Light Off.

Well it works, but only the first time (or depends on the original state of Theater Light On and Theater Light Off).

If Theater Light On is already on for some reason, and I try to turn Theater Light Virtual on, it won’t work. Same thing goes if Theater Light Off is on and I try to turn Theater Light Virtual off, it won’t work.

I also tried instead of turning on Theater Light On to toggle and still didn’t work.

i think my problem is that these are not 2 way devices so ST doesn’t know if the light is already on or off.

How do i change the if then to something like:
If Theater Light virtual has been pressed (whether it is the on or off button) and the state is On,
then Turn on Theater Light On.
If Theater Light virtual has been pressed (whether it is the on or off button) and the state is Off,
then Turn on Theater Light Off.


#2

At the top of your piston, click Settings, and then click the little gear cog at the bottom of the dialog window to see more options. Set your “command optimization” to disabled and see if that works.

Command optimization prevents webCoRE from sending redundant commands to devices (to turn on if already on, for example). Hopefully by disabling this feature, your virtual switch will always send the on/off commands to both lights regardless of current state.


#3

What should i use for the If statement? If i use If switch changes state, it won’t work because if the switch is already on and i am trying to turn it on, the state isn’t changed so the statement is false.

I actually initially tried this on Core, not Webcore. For some reason on WebCore my Virtual switch doesn’t show up.


#4

Don’t forget that you have to authorize devices in ST for webCore to see them. In the Classic app, go to Webcore, Available devices and contacts to select.


#5

Ok thanks. Still trying to figure out how to write the If statement for If button is pressed (but the state may or may not be changed)