Problem with current state

The trick is firstly to use a Switch node to separate motion start and stop. Pass the start message on directly to switch the light on, send the Off message to a Trigger node that waits for the time required and then switches the light off. To stop the light being turned off if the motion starts again before the trigger has timed out, also feed the start message to the trigger, but configure the 'Reset Trigger If' option in the Trigger node to reset if the payload is equal to the start motion payload, so that it resets the trigger and it does not send the light off command. I have set the trigger to 10 seconds in the demo flow to make it easier to test.

[{"id":"1511d45dd7baee43","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"1","payloadType":"num","x":110,"y":1260,"wires":[["d09f74b5913ecad9"]]},{"id":"583a7755e99f5859","type":"inject","z":"bdd7be38.d3b55","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"0","payloadType":"num","x":110,"y":1320,"wires":[["d09f74b5913ecad9"]]},{"id":"dded18b24cc7b073","type":"change","z":"bdd7be38.d3b55","name":"Lamp on","rules":[{"t":"set","p":"payload","pt":"msg","to":"On","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1280,"wires":[["8899f8e7fdb89ad6"]]},{"id":"d09f74b5913ecad9","type":"switch","z":"bdd7be38.d3b55","name":"Occupied?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"1","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":1300,"wires":[["86113191cf89969d","dded18b24cc7b073"],["86113191cf89969d"]]},{"id":"86113191cf89969d","type":"trigger","z":"bdd7be38.d3b55","name":"","op1":"","op2":"","op1type":"nul","op2type":"pay","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"1","bytopic":"all","topic":"topic","outputs":1,"x":470,"y":1320,"wires":[["7bdb253098f142aa"]]},{"id":"7bdb253098f142aa","type":"change","z":"bdd7be38.d3b55","name":"Lamp off","rules":[{"t":"set","p":"payload","pt":"msg","to":"Off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":640,"y":1320,"wires":[["8899f8e7fdb89ad6"]]},{"id":"8899f8e7fdb89ad6","type":"debug","z":"bdd7be38.d3b55","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":830,"y":1300,"wires":[]}]