Motion / Turn off the lights time out based on virtual switch on /off

Hello Community!!

I can't figure how to do this rule properly. What I am trying to achieve is if any of my daughters are at home, the guest bathroom light doesn't turn for 30min after motion has stopped. If they are all away then turn off the light when no motion.

I have a virtual switch to turns on if any my daughters are home and the virtual switch turns off when they are all away. I used switches incase I want to rename the switch or use it when I have guest.

Guest Bathroom Motion motion active

Dim: Guest bathroom light: 45
IF (VSwitch Nina or Alexa at home(on) is off(F) [FALSE]) THEN
Wait for event: Guest Bathroom Motion motion inactive
Off: Guest bathroom light
IF (VSwitch Nina or Alexa at home(on) is on(T) [TRUE]) THEN
Wait for event: Guest Bathroom Motion motion inactive
Off: Guest bathroom light --> delayed: 0:01:00
END-IF

I likely have it setup completely wrong =).

The delay is probably your issue. Once a delay is started unless cancellable the light will get turned off after an hour

Try wait for event and stays, if you edit the wait event there is a slider "and stays" turn that on. Also remove the delay from the second IF. Then if the motion goes active the rule gets retriggered and the wait is canceled.

2 Likes

This should be an ELSE-IF, not an IF. Otherwise, you're embedding this IF inside your first one. The editor would also display this as indented further to help show this. If this was a typo in the post maybe share a screenshot of the rule instead?

I don't see any delays in this rule, only "Wait for event: elapsed time," which is similar to a delay but automatically canceled on re-trigger, so that shouldn't be a problem.

1 Like

I missed it the first read through as well.

1 Like

Ah yeah, that could do it! Though if how it's written is really as above, I guess that line will never be reached anyway, so not a problem for now. :joy: (But something to look at after!)

2 Likes

Thank you. I'm all confused. Could you show me how it should look like?

This is what I have now and it seems to work except it doesn't start the timer over with motion actives again. I do have the cancelable on.

Dim: Guest bathroom light: 45
IF (VSwitch Nina or Alexa at home(on) is off(F) [FALSE]) THEN
Wait for event: Guest Bathroom Motion motion inactive
Off: Guest bathroom light
ELSE-IF (VSwitch Nina or Alexa at home(on) is on(T) [TRUE]) THEN
Wait for event: Guest Bathroom Motion motion inactive
Off: Guest bathroom light --> delayed: 0:01:00(cancelable)
END-IF

A cancelable action has to be cancelled explicitly. So, you would want your first action to be "cancel delayed actions" or, you can do what I wrote below. The wait action is auto-cancelled anytime the rule is re-triggered.

Trigger: Guest Bathroom Motion active
Actions:
Dim: Light: 45
IF (VSwitch is OFF) THEN
	Wait for event: Motion inactive
	Off: Light
	ELSE-IF (VSwitch is ON) THEN
		Wait Event: Guest Bathroom motion inactive and stays that way for: 0:01:00
		OFF: Light
	END-IF
END-IF
2 Likes

Thank you, I'll try it and send an update.

1 Like

You'd actually want something like this for the actions--no extra level of nesting, though the editor wouldn't quite let you do the above anyway:

IF (VSwitch is OFF) THEN
	Wait for event: Motion inactive
	Off: Light
ELSE-IF (VSwitch is ON) THEN
	Wait Event: Guest Bathroom motion inactive and stays that way for: 0:01:00
	Off: Light
END-IF

Thinking about this more, you could also just use ELSE instead of ELSE-IF, since a switch can only have two states, and there's no need to explicitly test for the other possibility.

3 Likes

Since Off is common to both scenarios, you could simplify even more.

IF (VSwitch is OFF) THEN
	Wait for event: Motion inactive
ELSE
	Wait Event: Guest Bathroom motion inactive and stays that way for: 0:01:00
END-IF
Off: Light
4 Likes

I went with Fredcheese2006... Thank you! I applied the changes before anyone else respond. It worked exactly as I wanted with the VSwitches in place.

Interesting: In edit mode, it showed off on both IF Then. I pasted the screen shot.

Here's the rules I went with:

Note: 2nd END-IF not needed. Also it was not an option to add another END-IF. Also I change the 45sec to 30min. lol

1 Like

As long as you got to a working solution, that's what ultimately matters.

1 Like

Actually, there is no reason to check the value of VSwitch a second time because if it's not OFF then you've already determined that it is ON. Replace the ELSE-IF with an ELSE and remove the "THEN".

1 Like

Yes, this is what I meant when I said:

1 Like

I think I get it? Like this?

On: Guest bathroom light
IF (VSwitch Nina or Alexa at home(off) is off(T) [TRUE]) THEN
Wait for event: Guest Bathroom Motion motion inactive
Off: Guest bathroom light
ELSE Wait for event: Guest Bathroom Motion motion inactive and stays that way for: 0:30:00
Off: Guest bathroom light
END-IF

1 Like

Yes--but what you have is logically equivalent, and there is no need to change if you do not want to. Just a tip that could save a couple clicks. :slight_smile:

1 Like

Or an equivalent rule in 4 lines...

On: Guest bathroom light
Wait for event: Guest Bathroom Motion motion inactive
IF (VSwitch Nina or Alexa at home is on) Wait for event: duration: 0:30:00
Off: Guest bathroom light

Note that the IF is a simple condition and therefore no THEN or END-IF.

There are many ways to achieve the same results. The most important thing is that whatever rule you use, you understand how it works and can debug if a problem arises later.

3 Likes

The shorter the better and more easier to understand :slight_smile:

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