Problems with motion sensor smart app

I just added a FAQ (with pictures!) for using the Lights and Switches scheduler that’s built into the mobile app, but is pretty hard to find:

2 Likes

Having just implemented an app that does OP’s desired automation, I stumbled (again) into a problem that blows the automation sometimes. Unless you are using an instant reporting dimmer, there is a lag between turning on the physical switch and ST recognizing it. In OP’s case, turning on the switch is supposed to be an override of motion turning things on / off, and should set the lights to bright. The problem is that if motion is detected during this lag period, the automation will fail. The On event from the motion will be recognized BEFORE the physical switch on event. So picture turning on the switch and then walking into the kitchen – that takes a couple of seconds. Unlike the dimmer, the motion sensor reports instantly.

The switchOnHandler has to distinguish between motion turning on the light and the switch turning it on to implement the override. So when motion turns it on we can set a flag so that the On handler knows not to implement the override. Turning on a light with a setLevel (from motion active) causes the device type to throw an On event, so we have to be aware of that, hence the flag. Here is the bad sequence of events:

  1. Physical switch turned on, intending to override.
  2. Motion active turns on the switch (before ST has seen 1), sets the flag to prevent override.
  3. On handler turns the flag back off to allow override, not doing the override because motion turned it on.
  4. ST sees the physical on; the device type DOES NOT throw another ON event, because the light is already on.
    ==> FAIL

I do not know how to get around this problem other than by using an instant reporting dimmer. If anyone has any ideas, I’m all ears.

1 Like

Sorry, I’m confused, and that this was the sensor A in the garage sensor B in the laundry room use case. I thought you were separating the turn on and turn off logic. What’s the override flag for, who’s setting it, and who’s checking it when?

edited to add

Oh, wait, is this the sensor sets lights to 10%, switch sets lights to 100% request?

It’s a mesh network, even with instant status you can’t guarantee sequencing. Ever. If you have two switches controlling the same light you can’t be sure which instruction arrives first.

Instead, have motion sensor control LED strips above or below cabinets and let wall switch control main fixture.

Or

Yes, this is use the physical switch to “override” the motion sensors, and turn the room on bright, even if due to mode, the motion sensors would turn it on to low. You are correct, the problem is sequencing. The first level problem is non instant reporting switch, which potentially creates a huge lag (20 seconds or more?). The second level problem, as you point out, is a sequence of closely timed events even with the instant reporting switch, which is non-deterministic. Either way, a switch press during the lag period fails the automation. Switch press after the lag works fine. IF, the natural time interval from pressing the switch to triggering the motion sensors were long enough, say 5 seconds, and instant reporting dimmer was used, it would probably work fairly reliably. Shorten the time interval, all bets are off.

1 Like