How to create a trigger that only occurs from 10pm to 12pm

I know how to do triggers that occur at say 4pm everyday. I got many of these types.

Done it via Certain Time option

But I want to create time slot triggers.

Scenario - between 10pm to 12pm, check sensor status, if opened, then do an action.

I can do the actions part, i just dont know how to create the time slot triggers

Tried this. Didn't work.

Any ideas?

Use the Required Expression option. That's where you put the condition of 10pm to 12pm (did you mean for 2 hours at night? if so, 12am).

And you need a trigger. Such as 'sensor opens'. Like this

i did it this way and it works.

used conditional triggers. Powerful stuff.

Yeah, that's good.

whats the difference between Conditional Trigger and Required Expression? seem to achieve the same thing?

They have different underlying implementations with subtle differences. They have the same intent, to only trigger under one or more conditions. That's the first difference right there, a Conditional Trigger has a single condition, not an expression. An expression is made up of conditions, operators like AND, OR, etc, and parentheses for grouping the logic.

The underlying differences make Required Expression more efficient in some cases. With Required Expression, when it becomes false, all of the rule's triggers are removed, until it becomes true, and then they are reestablished. For the duration of the falseness of the Required Expression, the rule is dormant. For example, I have a rule that's dormant from mid August to mid April the next year. Only an entry in my hub's schedule provides for a future instantiation of the rule. That entry came from a Between Two Dates condition in the rule's Required Expression.

A Conditional Trigger will actually wake up the rule for each trigger-possible event, where the first thing the rule does is check the condition. If the condition is false, the rule exits; otherwise it triggers.

A Required Expression is needed for complex conditions (more than a single condition), or situations where it is desirable to drop the trigger subscriptions during falsehood. For simple cases with a single condition, a Conditional Trigger will be better as it avoids the de-subscribe/re-subscribe of a Required Expression.

5 Likes

They will effectively do the same thing but you can also use them together. When used together you can define the conditional triggers and the required expressions basically saying "the triggers will only fire if these conditions are met, however these other conditions must be met for the triggers to evaluate and fire". There are some cases this is needed. I attached a screenshot of a rule I have using both.

ooo so Required expression is more a super user one. Nice!
Thanks for that explanation @bravenel and @LearningHubitat :sunglasses:

1 Like

i have a WHILE loop created and it works. Wanted to run it by you guys if it's efficient.

ACTIONS
say "door is open"
WHILE door sensor is open, repeat 30 times every 20 seconds
say "door is still open"
END-REP
say "door is now closed"

this good yea?

I have never set a rule up like that. This is teaching me something. I am looking forward to the more experienced members input.

What I would do is create a hub boolean variable and rule that is sets it to true at 10PM. At 12AM (or PM as you stated) another rule sets it is set to false. Actually your rule has a required expression of variable = TRUE. The trigger is just your sensor == open.
Since the variable is false outside of your time window nothing happens when the sensor is open.

1 Like

yea that trigger part i can do several ways,

What about this while loop actions part. Only this way to do it yea?

ACTIONS
say "door is open"
WHILE door sensor is open, repeat 30 times every 20 seconds
say "door is still open"
END-REP
say "door is now closed"

and how do i break out a while loop without waiting that 20 seconds?

like right now, when door is opened for 20 seconds, it'll say "door is open", wait 20 seconds, it will say "door is still open", i close the door, after 20 seconds it will say "door is now closed".

I dont want the 20 seconds wait after that door is closed to say "door is now closed".
as soon as door is closed, i want the WHILE loop to end.

How do i do that?

i think maybe this hack method might work?

edit the actions to this. add a variable GarageRuleInAction

ACTIONS
say "door is open"
set GarageRuleInAction = true
WHILE door sensor is open, repeat 30 times every 20 seconds
say "door is still open"
END-REP

create another rule that checks for GarageRuleInAction = true, and garage contact sensor = closed, and then say " garage door now closed". Then sets GarageRuleInAction = false.

Reason for having a separate rule for this closed part, is so the "garage door now closed" will be instant. That will work i guess. But maybe not a clean solution.

why does variable checking work in Triggers but not in Required Expression?

I flick the boolean GarageRuleInAction manually via device details page.

This rule below does not work.

but when i put the boolean check in the trigger, it works. See below.

Why is that?

i think maybe a bug that variables on its own cant be used in Required expression. Because using any other expression like time works.

Either way. i got it working.

Required expression
variable AND time between 6pm and 9 pm

Trigger
Door closed

works really good love it!

I think your 1st example needs a trigger

1 Like

i did this and it doesn't work. What i found is that the trigger event HAS to occur during the 10pm to 12am time frame for the actions to occur.

So if my windows are already open before 10 pm. and then time becomes 10pm, the actions do NOT occur.

How do I make it so actions fire even when the contact sensors are already open BEFORE the required expression is true? Been banging my head at this for a while now.

@Johnnyvaneddie @kanewolf @LearningHubitat @bravenel @johnwill1 @danabw

Perhaps trigger on 10 pm and contact open, or have a second rule trigger at 10 PM, then Run Actions of this original rule if contact open.

would that pick up if the contact was already open before 10pm?