Timer for switch if window is open and more

I have two ideas for apps that I would really like to use.

I have a fan in my window and would like it to turn on and off at specific times, if the window is open.

The other “problem” that I have is: Most of my lighting turns on at sunset if I’m home. If I get home after sunset, the lights obviously doesn’t turn on.
What I would like to see is an app that turns on lights at arrival, if it is after sunset.

If there is any way to currently do either of these, I apologize. Quite new with my ST.

Thanks in advance!

I solved the first one pretty easily.
I just added the app Smart Nightlight and made it turn on my lights for 999 minutes when it’s dark and movement in the hallway. That combined with Light Up the Night works beautifully!