Are you using RBoy’s app for this? If so, then you will have to dig deeper into his instructions. It appears that his app can do what you desire, but any help there is beyond to scope of this thread. If not, then there are many ways to address turning off the lights. A second, simple piston could address turning the lights off when you leave :
IF Lock 1 gets Locked
THEN
IF Motion_Sensor is not active for 30 seconds
THEN
Turn off lights;
END IF
END IF