Turn on lights once per morning

Hi, can you help me fix this rule. The objective is to fade on the kitchen cabinet lights once in the morning when motion is first detected. A second motion should not activate the rule.

This rule uses a Private Boolean to prevent second triggers from activating the rule.

I think the problem is in the wait time being outside the conditional time rage, but I think the condition should only limit when the action is triggered not when a triggered event actually occurs.

Here is the rule. The problem is that the Private Boolean isn’t flipping back to TRUE


IF (Time between 5:00 AM EST and 8:00 AM EST(F) AND
Private Boolean is true(F) [FALSE]) THEN
Set Private Boolean False
Dim: Sink Cabinet Lights, Stove Cabinet Lights: 10 --> fade: 0
Fade Sink Cabinet Lights, Stove Cabinet Lights up to 80 over 30 minutes with 60.0 seconds interval
Wait for event: When time is 8:01 AM EST
Set Private Boolean True
END-IF


Hi there,

You could try something like this;

IF (Time between 05:00 and 08:00  AND  Private Boolean is false) THEN
	Set Private Boolean True
	Fade closet (ct) up to 80 over 30 minutes with 60.0 seconds interval
ELSE-IF (NOT Time between 05:00 and 08:00  AND  Private Boolean is true) THEN
	Set Private Boolean False
END-IF

Rather than an ELSE-IF, which would rely on the rule being triggered a second time in the 5-8 timeframe, what if you close off the IF after turning on the lights and put a delayed action to set the private boolean to false? E.g.

IF (Time between 5 - 8am and Private Boolean is false) THEN
  Set Private Boolean True
  Fade closet (ct) up to 80 over 30 minutes with 60.0 seconds interval
END-IF
Set Private Boolean False (delay 3 hours)

EDIT: Actually that is essentially what is in the original post.... Hmmm..

@Brian123 - Is the private boolean not being set back only when motion occurs after 7:30am, or always? Reason being, I would expect the rule to only move on to the Wait for event.... action when the fading of the lights for 30 minutes completes, so if motion occurs at 7:45am you would be past 8:01am before starting to wait for it.

Simon

The ELSE IF triggers when that is true, which does not have to be within the time frame... Or do I miss something? It just says time should be anything but the time frame, plus PB should be set...

Edit: Just read your line about triggered a second time, missed that, sorry.

1 Like

You are correct, I should have read it more closely. It would only be the very rare chance of not triggering it again outside of the 5-8 timeframe which would mean the boolean is not reset. So in reality either option would work, including the one you put forward.

1 Like

Call it a draw.... :slight_smile:

1 Like

Hi sburke781, typically the motion trigger happens at 6AM and I’ve confirmed that the PB flips to FALSE. That would leave plenty of time for the 30min FADE before the action at 8:01AM to set the PB to TRUE. Do you think the action at 8:01AM isn’t happening because of the condition in the IF statement that limits the action to between 5-8AM? If so is that how you’d expect the logic to behave?

I came up with that logic expecting that the triggered chain of events would execute as long as the trigger happened while the conditions were true.

Thanks for your help!

1 Like

Shame, recommending you get up earlier is taken off the table.... :slight_smile:

I would expect the actions to happen in sequence and so expect your version of the rule to work. Only suggestion I can make is to try the couple of variations @furom and I suggested to try and zero in on where the issue may be. Apart from a few slight tweaks to the IF-THEN-ELSE setup we came up with, the other adjustment we suggested was to use a delay. I didn't suggest that with any knowledge of any issue with the wait for event, mostly because I had used the delays myself.

See how you go.

Simon

1 Like

What is likely happening is the rule is being trigger again. This will cancel the wait and not execute any subsequent action. Since the PB in now false, the condition fails and the wait for 8:01 isn't rescheduled.

1 Like

Looks like you are right @pseudonym. The last paragraph in Bruce's post below confirms that the waits are cancelled, unless something has changed in the meantime.

I have a similar requirement. I set a PB to "true" when the lights go on in the AM. In the same IF statement I check for PB to be "false" else it won't complete execution.

The set the PB "false" at 1 AM (or whatever time you think is the next day.

@JohnRob, how does your rule set the PB to false at 1AM?

@pseudonym, does the IF condition being false prevent the trigger from affecting the actions inside the IF statement?

Why aren't you just using a virtual switch for this, instead of of PB? As long as the switch is on, the motion sensor can trigger your routine. As endpart of the routine, the switch is toggled off and turned back on at a specific time.

Let me see if this answers your question. Re-triggering a rule creates another instance of the rule actions. Any Wait from a previous instance will be canceled. It doesn't matter if that Wait was part of an IF condition that is false during the re-trigger.

@pseudonym, yes, thanks, I now see how that behavior of WAIT in rule machine works. I guess that was not how I expected it to work.

Does that also mean that the FADE action gets canceled?

Is there a recommended rule that could achieve the same effect?

Thanks for your help!

Brian

Simple,

Trigger:
"time = 1:00AM"

Actions with conditions:
IF (if time = 1:00 am) THEN
set PB to false

only difference is that the virtual switch creates a device, otherwise the functionality is the same as the private boolean. Flipping the switch is the same as setting the boolean to true/false

1 Like

Ok, I've learned something new. :smiley:

@pseudonym, I accidentally addressed this question to the wrong person before.

In the same way that the WAIT action gets canceled, does the FADE action also get cancelled?

Thanks!

Download the Hubitat app