Curious About Simulated Switch Behavior

If a simulated switch is currently off, will sending it the off command cause it to send that off action on to the system, or will it just be ignored, because it was sent the command to enter the state it’s already in?

Of course, I could just test this to find out, but I want to know the expected behavior.


What I’m going for…

Basically, I want to have a simulated/Virtual switch that will pass-thru an on/off command once it is received, even if it is currently already in the state that is called for in the command.

To test this, I created two pistons in webCoRE…

Piston 1
if switch1 turns on
then turn on switch2

Piston 2
if switch2 turns on
then turn on switch3

When all three switches are off, and I turn switch1 on, the pistons turn on both switch 2 and switch 3.

However, if switches 1 & 3 are off, and switch2 is On, when I turn on switch1, nothing else happens (i.e. somehow, the command to turn on switch2 which is already on gets ignored, and the system never sends on the command to then turn on switch3).

Does anybody know of a way of getting it to pass the command through even when the switch receiving the command is already in the state being called for?

I’m interpreting the question as ‘will other apps/handlers see a state change event for the switch?’, and my understanding is that for the Simulated Switch the answer is no. However for the Virtual Switch the answer is yes. I can’t say I’ve ever tested it though.

1 Like

@orangebucket

Thank you.
I had forgotten about the distinct device type named Virtual Switch.
Well…I just tried it, and unfortunately it appears to operate the same as the Simulated Switch as far as my question is concerned.

Basically, I want to have a simulated/Virtual switch that will pass-thru an on/off command once it is received, even if it is currently already in the state that is called for in the command.

To test this, I created two pistons in webCoRE…

Piston 1
if switch1 turns on
then turn on switch2

Piston 2
if switch2 turns on
then turn on switch3

When all three switches are off, and I turn switch1 on, the pistons turn on both switch 2 and switch 3.

However, if switches 1 & 3 are off, and switch2 is On, when I turn on switch1, nothing else happens (i.e. somehow, the command to turn on switch2 which is already on gets ignored, and the system never sends on the command to then turn on switch3).

Does anybody know of a way of getting it to pass the command through even when the switch receiving the command is already in the state being called for?

Does the option “disable command optimization” achieve what you are looking for?

2 Likes

I tested by disabling in each of the two pistons individually, and having both of them set to disabled, but unfortunately, that did not change the behavior I’m concerned about here in any. of those three tests.

Thank you though.

Do you have any other ideas to try?

Yes, I just tested it also, with Virtual switches and Simulated switches. It failed with both. Hmmmmm, very interesting.

@WCmore, thoughts?

Turning on Switch_1 does turn on Switch_2. But it certainly does not turn on Switch_3 if Switch_2 is already on. Nothing even registers in the log for Switch_2 in the second piston.

1 Like

You would have to write a custom DTH for the switch that has “isStateChange: true” onto the end of the event creation. That is the only way you can get a device to broadcast an event where the value is the same as the current value. Any webCoRE or app workarounds will NOT work. Must fix it at the device level.

the correct way would be:

sendEvent(name:"switch", value:"off", isStateChange: true)

So, if you try and create a virtual switch DTH from one of the templates in the IDE, you would just have to change the sendEvent line.

1 Like

@sgnihttrams, as @Ryan780 stated above, you need in the DH’s sendEvent the isStateChange: true.

Natively when the sendEvent used in a DH it compares current state and the sendEvent’s state. If they match, then isStateChange is false, so the state hasn’t changed and no need for event to raise. But if you set it to be always true, then it will raise an event even if the state is the same.
(It can be useful for temperature measurements to register all reports even the temperature hasn’t changed.)

1 Like

It sounds like the various options have been tried. However you certainly need to disable command optimisation in webCoRE as no command is sent to the device handler at all without it. The Virtual Switch has isStateChange set to true for on and off.

1 Like

Thank you!
I will be testing this tonight…

Thank you for the added confirmation on this.

:frowning: bummer
I’m pretty sure I tried that before, but I will go through it again, and see if this combination gets it to work.

I’ll report back in a while…

UPDATE:
Unfortunately, while using the ‘Virtual Switch’ DH for all three switches involved here, and while having command optimizations disabled for both related webCoRE pistons, it’s still not passing the ‘turn on’ command beyond switch2 when it is told to turn on while already in the on state.

I will take a look at the code for the Virtual Switch DH to make sure it does actually have the recommended condition…

…yep. as @orangebucket said, it’s there for both on and off…

def on() {
    sendEvent(name: "switch", value: "on", isStateChange: true)
}

def off() {
    sendEvent(name: "switch", value: "off", isStateChange: true)
} 

Is anybody else getting the behavior I’m looking for with this same configuration?

1 Like

When you say “not getting the on behavior” do you mean from your webCoRE piston? Can you show your pistion?

1 Like

Why are you separating these pistons? You can use changes, and a second condition,switch 2 is equal on.
Do you want switch 2 to turn on switch 3 itself as a separate piston or you just want to chain all 3 together?

1 Like

Well, I could post a piston, but it is so simple that I didn’t feel it necessary.

All I’m doing is this…

Piston 1
if switch1 turns on
then turn on switch2

Piston 2
if switch2 turns on
then turn on switch3

Other than the part about disabling command optimization as recommended, that is all that is involved with these two pistons.

@Pantheon posted a couple pistons above that probably show what I’m doing.

In the example of my two pistons, I want switch3 to get turned on when switch1 turns on, regardless of whether switch2 was on or off when the ON command got to it.

At this point, I’m assuming this is just not possible, but if it is, I will try whatever hints or tips anyone gives me. :slight_smile:

I suspect this is getting to be a ‘forest for all the trees’ situation. lol

Sorry. I really do try like hell to communicate clearly, but I tend to use a lot of words, because this is the only way I know how to communicate.

The number of pistons involved here is irrelevant (to me; I just want it to work).

The number of anything else is irrelevant (again, to me).

All I am wondering is whether or not it is possible to have a situation where a switch that is already on gets an ON command, and then a piston that is watching to see if that switch turns on gets triggered and goes off doing whatever it’s been coded to do…regardless of whether that particular switch was on or off when it received the ON command (and vice-versa).

I’m confused…if you are turning on switch 1 which turns on switch 2 which turns on switch 3, why not simply turn on switch 2 and 3 with switch 1?

Also, this doesn’t tell me anything about what you are trying to do when the switch turns on. Why do you need to turn on a switch that is already on? This isn’t going to accomplish anything different that it already does.

If switch 3 is already on, turning switch 1 on again isn’t going to do anything to switch 3.

I guess a brute force method would be :

IF switch_2 is on
  Then
    Turn Switch_2 Off
    Turn Switch_2 On
END IF

But it’s sloppy and makes many assumptions.

LOL

Perhaps stop thinking about the fact that they are ‘switches’.

Also, the number of them, or how I’m going about it is irrelevant.

I simply want to have piston2 still do its job even if switch2 is already on when piston1 executes.

Then I think it is better to ask the minions on the WebCore forum. As you can see from your test, it does not. I would think “changes to” compares the last state and current state. It is WebCore, and not ST so it might saves the last state.
Or if you trigger something with WebCore then it passes the triggered event to another piston and that as above would look for itself the last state.
But I am just thinking loudly. You might get better results if you do use conditions.

1 Like