Select Actions for Front Foyer Light turn on with motion and off after 2 min but stay on if dimmer is changed

Having problems trying to get this to work. Want light to turn on with motion and shut off after 2 minutes unless the dimmer is changed from 40. Below is the 4.0 rule....

Select Actions for Front Foyer Light turn on with motion and off after 2 min
IF (Front Door Motion active(F) AND
Front Foyer Light(off) is off(T) AND
Time between Sunset and Sunrise(T) [FALSE]) THEN
Dim: Front Foyer Light: 40
On: Front Foyer Light
Delay 0:01:50
Refresh: Front Foyer Light
IF (Dimmer level of Front Foyer Light(67) is = 40(F) [FALSE]) THEN
Off: Front Foyer Light --> delayed: 0:00:10
END-IF
END-IF

What you have looks mostly good, except we can't see your triggers so we'll never know when these actions actually run. I'll assume you have "Front Door Motion changed" as your trigger; if not, that looks like what you would want here.

There is a likely problem, however. What you have should work, except it's unlikely you want your lights to turn off two minutes after motion starts. You probably want them to turn off two minutes after motion stops. There is a basic motion lighting example in the Rule 4.0 docs, which I highly recommend you'd read before attempting anything. This example doesn't do all what you want, but it's the basic structure you need. You can add your extra logic to get something like this:

IF (Front Door Motion Active) THEN
  Cancel Delayed Actions
  IF (Front Foyer Light is off AND Time Between Sunset and Sunrise) THEN
    Dim: Front Foyer Light: 40
  END-IF
ELSE
  Delay: 00:02:00 (cancel)
  /* most bulbs won't need a refresh but I assume you have that in your rule for a reason, so if yours do maybe put that here and add a small delay after if you need that too, shortening the one before to compensate if desired) */
  IF (Dimmer Level of Front Foyer Light is = 40) THEN
    Off: Front Foyer Light
  END-IF
END-IF

As-is, this would only turn the bulb on between sunset and sunrise but would turn it off any time the leve is 40 outside of those conditions, too. This is what I'd want personally, but if you only want it to turn off between sunset and sunrise you could add that to the last IF or wherever works for you. Or if you want it to turn off outside of those conditions but only if this rule turned it on in the fist place, you could use something like Private Boolean to keep track of that (say, set it true when this rule turns on the light and false when it gets turned off by this rule). Finally, I assume you know the idiosyncracies of whatever bulb you're using (that you really need that refresh and that it will report exactly 40% if set to 40%), but if not, you may wish to test that.

Good luck!

1 Like

Trigger is : Front Door Motion active

Ok so this is what the code looks like now. It seems to be working but the if statement IF (=Dimmer level of Front Foyer Light(40) is = 40(T) [TRUE]) THEN, should turn off light, but the switch/dimmer was changed to 80, so 80 != 40 so it should not turn off light. Is this a bug that it's not updating the code in Select actions to run?

IF (Front Door Motion active(F) [FALSE]) THEN
	Cancel Delayed Actions
	IF (Front Foyer Light(on) is off(F)  AND 
	Time between Sunset and Sunrise(T) [FALSE]) THEN
		Dim: Front Foyer Light: 40
		On: Front Foyer Light
	END-IF
ELSE
	Delay 0:02:00
	IF (Dimmer level of Front Foyer **Light(40)** is = 40(T) [TRUE]) THEN
		Off: Front Foyer Light
	END-IF
END-IF

Your trigger needs to be "changed," but if it's turning off I'm guessing you fixed that already. The problem with your rule is that you didnt' set the "Cancel" flag on your delay, so your "Cancel Delayed Actions" action (which cancels anything pending that has this flag set) doesn't do anything; thus your lights will always turn off.

1 Like