Rules for emulating a 3 way switch?

I’m trying to do a rules based emulation of the tradition 3-way light switch (2 patio light switches controlling 3 sets of lights that should follow the controlling switches on/off). The idea being you can turn all the backyard/patio lights on/off from either of the 2 switches. So far my efforts have not worked well.

I’ve tried the obvious thing:
if (sw1 == on) {
sw2 = on
sw3 = on

if (sw2 == on) {
sw1 = on
sw3 = on

if (sw1 == off) {
sw2 = off
sw3 = off

if (sw2 == off) {
sw1 = off
sw3 = off

I’ve run into a number issues. Is the Do block of a rule atomic? It doesn’t appear to be.

So any ideas?

I’m curious why you’re trying to emulate a 3 way switch, rather than just having a single switch? It seems like you’re overcomplicating your setup.

Is the Do block of a rule atomic?


Thank you for the suggestion of the single switch. I created a virtual switch tied to 3 smart switches, added rules for the motion detection sensors.

So now if I flip the either of the 2 physical switches on, all the lights controlled by the virtual switch come on. If motion is detected, it triggers that virtual switch to be on for 15 minutes. If you turn either of the 2 physical switches off, it turns off the virtual switch and clears the 15 minute timer.

So you’re using the second switch as a sort of manual override? I think you could do this:

Rule 1:

if (motion) {
  switch = on
  timer.set(15 minutes)

Rule 2:

if (timer == expired) {
  switch = off

Rule 3:

if (switch == on) {
  light1 = on
  light2 = on

Rule 4:

if (switch == off) {
  light1 = off
  light2 = off

  timer.clear()  // probably not necessary

I kind of used a brute force solution, and it’s probably overkill, but it now works.

Backyard_Lights_Switch is a virtual on/off light switch.
Back_Patio-On_Motion-Timer is a 15 minute timer.
Back_Patio_Light_Switch is on a shared patio with Library_Patio_Light_Switch and not physically close to each other (unfortunately).

IF Back_Patio-Motion is Motion and, Time-of-Day is Dark, Backyard_Lights_Switch is not On, 
	do Back_Patio-On_Motion-Timer action "reset", 
	do Back_Patio-On_Motion-Timer action "start", 
	and set Backyard_Lights_Switch On to true.
IF Back_Patio-On_Motion-Timer is elapsed and, Backyard_Lights_Switch is On, 
	set Backyard_Lights_Switch On to false,
	and do Back_Patio-On_Motion-Timer action "reset".

IF Backyard_Lights_Switch is not On or, Library_Patio_Light is not on,	Back_Patio_Light_Switch is not on, 
	turn Back_Patio_Light_Switch off, 
	turn Library_Patio_Light off, 
	turn Bedroom_Patio_Light off, 
	do Back_Patio-On_Motion-Timer action "reset", 
	and set Backyard_Lights_Switch On to false.
IF Backyard_Lights_Switch is On or, Back_Patio_Light_Switch is on, Library_Patio_Light is on, 
	turn Back_Patio_Light_Switch on, 
	turn Library_Patio_Light on, 
	turn Bedroom_Patio_Light on, 
	and set Backyard_Lights_Switch On to true.

Thank you for the suggestions. It helped resolve my problem.