Turn off light if its on beyond 10 PM multiple times a day

I have a peculiar problem. Power outage is frequent in my area but lasts very few mins. This creates a probe for Tuya lights. Whenever power comes back Tuya lights automatically turn on. I have an automation that turns on lights at 6PM and turns them off at 10 PM. But because of power outage I see these lights on at random times.

I can not use the state automation because the light is already on by the time device connects to the network and HomeAssisatnt boots.

I want automation that forces these lights of beyond 10 PM. How can I do this?

You could have a time pattern trigger, every 5 minutes (say), that turns off all the lights

automation:
- alias: "Darkness rules"
  trigger:
  - platform: time_pattern
    minutes: "/5"
  condition:
  - condition: time
    after: "22:00:00"
    before: "06:00:00"
  action:
  - service: light.turn_off
    entity_id: all

Couldn’t you just set them to a desired default when HA starts:

I’m not sure there is anything that can be done in HA to prevent the lights coming on automatically on a restoration of power. that is probably a function of the light. I have zwave and zigbee bulbs that do the same. If power is turned off to them and then turned back on they will come on by themselves.

Maybe there is a setting in Tuya to change that behavior?

the only thing HA can do is to turn them back off after they come on.

I have considered this previously. My only question is will this affect performance? I mean triggering an automation every 5 Mins, will this put pressure on Pi 4?

What about something os an If-Else condition? If lights are off do nothing. Proceed next only of the lights are on?

If you were on a Pi2 or below then maybe, but a Pi3 or better will be fine with that.

Adding a condition of the lights being on would be a good thing.