Automation for time on period

Currently I have 2 automations one for turning my Lights on at night and 1 for turning the lights off in the morning. This works ok…

What would be better is if I could have 1 automation that sets a On period (8pm-8am etc) for the lights and turns off when the period is complete. So if HA was to crash or have a power cut etc on recovery the automation would hopefully run and if the time is within the period turn on etc.

Is this possible?

That’s not the way automations work.

automations need a trigger. Triggers are discrete moments in time. Like at a certain time or an event like a HA restart. they don’t look for a certain time period and take actions based on that.

That said you could just add a HA restart event to your trigger and then put a time range condition (after and before the desired time range) in the list of conditions.

then if HA restarts during that time range then the automation actions run and place the lights in the correct state.