Challenged by time

As a Hubitat newbie I am in need of a bit of mentoring or inspiration.

I am trying to make a rule to handle a switch controlling the light in in my chicken coop.

I want the switch to be on between 7am and sunrise+45 minutes unless sunrise+45 minutes is before 7am.
I also want the switch to be on between sunset-45 minutes and 7pm unless sunset-45 minutes is after 7pm.
The rest of the time the switch should be off.

My challenge is that I cannot find out how to compare two different timestamps.

Any help will be greatly appreciated

Just do both. :smiley:

Turn it on at 7 and then turn it on at sunrise+45

Which ever occurs first will work and then a 2nd turn on to an already turned on light will occur. Unlike Star Trek, that won't cause the switch to blow up :smiley:

1 Like

No - I don't think this is correct.

@user1270 wants the light to be on between 7 AM and sunrise+45.

If sunrise+45 is before 7AM, they don't want the light to turn on, because it is already bright enough.

1 Like

I want the light turn on at 7am and off at sunrise+45.

However being far up the northern hemisphere sunrise+45 will be around 9:15am at this time of year but in the summer sunrise+45 can be at 4am. So if sunrise+45 falls before 7am I don't want to turn the light on at all.

1 Like

Sorry, I saw the Sunset portion of the question and interpreted it as you wanting it to be On a LOT. :slight_smile:

There is a way to do that by date I believe. It was a long time ago but I think Bruce detailed it in a response to someone. It has something to do with checking sunrise/sunset times for your location and setting a date according to the offset so that it can't trigger if sunrise plus 45 is before 7AM. I know that's not much help without a link to the post I'm referring to, but perhaps someone will recall it.

2 Likes

@user1270

Do you use NodeRED? I know how to do this in NodeRED, but I can't figure out how to do it in RM. Also, if you're coming from SmartThings, and previously had this working in webCoRE, webCoRE is now a built-in app - so you can reuse your old (working) piston.

1 Like

No, I am not using NodeRed and would rather avoid having to do so. Also I am not migrating from ST, but eagerly awaiting the release of the built-in webCoRE. :slight_smile:

1 Like

I think you can use basic rule with something like this ?

2 Likes

The problem with that is that if sunrise+45 is before 7 am, then the light is going to turn on at 7 am and stay on until sunrise+45 the next morning.

  1. Make two hub variables of type DateTime. Set them to whatever for default.
    image
  2. Create a rule to update the variables each day.
    image
  3. Create one rule for morning.
    image
  4. And another for evening
    image
3 Likes

I think you would do it as two rules one for sunrise, one for sunset.

Check sunrise/sunset times on timeanddate.com for your location. Find the dates when sunrise plus 45 is before 7AM. Then set your required expression for between two dates and set those dates so that the rule can only trigger on dates when sunrise plus 45 is after 7AM. Do the same for the sunset rule.

Edit: Ignore the above @anon47916022 solution is far easier!

Even with the restriction between 2am and sunrise?

2 Likes

Nope...you're right. I don't use Basic Rules so I completely missed the restriction statement.

Ha...and that solution is WAAAAYYYY simpler than the around the elbow route I took.

1 Like

Here's an option

Define Required Expression
Time between 2:00 AM and Sunrise+45 minutes

Select Trigger Events
When time is 7:00 AM

If Sunrise+45 minutes is before 7:00 AM the rule won't trigger.

2 Likes

@user1270 if you choose to use my suggestion, there is something that you need to consider. If sunrise+45 is 7:01, do you really want the light to be on for only 1 minute? I think anything less than 5 then I'm not turning on the light. If you're using a Wait command to turn off the light at sunrise+45 then when sunrise+45 is 7:00 you'll miss the wait and the light will stay on until the next morning.

For the light to stay on at lease 5 minutes, I would suggest modifying the Required Expression to:

Required Expression
Time between 2:00 AM and Sunrise+40 minutes.

Then turn off the light at sunrise+45

If you're okay with the light only being on for 1 minute then you can keep the Required Expression as sunrise+45 but I would suggest the actions as

Selection Actions to Run
On: Light
Wait for events: When time is Sunrise+45 OR When time is Sunrise+46 minutes
Off: Light

This will catch the sunrise+45 = 7:00 AM case and turn off the light at 7:01.

2 Likes

The problem with this is that you may be overlapping at some point when sunrise+45 is past 7:00am. You should do a required expresion of 7:am or sunrise+45 then set another seperate rule to turn off.

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