How to: Do something at Sunrise or 7AM whichever is later?

There will be a better solution than this, but you could setup a rule that is triggered at either 7am or sunrise, which sets the private Boolean and/or a hub variable, with a required expression that the private Boolean is false. Then in a second rule do the actions you want. You will likely want something to run overnight to reset the private boolean. Luke I said, not as near as solution as others are likely to come up with.

Edit - I could have that logic round the wrong way.... Been a long day.... :slightly_smiling_face: Hopefully you get the idea.

I think I get it. Probably have to set the boolean a minute earlier than the trigger time to make sure it's set. Thanks. Unless someone has a simpler idea I will code this up.

1 Like

Room Lights allows you to specify « later of two times » for a time period. That’s what I use.

But to open a curtain I have to operate an actuator, not turn on or off lights. I didn't see how I would do that. Plus, going in to room lighting reminded me why I don't use it, super overly complicated. I do appreciate the attempt to help me though.

1 Like

In my case the blind driver exposes a Window Shade capability, which Room Lights can handle directly.

I thought so too at first but persisted and now I am really enjoying all the possibilities.

Here's a way to achieve what you want I RM (didn't test)

2 Likes

Idea if you want to live in a single rule:

Have a rule with both triggers and a variable that counts up on each event. On one, do nothing. On two, take action and then reset your counter.

Once that falls out of sync, it will stay out of sync... Perhaps another trigger to reset it every day if you want it to self heal after a power cut kind of scenario.

This approach failed this morning because it opened the curtain at 7am - instead of waiting for sunrise.

This seems doable. Second try for tomorrow will be this approach if I can actually put it into a rule.

There is a way to do this but I've previously looked for the post where it was detailed and can't locate it. The answer came from either bobbyD or bravenel but it was probably two years ago shortly after I first started with Hubitat.

IIRC it revolved around looking at the tables for sunrise/sunset for your specific location. There's a way to specify a date that gets used in the rule, that will allow this to work. Apologies as this is so vague, I'll try and locate the post/solution again. I could do with finding it, as I need to use similar to ensure my curtains don't close too early in the winter.

I posted a feature request for RM a while back asking for this but didn't get any responses.

Find the earliest sunrise for the year in your location, then:

Rule 1
Trigger:

  • certain time (set before earliest possible sunrise)

Actions:

  • Set Hub Variable False
  • Wait until 7AM
  • Set Hub Variable True

Rule 2
Trigger:

  • Sunrise

Actions:

  • Wait for expression (not event) Hub Variable True
  • open curtains

At sunrise if it's not yet 7AM the Hub Variable will be false and the rule will wait until it's true before opening the curtains. However if sunrise is after 7AM the rule will trigger and say 'expression already true' and open the curtains immediately

1 Like

Might make sense as a trigger, but not sure about a conditional expression. What would that look like ? What’s the use case? (Just curious)

Something like this should do it:

Triggers on either, but only acts if both are true.

4 Likes

I think this is the winner. I was able to easily code this just now. We'll see how it performs tomorrow morning, but this is simple and elegant. Thanks @johnwill1. And thanks to all that weighed in. I'll mark this as the solution when it works tomorrow.

Plus

2 Likes

Yeah good idea, gets rid of the local variable.

Updated my example with your idea (both work essentially the same way):

1 Like

I'm a little bit late to the party, but there is an even easier way to do later of two times (or earlier).

The above does an earlier of two times within Rule Machine. To do a later of two times, keep the structure the same except, but move the actions to the Else. It would be:

If Boolean true, set Boolean False
Else, Actions and set Boolean True

1 Like

Here's an option that will trigger at the later of sunrise and 7:00 AM

Trigger Events
When time is Sunrise - ONLY IF(Time between 7:00 AM and 12:00 PM)
OR
When time is 7:00 AM - ONLY IF(time between Sunrise and 12:00 PM)

You may get both to trigger when sunrise is 7:00 AM but I don't believe sending the curtain open command twice should be a problem.

3 Likes

Winner winner chicken dinner. Clever... :+1:

1 Like

Nice ...

Worked great. There might be more clever solutions, but I understood this one, was easy to code, and works.

2 Likes