See Design Pattern: Manual Trigger Detection for how to tell if the light was manually turned on. See Design Pattern: Motion Sensor Timer for how to implenent the motion sensor timer. Given the names of since of your variables I suspect you ashtray found these though.
As for the error, because the last line of your time’s lambda is to set the variable to null, there really is no reason to check for hasTerminated. The variable will be set to null before hasTerminated would return false.
I can’t say why the code as written is generating an error. But since there is no need to test due hasTerminated, we can avoid the error though.
And once you are only checking for null, you can use
motionTimer?.reschedule(now.plusMinutes(15))
The ? replaces the if{motionTimer !== null)