Have you noticed that the amount of sunlight visible X minutes before sunset seems quite different at various times throughout the year? For example, Sunset-20 seems much darker in the summer than in the winter.
I have come up with a math formula to automatically compensate for this. It ends up being a very simple formula, but does require the data stored in the @@dayLengthPercent variable above for it to work.
In the following example, at the summer solstice, the piston would trigger 60 minutes before sunset, and gradually shift over the next 6 months. By the time the winter solstice arrives, the piston would be firing 20 minutes before sunset. It would then spend the next 6 months slowly moving back in the other direction.
(the step-by-step guide below is so you can use numbers that work for you)
- First, you have to decide how many minutes before sunset you want your piston to trigger at the two solstices. (I am using 60 for the longestDayOffset, and 20 for the shortestDayOffset)
- Next, we subtract one from the other to find the difference. (60 - 20 = 40)
- Finally, we take 100 divided by the difference to find our multiplier. (100 / 40 = 2.5)
The formula for webCoRE would be:
round(-((@@dayLengthPercent / multiplier) + shortestDayOffset),0)
Or, using our example above, you can define a variable in the top section like this:
define integer sunsetOffset = round(-((@@dayLengthPercent / 2.5) + 20),0)
(Don’t forget to replace 2.5 and 20 with YOUR numbers)
and make the first line of code something like this:
Time happens daily at {sunsetOffset} minutes past {$sunset}
This piston idea works great for things like closing blinds, turning on evening lights, or anything else revolving around the time of sunset… I have been using this code for a couple months, and it works like a champ! (every couple of days, the offset shifts another minute)
SIDE NOTE:
This formula was designed to work with any two integers (whole numbers)…
The only restriction is the longestDayOffset (Summer) has to be greater than the shortestDayOffset (Winter).