Ah…that’s different. I was assuming you would spend 15-30 minutes fading light on at sunrise, then leave it on all day and spend 15-30 minutes fading light at sunset.
What you want is max bright middle of the day and fade up to it starting at sunrise, then fade back down until sunset. Ignoring that you probably really want to quickly go up to around 50% bright after sunrise, then slowly increase until midday we will start on the problem…
You don’t really want to use fade & start/stop at sunrise/sunset. You want to set your brightness based on how far through the day we are, so we need to come up with some math that allows you to calculate a value between 0 & 1 based on how far we are through the day.
The first step is to determine if we are within day or night. Just set brightness to zero if we are outside of daytime. I’m going to assume hours for this example. Using time-of-day in minutes will give you better fade (it won’t jump to new value each hour), but this will make code a little easier & you can see the change if you change hour for testing.
When we are in daytime mode, we need to know how many hours are in the day so we can calculate how far we are through the day, so subtract sunrise from sunset time to get length of day (17-4=13 hours in your initial example). Now subtract sunrise time from current time to determine how far we are into the day (7-4=3). So we are 3 hours into a 13 hour day.
We get brighter until mid-day, then get dimmer, so we need to know mid-day. Since day is 13 hours, mid-day would be 13/2=6.5 hours. Current time divided by length of 1/2 day (3/6.5=0.46) can be used to set LED brightness. This works until we get to hour 7 (after mid-day) & 7/6.5=1.07, which is greater than 1, but we want to start getting dimmer after mid-day. One solution is to calculate brightness using current/mid-day (where current already has sunrise time subtracted from it), but subtract the result from 2 if value is >1. So before mid-day, LED is set to current/mid-day and we get brighter as we approach mid-day. Just after mid-day, calculated value is just over 1; subtract it from 2, and we get an LED value just under 1. As we approach sunset, calculated value approaches 2, and LED value approaches 0.
Assuming you can figure out the calculations, the divide in this example will be fed the current time (minus sunrise) on the left, and length of 1/2 day ( (sunset-sunrise)/2 ) on the right. You’ll need to add in additional code to make sure the LED is off at nighttime (an additional if-else between this if-else & led-LUM would be one option).