CoRE - Get peer assistance here with setting up Pistons

Hi all

I’m new to CoRE and have been trying to create a particular Piston but am unsure about how to go about it.

My setup:

What I’d like to achieve, and have setup through lighting director right now is to have the lounge lights, (can be individually and set level, using a group switch, or using a momentary scene switch), turn on when:

lux is below 20 AND there is motion
Turn off if no motion for 3 mins

BUT

If the lights are manually turned on using: hue widget/smartthings/sharptools - whatever. Then don’t worry about the former.

Any pointers would be greatly appreciated.

Nitin

EDIT: actually, something close to this type of logic with an external variable looks like it may be how I should structure this? (credit to ady624)