Understood. I like this problem. It gets you thinking. There are probably again several different ways to do this. As Mike mentioned, you can simply check for the last_called attribute.
You can also try it with the one I made below:
[{"id":"220817d0.2dbbe8","type":"server-state-changed","z":"dc7bdb4e.f7fc88","name":"Motion","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.presence_9","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"x":50,"y":520,"wires":[["8ee5f546.7043d8"]]},{"id":"96adb102.e4aa7","type":"time-range-switch","z":"dc7bdb4e.f7fc88","name":"","startTime":"06:00","endTime":"20:00","startOffset":"","endOffset":"","x":810,"y":440,"wires":[["c864ac28.5559b"],[]]},{"id":"d9619db7.95dd5","type":"switch","z":"dc7bdb4e.f7fc88","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":470,"y":520,"wires":[["4918c64d.a000d8"],["73c0af93.51203"]]},{"id":"c864ac28.5559b","type":"api-call-service","z":"dc7bdb4e.f7fc88","name":"Turn On","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_on","entityId":"switch.kitchen_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":980,"y":440,"wires":[[]]},{"id":"e0e9712e.87612","type":"template","z":"dc7bdb4e.f7fc88","name":"cancel","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"cancel","output":"str","x":790,"y":520,"wires":[["5a4bf388.d0da4c"]],"inputLabels":["on"],"outputLabels":["stop"]},{"id":"5a4bf388.d0da4c","type":"mytimeout","z":"dc7bdb4e.f7fc88","name":"30sec","outtopic":"","outsafe":" ","outwarning":"","outunsafe":"off","warning":"","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":910,"y":600,"wires":[["13b633ee.52643c"],[]]},{"id":"4918c64d.a000d8","type":"api-current-state","z":"dc7bdb4e.f7fc88","name":"Light On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"switch.kitchen_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":440,"wires":[["e0e9712e.87612"],["96adb102.e4aa7"]]},{"id":"687a5a68.d1a824","type":"comment","z":"dc7bdb4e.f7fc88","name":"Delay for turn off","info":"","x":940,"y":560,"wires":[]},{"id":"73c0af93.51203","type":"api-current-state","z":"dc7bdb4e.f7fc88","name":"Light On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"switch.kitchen_light","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":640,"y":600,"wires":[["5a4bf388.d0da4c"],[]]},{"id":"13b633ee.52643c","type":"switch","z":"dc7bdb4e.f7fc88","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1090,"y":600,"wires":[["4c15254b.8e449c"]]},{"id":"4c15254b.8e449c","type":"api-call-service","z":"dc7bdb4e.f7fc88","name":"Turn Off","version":1,"debugenabled":false,"service_domain":"switch","service":"turn_off","entityId":"switch.kitchen_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1260,"y":600,"wires":[["8ee5f546.7043d8"]]},{"id":"781c6dd9.c442b4","type":"comment","z":"dc7bdb4e.f7fc88","name":"Cancel if Motion is detected during turn off delay","info":"","x":920,"y":480,"wires":[]},{"id":"8ee5f546.7043d8","type":"delay","z":"dc7bdb4e.f7fc88","name":"","pauseType":"rate","timeout":"1","timeoutUnits":"seconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":270,"y":520,"wires":[["d9619db7.95dd5"]]}]
This one is untested, but it should work. The idea is to have a rate limiter in there that is triggered at the same time as the light turns off. Therefore you will have an automatic 1sec delay in case there is motion discovered in this “perfect timing case”.
Furthermore, my assumption is that you also want to turn off the light if no motion was discovered for some time (30sec) in my flow.
NOTE: I’m using a custom node called “mytimeout” but you can also replace it with the stoptimer. I just prefer using the mytimeout node.
Anyway… its probably easier to help you after you post your current flow that you are unhappy with.