Light Automation Help - controls lights if lux level at certain number

I need some help setting up an automation that can control 4 switches depending on a sensor reading.
For Example.
I have 4 rows of lights (1 row per switch, so 4 switches). I have a light sensor via MQTT updating a value.

If all 4 switches (rows of lights) are turned on, and the LUX (light level) WAS above a certain number, say 50, then Turn off all the switches.

The issue i need to avoid is the LUX sensor updating the new light level before the event is triggered.
I.e. I know how to wait for the event of all 4 switches are ON, Do X. But I don’t want to do it unless the LUX level reading is from when ALL 4 switches were Off (i.e. natural light was high enough).

Another case I need to account for. Someone has 1-3 rows of lights on… then the 4th row comes on. The LUX reading is for sure from when the 1-3 were on, so I would do nothing in this case.

I don’t want to run the test when one switch turns on (i.e. can catch an event where 4 off, 1 comes on, do the test) because I wan’t to be able to allow people to have 2 rows of lights on, even if LUX is say 50… Ideally i would trigger the test when 3 or 4 rows are on.

Hopefully some scripting guru sees this and can help me please!!