Automation full range value question

I have install two xiaomi sensors in my HA system. I want place one sensor1 out side the bedroom and the other sensor2 in the bedroom. If some one enter the room triggered sensor1 and sensor2 in a row then turn on the light.and I need a value to count how many man in the bedroom. to avoid if some one get out the bedroom trigger the sensor2 and sensor1 in a row.the light turn off automatically left someone in the dark. can I define a full range various in the automation? Need help!