Sonoff presence sensor (SNZB-06p) race condition between presence and Illuminance entities

I’m trying to create a basic automation using the Sonoff presence sensor (SNZB-06P) connected via zigbee2mqtt. The automation will turn on the lights when presence is detected under the condition that it is dim.

Turns out it wasn’t as straightforward, as the SNZB-06P updates its Illuminance only upon presence. This creates a race condition between presence being detected and the update of Illuminance values in an automation. The odd thing is, this setup works for a regular zigbee motion and Illuminance combo sensor, but why not the SNZB-06P.

Has anyone encountered this? The workaround was to have presence detected for 1 sec before triggering the automation, but that would delay the trigger, which is not optimal. I’m attaching a screenshot which shows the order of entities being updated.

Not sure it creates a race.

If you trigger on both presence and illuminance, assuming that both happen in quick succession

  1. You get presence first: You do whatever actions based upon the current illum, then you get the illum trigger, and you adjust based upon it.
  2. You get illum first: If presence is off, you basically do nothing. then you get presence, and do your actions based upon current illum, like 1)

In a scenario where the last known Illuminance value was ‘bright’: when presence triggers the automation, the illuminance value doesn’t get updated to ‘dim’ on time, missing the automation window. In this case, the lights won’t turn on since Illuminance remained as ‘bright’ and didn’t change to ‘dim’ until after the automation has executed completely. As noted, the SNZB-06P updates its illuminance value only when presence is detected.