You are making this far too complicated.
Add your lux condition to this: Motion activated lights automation