Ran into a Logic Loop Between Two Switches

It is possible to create a loop between rules…ie

  • If device1 switches on, then switch device2 on.
  • If device2 switches on, then switch device1 on.

This makes the hub very unhappy - not sure what would happen if both devices are in the cloud

Use preconditions:

Device 2 is off
Device 1 turns on
Turn on device 2

If smart lighting is available in your region, you can use the mirror option depending on types of devices.

Some folks like to use virtual devices so that is a third option.


There was an outbreak of it with a popular workaround for STHM access that uses three virtual switches and six Routines. On the face of it the workaround defined infinite loops but in practice the fine technical details of the implementation meant they were prevented. Then the Routines were switched to the Rules API and nothing stopped the loops, apart from something somewhere terminating the loop after a significant number of iterations (can’t remember if it was 40 or 90 or if we even knew). It could also be done more generally with arrival and departure routines before preconditions came along, where no attempt was made to differentiate between someone leaving and someone arriving.

The irony of the situation was that back in time the Routines would not accept the same device in the condition and action and one of the reasons given was that they wanted to avoid users creating infinite loops. ‘We are not idiots, we wouldn’t do that’ said the community …

1 Like

Haha great stuff…

The fact that there is a ‘mostly invisible’ set of rules for SmartApps contributed to this

1 Like

There are multiple factors that complicate this as well.

Some light switch models have a “debounce” factor which means they won’t accept a turn on within less than a second of a turn off. So that can shield them against looping where a different model might.

1 Like