Virtual Device (switch) states update

created a virtual switch to control a wall switch (experimenting HomeKit integration), can't figure out a way to update the virtual switch states if the physical switch states changed.

How is the physical wall switch set up? Is it on HE, Alexa, or ???

1 Like

the setup is on HE.

There used to be a Mirror app, but you can also use a rule to do set the virtual on/off based on the physical state.

2 Likes

Can you guide me how to setup this rule,
Currently I’m having 2 rules per switch, one to turn it on and the second to turn it off, but I’m having an issue that sometimes when I turn the switch off it goes into a loop of turning off 10 sec then on, then off again.

Basically there are 4 conditions that you want to trap and respond to:

  1. If physical switch changes to on, set virtual switch to on
  2. If physical switch changes to off, set virtual switch to off
  3. If virtual switch changes to on, set physical switch to on
  4. If virtual switch changes to off, set physical switch to off

You'll get a small loop, but it will stop when it discovers that the physical and virtual agree, i.e. Triggering #1, will result in #3 also being triggered milliseconds later, but since the physical is already on processing will stop.

1 Like

Thanks a lot for your help, I think the endless loop is due to the delay in the mirror app, any idea how to set the rule to get the physical state to the virtual switch.

It will be a few hours before I get back home and get on one of my hubs, but I'll throw together a quick set of rules and post them when I do.

1 Like

Thanks a lot, I really appreciate your help.

This is a Rule Machine 5.1 rule for a physical switch on to turn on the virtual switch, but the idea is the same for all 4 of the conditions.

1 Like

Thanks a lot for your help and support, I created the rules using simple conditioning action, had to create 2 different rules, the first is to control the physical switch from the virtual one,

And the second is to mirror the physical switch states

Unfortunately when I tried to setup one rule that combine all, the switch goes through endless loop of On/Off, I believe it due to a the slight delay of the states synchronization between the virtual and the physical switch.

1 Like

Two rules IMHO is cleaner, but believe you are on the right track on the delay as there is a small fraction of time needed to write to the database. By default the database reads are via cache also, so another small fraction needed for the cache to realize it is stale.

Now I’m facing a new issue, while setting up the rules, I got an error on rule machine, I restated the hub and since then it’s too slow to respond and my old automation is not working consistently, even the device states takes long time to update. :woozy_face:

May want to look at the Apps and Device tabs on the Logs page and see if anything looks like it's eating CPU

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.