Here is mine based on state machine, I found this example in reddit (dont have the link now) and i customised it according to my needs.
The link in and out sensor are also used to turn the state machine to steady state (off in which case). This is triggered from my bed sensor when i go to bed, so that the switch override is no more active at night and motion detection can turn the lights on.
[{"id":"de12e9a4.6b6f88","type":"trigger-state","z":"c159cc9d.b6c6","name":"Hallway motion, when light is not unavailable","server":"bb4f1378.25112","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.diadromos_motion_sensor_2","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"t8agwg8k43","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"yfi570775pd","targetType":"entity_id","targetValue":"light.diadromos","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"unavailable"},{"id":"5hp3s08gqvi","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"x":190,"y":220,"wires":[["fc3f8cfe.fde5"],[]]},{"id":"13a923bd.be366c","type":"trigger-state","z":"c159cc9d.b6c6","name":"Hallway lights","server":"bb4f1378.25112","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"light.hallway_lights","entityidfiltertype":"exact","debugenabled":false,"constraints":[],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":300,"y":340,"wires":[["58446483.5d16ec"],[]]},{"id":"db06bb86.98b868","type":"state-machine","z":"c159cc9d.b6c6","name":"","triggerProperty":"payload","triggerPropertyType":"msg","stateProperty":"payload","statePropertyType":"msg","outputStateChangeOnly":true,"throwException":false,"states":["off","switch","motion-detected","motion-on","motion-off","on"],"transitions":[{"name":"motion-detected","from":"off","to":"motion-detected"},{"name":"motion-detected","from":"motion-on","to":"motion-on"},{"name":"off","from":"*","to":"off"},{"name":"on","from":"*","to":"on"},{"name":"switch","from":"off","to":"switch"},{"name":"switch","from":"on","to":"switch"},{"name":"switch","from":"switch","to":"switch"},{"name":"switch","from":"motion-on","to":"switch"},{"name":"motion-on","from":"motion-detected","to":"motion-on"},{"name":"motion-off","from":"motion-on","to":"motion-off"}],"x":693,"y":227,"wires":[["5eccd45a.407c4c","6a10bd49.a84214","3a9c93f2.df1a3c","20a619e8.6ccfd6"]],"info":"State node to trigger taskes based on state was and incoming state"},{"id":"58446483.5d16ec","type":"change","z":"c159cc9d.b6c6","name":"switch","rules":[{"t":"set","p":"payload","pt":"msg","to":"switch","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":490,"y":340,"wires":[["db06bb86.98b868"]]},{"id":"fc3f8cfe.fde5","type":"change","z":"c159cc9d.b6c6","name":"motion","rules":[{"t":"set","p":"payload","pt":"msg","to":"motion-detected","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":527,"y":229,"wires":[["db06bb86.98b868"]]},{"id":"2a6c703e.359a4","type":"link in","z":"c159cc9d.b6c6","name":"hallway state machine","links":["e9fc5953.176bc8"],"x":695,"y":160,"wires":[["db06bb86.98b868"]]},{"id":"da27162f.5f4eb8","type":"api-call-service","z":"c159cc9d.b6c6","name":"Lights On 1%","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":1}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":40,"wires":[["e2b55636.21f158"]]},{"id":"c2187e17.6a466","type":"api-call-service","z":"c159cc9d.b6c6","name":"Turn off lights","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.diadromos, light.diadromos2","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":247,"wires":[["6529d739.f82db8"]]},{"id":"74f82ba1.922b84","type":"stoptimer","z":"c159cc9d.b6c6","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"pause detection","x":1260,"y":394,"wires":[["4d616d8b.ffbbe4"],[]]},{"id":"4d616d8b.ffbbe4","type":"api-current-state","z":"c159cc9d.b6c6","name":"Light state","server":"bb4f1378.25112","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.hallway_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1530,"y":280,"wires":[["e9fc5953.176bc8"]]},{"id":"96e3555f.5d3bf8","type":"change","z":"c159cc9d.b6c6","name":"stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1030,"y":320,"wires":[["d0c5e596.2dff38","bc8d958c.32f958"]]},{"id":"6519ae82.7e9df","type":"change","z":"c159cc9d.b6c6","name":"motion-on","rules":[{"t":"set","p":"payload","pt":"msg","to":"motion-on","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1540,"y":240,"wires":[["e9fc5953.176bc8"]]},{"id":"9c9eae95.7c14f","type":"change","z":"c159cc9d.b6c6","name":"motion-off","rules":[{"t":"set","p":"payload","pt":"msg","to":"motion-off","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1520,"y":340,"wires":[["e9fc5953.176bc8"]]},{"id":"6529d739.f82db8","type":"stoptimer","z":"c159cc9d.b6c6","duration":"10","units":"Second","payloadtype":"num","payloadval":"0","name":"pause","x":1250,"y":247,"wires":[["4d616d8b.ffbbe4"],[]]},{"id":"e2b55636.21f158","type":"stoptimer","z":"c159cc9d.b6c6","duration":"10","units":"Second","payloadtype":"num","payloadval":"0","name":"pause","x":1650,"y":100,"wires":[["6519ae82.7e9df"],[]]},{"id":"e2566ecb.b301f","type":"inject","z":"c159cc9d.b6c6","name":"steady-state","topic":"","payload":"stop","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":1370,"y":460,"wires":[["74f82ba1.922b84","4d616d8b.ffbbe4"]]},{"id":"5eccd45a.407c4c","type":"switch","z":"c159cc9d.b6c6","name":"motion-detected","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"motion-detected","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":900,"y":140,"wires":[["e81c0f5e.030e9"]]},{"id":"6a10bd49.a84214","type":"switch","z":"c159cc9d.b6c6","name":"motion-on","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"motion-on","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":880,"y":287,"wires":[["d0c5e596.2dff38","bc8d958c.32f958"]]},{"id":"e9fc5953.176bc8","type":"link out","z":"c159cc9d.b6c6","name":"hallway state machine","links":["2a6c703e.359a4"],"x":1775,"y":120,"wires":[]},{"id":"3a9c93f2.df1a3c","type":"switch","z":"c159cc9d.b6c6","name":"switch","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"switch","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":890,"y":380,"wires":[["96e3555f.5d3bf8","74f82ba1.922b84"]]},{"id":"20a619e8.6ccfd6","type":"switch","z":"c159cc9d.b6c6","name":"motion-off","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"motion-off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":880,"y":247,"wires":[["c2187e17.6a466"]]},{"id":"d0c5e596.2dff38","type":"stoptimer","z":"c159cc9d.b6c6","duration":"3","units":"Minute","payloadtype":"num","payloadval":"0","name":"","x":1280,"y":287,"wires":[["9c9eae95.7c14f"],[]]},{"id":"e81c0f5e.030e9","type":"time-range-switch","z":"c159cc9d.b6c6","name":"","lat":"47.13845","lon":"7.24346","startTime":"00:01","endTime":"06:00","startOffset":0,"endOffset":0,"x":1050,"y":60,"wires":[["da27162f.5f4eb8"],["ded7dc3a.e437f"]]},{"id":"98bfff77.3a625","type":"api-call-service","z":"c159cc9d.b6c6","name":"Lights On 100%","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":100}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":160,"wires":[["e2b55636.21f158"]]},{"id":"59d0b65.99d2448","type":"trigger-state","z":"c159cc9d.b6c6","name":"Door opened","server":"bb4f1378.25112","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.sensor","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"51a2cifgg2c","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"jl22qki73pj","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","x":90,"y":280,"wires":[["fc3f8cfe.fde5"],[]]},{"id":"5d5a8565.3e198c","type":"comment","z":"c159cc9d.b6c6","name":"Automation for Hallway Light","info":"","x":1040,"y":20,"wires":[]},{"id":"80567b4e.c41808","type":"comment","z":"c159cc9d.b6c6","name":"Automation for Hallway Dimmer","info":"","x":690,"y":460,"wires":[]},{"id":"5b5383c5.8787dc","type":"time-range-switch","z":"c159cc9d.b6c6","name":"","lat":"47.13845","lon":"7.24346","startTime":"22:00","endTime":"00:00","startOffset":0,"endOffset":0,"x":1210,"y":167,"wires":[["841d239e.17c7b"],["98bfff77.3a625"]]},{"id":"841d239e.17c7b","type":"api-call-service","z":"c159cc9d.b6c6","name":"Lights On 30%","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":30}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":120,"wires":[["e2b55636.21f158"]]},{"id":"ded7dc3a.e437f","type":"time-range-switch","z":"c159cc9d.b6c6","name":"","lat":"47.13845","lon":"7.24346","startTime":"06:01","endTime":"07:30","startOffset":0,"endOffset":0,"x":1110,"y":120,"wires":[["651ffaf8.ee4134"],["5b5383c5.8787dc"]]},{"id":"651ffaf8.ee4134","type":"api-call-service","z":"c159cc9d.b6c6","name":"Lights On 20%","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.hallway_lights","data":"{\"brightness_pct\":20}","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1420,"y":80,"wires":[["e2b55636.21f158"]]},{"id":"d164bcf0.5a9f1","type":"trigger-state","z":"c159cc9d.b6c6","name":"Hallway motion on->off","server":"bb4f1378.25112","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.diadromos_motion_sensor_2","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"vvewwqnt4l","targetType":"entity_id","targetValue":"light.hallway_lights","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"unavailable"},{"id":"1wr9ik19xur","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"id":"k73xyo36npb","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"x":120,"y":60,"wires":[["894c256f.b5ca78"],[]]},{"id":"894c256f.b5ca78","type":"stoptimer","z":"c159cc9d.b6c6","duration":"10","units":"Minute","payloadtype":"num","payloadval":"0","name":"10 mins","x":400,"y":60,"wires":[["9518f24a.01dd2"],[]]},{"id":"9518f24a.01dd2","type":"api-current-state","z":"c159cc9d.b6c6","name":"If light is on","server":"bb4f1378.25112","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.hallway_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":650,"y":60,"wires":[["88ddb627.8168a8"],[]]},{"id":"88ddb627.8168a8","type":"api-call-service","z":"c159cc9d.b6c6","name":"Turn off lights","server":"bb4f1378.25112","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.hallway_lights","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":840,"y":60,"wires":[["33d91744.7a29f8"]]},{"id":"4449a059.21608","type":"comment","z":"c159cc9d.b6c6","name":"Motion not detected for 10 mins and light is on, used to turn off light after 10 mins overriding the switch state","info":"","x":380,"y":20,"wires":[]},{"id":"421d0615.2447a8","type":"api-current-state","z":"c159cc9d.b6c6","name":"Light state","server":"bb4f1378.25112","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.hallway_lights","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":570,"y":180,"wires":[["db06bb86.98b868"]]},{"id":"33d91744.7a29f8","type":"stoptimer","z":"c159cc9d.b6c6","duration":"10","units":"Second","payloadtype":"num","payloadval":"0","name":"pause","x":430,"y":180,"wires":[["421d0615.2447a8"],[]]},{"id":"851ff00e.d158e","type":"trigger-state","z":"c159cc9d.b6c6","name":"Hallway motion off->on","server":"bb4f1378.25112","exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":"binary_sensor.diadromos_motion_sensor_2","entityidfiltertype":"exact","debugenabled":false,"constraints":[{"id":"vvewwqnt4l","targetType":"entity_id","targetValue":"light.hallway_lights","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"unavailable"},{"id":"1mgb2msa1hh","targetType":"this_entity","targetValue":"","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"id":"t200na6tpu","targetType":"this_entity","targetValue":"","propertyType":"previous_state","propertyValue":"old_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"}],"constraintsmustmatch":"all","outputs":2,"customoutputs":[],"outputinitially":false,"x":120,"y":140,"wires":[["894c256f.b5ca78","aa5fe521.144d58"],[]]},{"id":"aa5fe521.144d58","type":"mytimeout","z":"c159cc9d.b6c6","name":"10 mins","outtopic":"msg.payload","outsafe":"","outwarning":"Warning","outunsafe":"s","warning":"1","timer":"600","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":400,"y":100,"wires":[[],[]]},{"id":"bc8d958c.32f958","type":"mytimeout","z":"c159cc9d.b6c6","name":"3 mins","outtopic":"msg.payload","outsafe":"","outwarning":"Warning","outunsafe":"s","warning":"1","timer":"180","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1250,"y":334,"wires":[[],[]]},{"id":"f9ac5af4.a04888","type":"link in","z":"c159cc9d.b6c6","name":"Master bedroom switch override ","links":["2fc0277c.4887b8"],"x":295,"y":180,"wires":[["33d91744.7a29f8"]]},{"id":"bb4f1378.25112","type":"server","z":"","name":"Hassio","legacy":false,"addon":false,"rejectUnauthorizedCerts":false,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]
```![06-05-_2020_11-11-39|690x186](upload://dd2Z2OIOGqmbVXSjhbMlsLWxwmX.jpeg)![06-05-_2020_11-11-39|690x186](upload://dd2Z2OIOGqmbVXSjhbMlsLWxwmX.jpeg)![06-05-_2020_11-11-39|690x186](upload://dd2Z2OIOGqmbVXSjhbMlsLWxwmX.jpeg) ![06-05-_2020_11-11-39|690x186](upload://dd2Z2OIOGqmbVXSjhbMlsLWxwmX.jpeg)![06-05-_2020_11-11-39|690x186](upload://dd2Z2OIOGqmbVXSjhbMlsLWxwmX.jpeg)