Calculate current light state on connection or power restore

We live in the country and suffer the occasional power outage, particularly during the winter months. What I would like to be able to do for some devices is to devise an automation that will set the correct state for the lights. I don’t want to restore to off or on or the last state. I would like the automation to detect that HA has just started or a device has gone from being unconnected/unavailable to being connected/available and then calculate and set the state to what is should be at that time.

I have some that can be set on or off based on the light level detected from the weather station but others have scheduled on/off times.

Bonus points to consider/remember that a light had been manually turned off early in it’s on time and restore that if power was restored before it’s timed off time.

Does this all make sense to anyone other than me?