Presence Sensor based lighting with time condition

In my TV Room, I have an Aqara Presence Sensor and some Aqara Light Bulbs that are connected to Homey using Matter through the Aqara M3 hub.

I have created an automation to turn the light bulbs on at sunset through Homey which works fine.

I have another automation in Homey to turn the lights off at 10:30 PM in other parts of the house. However, in my TV Room, I would like to have the following:

  1. At 10:30, If no one is in the TV room then turn the lights off but if someone is there keep the lights on
  2. Between 10:30 and sunrise, if anyone enters the room, turn the lights on and stay on until no one is in the room, at which point, wait for a minute and turn the lights off.

I do not use an Aqara presence-sensor-fp1e, … to make the logic possible I think you need to know the total number of persons in the room. The sensor triggers on movement which does not necessarily happen when somebody is still in the room or another person leaves or another coming in while another is leaving, so you might also want to know if a person is entering ore leaving the room as well. You probably need more then one fp 1e for this to work flawlessly. The time condition can work as you want to only when the conditions above are met.