First steps with node-red: automation how to turn ON light with movement sensor

Trying to move (slowly) my automation from yaml to node-red.

These are my first steps, be patience.

WHich are the steps to achieve the following

trigger: motion sensor
condition at night
action turn on light

if no movement for X minutes, then turn off light

?

Here a starting point
i use this nodered as my office montion send a on then a off
so i use a delay of 3 mins to send a off command

and the code

[{"id":"96fdb10f.da9a5","type":"mqtt in","z":"d664133d.f572c","name":"Office Motion","topic":"stat/SONOFF-FAN/POWER3","qos":"2","broker":"987c4047.b2d81","x":90,"y":60,"wires":[["a715b704.c649d8","1c620434.e3a7cc"]]},{"id":"1c620434.e3a7cc","type":"debug","z":"d664133d.f572c","name":"","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":510,"y":140,"wires":[]},{"id":"588e82b3.973a8c","type":"delay","z":"d664133d.f572c","name":"","pauseType":"delay","timeout":"3","timeoutUnits":"minutes","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":140,"y":240,"wires":[["f3fed4fc.ec8d58"]]},{"id":"81080a7d.d7c118","type":"mqtt out","z":"d664133d.f572c","name":"","topic":"nodered/motion","qos":"","retain":"","broker":"987c4047.b2d81","x":580,"y":60,"wires":[]},{"id":"a715b704.c649d8","type":"function","z":"d664133d.f572c","name":"","func":"if (msg.payload ==\"ON\") {\n    msg.reset = true;\n    msg.payload = \"ON\"\n}\nelse{\n    \n    msg.payload = \"ON\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":250,"y":40,"wires":[["81080a7d.d7c118","1c620434.e3a7cc","588e82b3.973a8c"]]},{"id":"1affd008.6582e","type":"mqtt out","z":"d664133d.f572c","name":"","topic":"nodered/motion","qos":"","retain":"","broker":"987c4047.b2d81","x":560,"y":240,"wires":[]},{"id":"f3fed4fc.ec8d58","type":"function","z":"d664133d.f572c","name":"","func":"if (msg.payload ==\"ON\") {\n    msg.payload = \"OFF\"\n}\nelse{\n    msg.payload = \"OFF\"\n}\n\nreturn msg;","outputs":1,"noerr":0,"x":330,"y":240,"wires":[["1affd008.6582e","1c620434.e3a7cc"]]},{"id":"987c4047.b2d81","type":"mqtt-broker","z":"","name":"","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","willTopic":"","willQos":"0","willPayload":""}]