Trigger whichever is the latter

Hi guys, with Rule Machine, how do I get a rule to trigger at different times depending on what time it is.

So basically, I want a light to turn on at Sunset or 20:50, which ever is the latter. Then I want to wait until sunrise or 08:00 which ever is the earlier to turn the light off. I'm having writers block on this one.

Appreciated in advance

You can do it with Modes pretty easily since it is built in. This is how I have been doing it. Then trigger rules from the modes.

I think you can also do it in Room Lighting using custom "Time Periods" if you dont want to mess with modes.

Odd that the "earlier of" or "later of" isn't available on RM. Thanks though :+1:

You'll need two different rules, but it can be done in Rule Machine using the Private Boolean.

Triggers
Sunset
20:50

Actions
If Private Boolean is true,
Set Private Boolean False
Else,
Turn on Light
Set Private Boolean True
End-IF

Basically, the first trigger will set the Private Boolean to False and do nothing else. When the second trigger happens, it will start with the Else since the Boolean is False, turn on the light, and reset the rule for the next day by turning the Boolean true.

Same as above, but moving the actions under the IF instead of the Else.

Triggers
Sunrise
8:00

Actions
If PB is true,
Set PB False
Turn off Light
Else
Set PB True
End-IF

2 Likes

Here's a suggestion for a single RM rule.

Required Expression
Private Boolean is true

Trigger Events
When time is Sunset
OR
When time is 20:50

Actions to Run
Set Private Boolean False
Set SunsetVar to sunset time
IF (NOT Variable SunsetVar = 20:50) THEN
    Wait for events: When time is Sunset
        OR When time is 20:50
END-IF
On: Light
Wait for events: When time is Sunrise
  OR When time is 8:00 AM
Off: Light
Set Private Boolean True

Local Variable
SunsetVar    DateTime

The SunsetVar and IF-THEN take care of the case when sunset = 20:50.

3 Likes

Thanks for this but I don't think it will work. Taking your first rule in the winter it may trigger at sunset which could be 17:00 but I want no earlier than 20:50

Thanks for this. I think looking at this rule. If it triggers at 20:50 but sunset is 21:30 (for example) then the light will come on at 20:50 rather than waiting until sunset. Do no you agree?

However if sunset is before 20:50 then it will wait until 20:50. I know this rule is close but I don't think it's quite there. It's mashing my head.:scream_cat:

Or does sunset look at the time down to the second. If it does, I think you're right and this will work. I assumed sunset was just HH:MM Rather than HH:MM:SS

If it triggers at 20:50 and sunset is 21:30, it'll check to see if sunset does not = 20:50. It'll pass that check so it will proceed to the Wait for the event sunset or 20:50. Since 20:50 already occurred the Wait will be satisfied at 21:30.

1 Like

So when waiting for 20:50, is the rule actually waiting until 20:50:00?

I assumed any time between 20:50:00 until 20:50:59 would be considered to be true? Appreciate you help

An event is an instantaneous occurrence. When time goes from 20:49.999 to 20:50.000 the event happens (or within milliseconds of that change). The next occurrence of that event won't happen until the next day. What your referencing here appear to be the condition applied to a certain time.

IF (time is 20:50) is evaluated as true between 20:50.000 and 20:50.999.

The rule should work as expected.

1 Like

Marvellous bit of insight. Really appreciate your help on this one

1 Like

@pseudonym is amazeballs at rule-building wizardry. I bookmark just about every suggestion he makes in posts like this, since his recommendations are always both staunch and efficient :+1:

1 Like

Room Lights:
The way this works is you set two time periods, one will trigger lights on, other will trigger off. For the "Off" period, you set the activation to actually turn the light off. It seems counter-intuitive but this was how RL was designed. Think of it like activating a "Scene", and in the OFF scene we want to lights off!

This RL will ALWAYS be "active", and the "Adjust Lights at Time Period Changes" will force it to adjust everything to current settings when the period changes over. I use this in my Kitchen to adjust the light level throughout the day and it works amazing.

Click where the arrow points to open the time period settings

Set up Like this:

1 Like

It would still work regardless of season. In the winter, for a sunset at 17:00, the rule would set the PB false at 17:00 and turn the light on at 20:50. In the summer, for a sunset at 22:00, the rule would set the PB false at 20:50 and turn the light on at 22:00.

1 Like

Pseudonym is nothing short of genius. I wouldn't have worked that rule out in a million years. The request seemed simple, the logic partially simple but mind bending. Thank you @pseudonym

1 Like

Hi @bravenel , could we request that you bring the "earlier of" and "later of" into rule machine please. Appreciated :+1:

@stueyhughes @hydro311 :joy: Thanks, guys. I'm glad that you find my suggestions helpful!

2 Likes

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