Help with flow around sunrise

I have built a flow for a motion sensor and part of it is to turn on lights when someone goes down the stairs in the morning. I have it set so that the lights come on if the sensor is activated between 06:00 and sunrise + x minutes. This worked fine when the sun rose after 06:00 but when sunrise is before 06:00 this breaks and the time range is from 06:00 to sunrise the following day.

Please could someone help me with a way to account for this in the flow so that the when sunrise + x minutes is before 06:00 then the flow works properly?

The flow is as follows:

[{"id":"8f4879fb.49f7c8","type":"time-range-switch","z":"426f7057.3f65","name":"06:00 - sunrise + 44","lat":"52.2566","lon":"0.0705","startTime":"06:00","endTime":"sunrise","startOffset":0,"endOffset":"44","x":740,"y":1320,"wires":[["d0939ea3.c5d8a"],[]]},{"id":"d80f7e0a.c63cb","type":"link out","z":"426f7057.3f65","name":"link from stairs motion sensor","links":["76277dab.c2a7b4"],"x":1095,"y":1320,"wires":[]},{"id":"d0939ea3.c5d8a","type":"api-call-service","z":"426f7057.3f65","name":"set stairs sensor","server":"5a2e6e11.51fca8","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.stairs_sensor","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":960,"y":1320,"wires":[["d80f7e0a.c63cb"]]},{"id":"8ef58a72.e32628","type":"api-current-state","z":"426f7057.3f65","name":"is it cloudy?","server":"5a2e6e11.51fca8","version":1,"outputs":2,"halt_if":"cloudy","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"weather.home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":530,"y":1320,"wires":[["8f4879fb.49f7c8"],["f9357042.3de84"]]},{"id":"f9357042.3de84","type":"api-current-state","z":"426f7057.3f65","name":"is it rainy?","server":"5a2e6e11.51fca8","version":1,"outputs":2,"halt_if":"rainy","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"weather.home","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":520,"y":1380,"wires":[["8f4879fb.49f7c8"],["787dddb8.44d664"]]},{"id":"787dddb8.44d664","type":"time-range-switch","z":"426f7057.3f65","name":"06:00 - sunrise + 29","lat":"52.2566","lon":"0.0705","startTime":"06:00","endTime":"sunrise","startOffset":0,"endOffset":"29","x":740,"y":1380,"wires":[["d0939ea3.c5d8a"],[]]},{"id":"5a2e6e11.51fca8","type":"server","z":"","name":"Home Assistant","legacy":false,"addon":false,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Thanks

If you want a time before 6:00 hr why not start the node earlier?
and make it for example sunrise as start? and ending sunrise +x time?

Because in the winter months when sunrise can be as late as 08:00 the lights wouldn’t come on at the right brightness level when someone gets up at 06:00

In that case, maybe you can do a sunrise check every day at around 01:00 for the day, and then save this value. Simply refer to this saved value (adjusted to your needs i.e. +45min) then in your flow.

I have temporarily fixed the flow by inserting checks on whether the sun has risen or not (using sun.sun) and changing the responses within different time ranges accordingly but this has made the flow much more complicated.

I had considered getting the sunrise time from somewhere and using it in the flow but I don’t have the knowledge to make that work. My other problem was where to get the sunrise time from, I could use the Dark Sky Sunrise 0d sensor but given the news this week about the closure of the Dark Sky API I would rather not put in something that’s not going to be permanent (as permanent as anything gets anyway). After some online searching I have found this https://notenoughtech.com/home-automation/nodered-home-automation/nodered-sun-and-time/ which will do the job perfectly but I don’t know how to take the output and work it into the flow to make it useful. If you are able to help at all I would be really grateful.