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.
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
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.
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.
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.
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.
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!
@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.
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.