Motion sensor with light + non-intelligent power switch

Hi!

I am very noobie but eager to learn… Anyway I’ve tried but not succeeded… I am starting to use automation more and more and this kind of behavior is my biggest need because at this moment I am not replace my light switches - just light bulbs. I am using currently Ikea tradfri led lamps with zigbee

So my scenario is:

  • Normal power switch to the light - no intelligent. If it is off -> light is off and its status is probably unknown

How I’d like to lights behave:

  1. Switch is off (somebody has put it off) and manually put on -> I want timer put light off after 5 min (independent of time) if there is no motion. If there is motion -> restart 5 min timer
  2. Switch is on - light is off - there is motion - I want timer put light off after 5 min (independent of time) if there is no motion. If there is motion -> restart 5 min timer
  3. Switch is on - light is on - there is motion - I want timer put light off after 5 min (independent of time) if there is no motion. If there is motion -> restart 5 min timer
  • Motion lights (case 2&3) on should happened between 9 pm - 8 am but case 1 should put light off independent of time

I apologize but I need exported code for helping me to understand how this works…

Hello, no worries. We all started as beginners :wink:

What you want to achieve is pretty straight forward.
You can expect the best help from people here, if you already share what you have tried.

Anyway, in order to get you going i am sharing my light flow. Its a bit more complicated than what you want to achieve, but should help you out by seeing how it all works.

[{"id":"95eda17.686a66","type":"switch","z":"8957e05a.44595","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":430,"y":20,"wires":[["37244f61.0ae69"],["5c0513a7.e986ec"]]},{"id":"43188a65.235cf4","type":"api-current-state","z":"8957e05a.44595","name":"Light Off?","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kuche","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":740,"y":20,"wires":[["c4fefba6.1a6988","2807ffa5.93626"],["7d9fb621.0d0198"]]},{"id":"43c2ea13.c57bb4","type":"inject","z":"8957e05a.44595","name":"","topic":"","payload":"on","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":430,"y":120,"wires":[["37244f61.0ae69"]]},{"id":"3add5a74.d39796","type":"inject","z":"8957e05a.44595","name":"","topic":"","payload":"off","payloadType":"str","repeat":"","crontab":"","once":true,"onceDelay":0.1,"x":430,"y":180,"wires":[["5c0513a7.e986ec"]]},{"id":"f5887b19.3a6778","type":"api-call-service","z":"8957e05a.44595","name":"OFF","version":"1","service_domain":"light","service":"turn_off","entityId":"light.kuche","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2230,"y":320,"wires":[[]]},{"id":"7e2a5c2a.6fa754","type":"api-current-state","z":"8957e05a.44595","name":"Still Motion?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"binary_sensor.fib_kitchen_motion","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1470,"y":320,"wires":[[],["f5887b19.3a6778"]]},{"id":"5754036c.fe567c","type":"template","z":"8957e05a.44595","name":"cancel","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"cancel","output":"str","x":1070,"y":80,"wires":[["cf048dcd.2687b","5d191c55.bf6c34"]],"inputLabels":["on"],"outputLabels":["stop"]},{"id":"cf048dcd.2687b","type":"mytimeout","z":"8957e05a.44595","name":"15sec","outtopic":"","outsafe":" ","outwarning":"","outunsafe":"off","warning":"","timer":"15","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1210,"y":320,"wires":[["ca676ea4.a4f0c"],[]]},{"id":"ca676ea4.a4f0c","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1330,"y":320,"wires":[["7e2a5c2a.6fa754"]]},{"id":"e5d32e0e.b00c6","type":"template","z":"8957e05a.44595","name":"Off to On","field":"payload","fieldType":"msg","format":"handlebars","syntax":"plain","template":"On","output":"str","x":1080,"y":320,"wires":[["cf048dcd.2687b"]],"inputLabels":["on"],"outputLabels":["stop"]},{"id":"c4fefba6.1a6988","type":"function","z":"8957e05a.44595","name":"Set Automation On","func":"flow.set(\"kitchen\", 1, \"storeInFile\");\n\n","outputs":1,"noerr":0,"x":930,"y":20,"wires":[[]]},{"id":"7d9fb621.0d0198","type":"function","z":"8957e05a.44595","name":"Automation on?","func":"var newmsg = {}\nvar bathflow = flow.get('kitchen',\"storeInFile\");\nif (bathflow == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":920,"y":80,"wires":[["5754036c.fe567c","2807ffa5.93626"]]},{"id":"6ed149af.f1dfb8","type":"function","z":"8957e05a.44595","name":"Automation on?","func":"var newmsg = {}\nvar bathflow = flow.get('kitchen',\"storeInFile\");\nif (bathflow == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nreturn newmsg;\n","outputs":1,"noerr":0,"x":920,"y":180,"wires":[["5d191c55.bf6c34"]]},{"id":"5c0513a7.e986ec","type":"api-current-state","z":"8957e05a.44595","name":"Already On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kuche","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":590,"y":180,"wires":[["6ed149af.f1dfb8"],["a254c430.6e5098"]]},{"id":"2807ffa5.93626","type":"api-current-state","z":"8957e05a.44595","name":"Mode","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1790,"y":20,"wires":[["4ea94982.950118"]]},{"id":"4ea94982.950118","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Tag","vt":"str"},{"t":"eq","v":"Nacht","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1930,"y":20,"wires":[["6590f202.f12eec"],["cd6ce88e.d8aca8"]]},{"id":"fd445d93.5b702","type":"server-state-changed","z":"8957e05a.44595","name":"Kitchen Motion","version":1,"entityidfilter":"binary_sensor.fib_kitchen_motion","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":80,"y":20,"wires":[["95eda17.686a66"]]},{"id":"37244f61.0ae69","type":"api-current-state","z":"8957e05a.44595","name":"Illuminance","version":1,"outputs":2,"halt_if":"250","halt_if_type":"num","halt_if_compare":"gt","override_topic":true,"entity_id":"sensor.fib_kitchen_light","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":590,"y":20,"wires":[[],["43188a65.235cf4"]]},{"id":"9d7a12ae.9750b","type":"api-current-state","z":"8957e05a.44595","name":"Still Motion?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"binary_sensor.fib_kitchen_motion","state_type":"str","state_location":"","override_payload":"none","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1470,"y":180,"wires":[[],["e5d32e0e.b00c6","2dd95b0f.e0ce34"]],"outputLabels":["","on"]},{"id":"2dd95b0f.e0ce34","type":"api-current-state","z":"8957e05a.44595","name":"still On?","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kuche","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1640,"y":180,"wires":[["5b883464.7c6cec"],[]]},{"id":"5b883464.7c6cec","type":"api-current-state","z":"8957e05a.44595","name":"Mode","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1790,"y":180,"wires":[["e06d5f1b.c9d32"]]},{"id":"e06d5f1b.c9d32","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Tag","vt":"str"},{"t":"eq","v":"Nacht","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1930,"y":180,"wires":[["ef4d708f.732f2"],["a6625f08.e149e"]]},{"id":"6590f202.f12eec","type":"api-call-service","z":"8957e05a.44595","name":"Tag","version":"1","service_domain":"light","service":"turn_on","entityId":"light.kuche","data":"{\"kelvin\":\"2700\",\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2230,"y":20,"wires":[[]]},{"id":"cd6ce88e.d8aca8","type":"api-call-service","z":"8957e05a.44595","name":"Nacht","version":"1","service_domain":"light","service":"turn_on","entityId":"light.kitchen_top","data":"{\"color_name\":\"red\",\"brightness_pct\":\"25\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2230,"y":80,"wires":[[]]},{"id":"ef4d708f.732f2","type":"api-call-service","z":"8957e05a.44595","name":"Tag Dim","version":"1","service_domain":"light","service":"turn_on","entityId":"light.kuche","data":"{\"kelvin\":\"2700\",\"brightness_pct\":\"50\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2240,"y":180,"wires":[[]]},{"id":"a6625f08.e149e","type":"api-call-service","z":"8957e05a.44595","name":"Nacht Dim","version":"1","service_domain":"light","service":"turn_on","entityId":"light.kitchen_top","data":"{\"color_name\":\"red\",\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":2250,"y":240,"wires":[[]]},{"id":"b50876a9.65c2d8","type":"server-state-changed","z":"8957e05a.44595","name":"Light Off?","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.kuche","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":580,"y":240,"wires":[["a254c430.6e5098"],[]]},{"id":"5d191c55.bf6c34","type":"mytimeout","z":"8957e05a.44595","name":"10sec","outtopic":"","outsafe":" ","outwarning":"","outunsafe":"off","warning":"","timer":"10","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":1210,"y":180,"wires":[["e261e742.f4ac48"],[]]},{"id":"e261e742.f4ac48","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1330,"y":180,"wires":[["9d7a12ae.9750b"]]},{"id":"27f16475.194c9c","type":"link in","z":"8957e05a.44595","name":"Set Automation Output","links":["94be304b.ddfcb","a254c430.6e5098","9dadafd2.bbd4f","df1df813.13cb88","fe904d39.1a926"],"x":915,"y":240,"wires":[["6e27c0a4.0cf94"]]},{"id":"a254c430.6e5098","type":"link out","z":"8957e05a.44595","name":"Set Automation Input","links":["27f16475.194c9c"],"x":855,"y":240,"wires":[]},{"id":"6e27c0a4.0cf94","type":"function","z":"8957e05a.44595","name":"Set Automation off","func":"flow.set(\"kitchen\", 0, \"storeInFile\");\n\n","outputs":1,"noerr":0,"x":1050,"y":240,"wires":[[]]}]

What is happening here:
Motion is the trigger. If motion is detected, i check for other variable (light level, if the light is already on, if the light was turned on by this automation or manual etc.). Then if everything checks out, i turn on the light based on the state of the house. (i.e. Night Mode / Day Mode). After a timeout of no motion, i will first dim the lights, and then after another timeout, turn them off. Otherwise if there is motion again, they will turn back to the previous level.

I can only encourage you to play around with NodeRed. Try things out, and if you run into any roadblocks, report back and ask specific questions :slight_smile:

2 Likes

Thx for this but for start there is way 2 many “happenings” for my need… maybe after some time…:wink:

I love it!

FYI… some time ago i redid the whole thing, and its now much simpler… at least to me:
Using MQTT messages as states for triggering.

[{"id":"914a9b73.c28298","type":"subflow","name":"Motion Timeout 10s","info":"","category":"","in":[{"x":60,"y":140,"wires":[{"id":"38ecdf53.b21a"}]}],"out":[{"x":680,"y":140,"wires":[{"id":"ed97cd7e.57ca7","port":0}]}],"env":[],"color":"#DDAA99"},{"id":"38ecdf53.b21a","type":"function","z":"914a9b73.c28298","name":"on/off","func":"var stop = {payload:\"STOP\"}\n\nif (msg.payload === \"on\") {\n   return [ msg, stop ];\n} else {\n   return [ null, msg ];\n}\nreturn msg\n\n","outputs":2,"noerr":0,"x":270,"y":140,"wires":[["ed97cd7e.57ca7"],["2ce8c212.97a0ce"]]},{"id":"e5afe76f.aa45a8","type":"inject","z":"914a9b73.c28298","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":90,"y":80,"wires":[["38ecdf53.b21a"]]},{"id":"deefcb6a.ad8a38","type":"inject","z":"914a9b73.c28298","name":"","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":90,"y":40,"wires":[["38ecdf53.b21a"]]},{"id":"2ce8c212.97a0ce","type":"stoptimer","z":"914a9b73.c28298","duration":"10","units":"Second","payloadtype":"str","payloadval":"","name":"","x":430,"y":180,"wires":[["ed97cd7e.57ca7"],[]]},{"id":"ed97cd7e.57ca7","type":"rbe","z":"914a9b73.c28298","name":"","func":"rbe","gap":"","start":"","inout":"out","property":"payload","x":590,"y":140,"wires":[[]]},{"id":"2a67c903.a2c366","type":"mqtt in","z":"8957e05a.44595","name":"","topic":"NodeRed/Motion/Kitchen/Off/10sec","qos":"1","datatype":"auto","broker":"38f11bdf.cd0904","x":180,"y":560,"wires":[["cbd97dc8.64f5e"]]},{"id":"26879474.f8338c","type":"api-current-state","z":"8957e05a.44595","name":"Mode","server":"2fba4297.e4145e","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":870,"y":560,"wires":[["5ec8949d.e1445c"]]},{"id":"5ec8949d.e1445c","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Tag","vt":"str"},{"t":"eq","v":"Nacht","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":560,"wires":[["b08ef913.0576e8"],["14ae7314.4279ad"]]},{"id":"39ef33f.26896cc","type":"mqtt in","z":"8957e05a.44595","name":"","topic":"NodeRed/Motion/Kitchen/Off/30sec","qos":"1","datatype":"auto","broker":"38f11bdf.cd0904","x":180,"y":680,"wires":[["f9c71a1b.ac3e28"]]},{"id":"130db47a.4b065c","type":"function","z":"8957e05a.44595","name":"on/off?","func":"newmsg = {};\nif (msg.payload == \"off\")\n{\n    newmsg.payload = \"True\";\n}else {\n    newmsg.payload = \"cancel\";\n//    global.set(\"motion\", 0);\n//    flow.set(\"motion\", 0);\n}\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n\nreturn newmsg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":470,"y":100,"wires":[["7fe9d8ba.734f28","fae5a5ed.d11338"]]},{"id":"7fe9d8ba.734f28","type":"mytimeout","z":"8957e05a.44595","name":"20min","outtopic":"","outsafe":" ","outwarning":"","outunsafe":"20","warning":"900","timer":"1200","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":610,"y":100,"wires":[["5a0b9c6e.8581e4"],[]]},{"id":"5a0b9c6e.8581e4","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"20","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":100,"wires":[["aba3b31c.d826a"],[]]},{"id":"aba3b31c.d826a","type":"mqtt out","z":"8957e05a.44595","name":"No Motion for 20min","topic":"NodeRed/Motion/Kitchen/Off/20min","qos":"1","retain":"","broker":"38f11bdf.cd0904","x":1020,"y":100,"wires":[]},{"id":"666c519d.5242a","type":"subflow:914a9b73.c28298","z":"8957e05a.44595","name":"","x":290,"y":100,"wires":[["130db47a.4b065c"]]},{"id":"6a6c0e1f.bcacf","type":"debug","z":"8957e05a.44595","name":"motion kitchen","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":280,"y":160,"wires":[]},{"id":"fae5a5ed.d11338","type":"mytimeout","z":"8957e05a.44595","name":"30/10sec","outtopic":"","outsafe":" ","outwarning":"10","outunsafe":"30","warning":"20","timer":"30","debug":false,"ndebug":false,"ignoreCase":false,"repeat":false,"again":false,"x":620,"y":160,"wires":[["642645e9.fb267c"],[]]},{"id":"642645e9.fb267c","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"10","vt":"num"},{"t":"eq","v":"30","vt":"num"}],"checkall":"true","repair":false,"outputs":2,"x":770,"y":160,"wires":[["fdac22c6.e16f5"],["d79712a.d93c7f"]]},{"id":"fdac22c6.e16f5","type":"mqtt out","z":"8957e05a.44595","name":"No Motion for 10sec","topic":"NodeRed/Motion/Kitchen/Off/10sec","qos":"1","retain":"","broker":"38f11bdf.cd0904","x":1020,"y":160,"wires":[]},{"id":"d79712a.d93c7f","type":"mqtt out","z":"8957e05a.44595","name":"No Motion for 30sec","topic":"NodeRed/Motion/Kitchen/Off/30sec","qos":"1","retain":"","broker":"38f11bdf.cd0904","x":1020,"y":220,"wires":[]},{"id":"5d466d1.23fbc94","type":"api-current-state","z":"8957e05a.44595","name":"Mode","server":"2fba4297.e4145e","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_select.mode","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":870,"y":340,"wires":[["867d8183.a6f84"]]},{"id":"867d8183.a6f84","type":"switch","z":"8957e05a.44595","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"Tag","vt":"str"},{"t":"eq","v":"Nacht","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1010,"y":340,"wires":[["74710206.3c721c"],["189d1c85.de9db3"]]},{"id":"e764f6d8.7aeb88","type":"mqtt in","z":"8957e05a.44595","name":"","topic":"NodeRed/Motion/Kitchen/Off/20min","qos":"1","datatype":"auto","broker":"38f11bdf.cd0904","x":180,"y":800,"wires":[["e58bd513.a71f28"]]},{"id":"58deb4e9.19295c","type":"comment","z":"8957e05a.44595","name":"Lights Automation based on Mode, Motion, Light","info":"","x":180,"y":20,"wires":[]},{"id":"55600b8d.25ed34","type":"comment","z":"8957e05a.44595","name":"Detect Motion - Trigger MQTT when off","info":"","x":190,"y":60,"wires":[]},{"id":"f52db1f1.30e3","type":"comment","z":"8957e05a.44595","name":"Turn on Light if conditions are met","info":"","x":180,"y":300,"wires":[]},{"id":"2dd5ab1c.02ad44","type":"comment","z":"8957e05a.44595","name":"MQTT Triggers light dimming after 2min","info":"","x":190,"y":520,"wires":[]},{"id":"1d8ded8b.cda832","type":"comment","z":"8957e05a.44595","name":"MQTT Triggers light off after 3min","info":"","x":170,"y":640,"wires":[]},{"id":"d27f57c4.7b9398","type":"comment","z":"8957e05a.44595","name":"MQTT Triggers light off after 20min (Manual turn on is overridden)","info":"","x":270,"y":760,"wires":[]},{"id":"2c2f05c8.8f817a","type":"comment","z":"8957e05a.44595","name":"Light off turns off automation variable","info":"","x":180,"y":860,"wires":[]},{"id":"b25a9498.6318d8","type":"server-state-changed","z":"8957e05a.44595","name":"Motion Küche","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.xiaomi_motion_kitchen_occupancy","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":100,"wires":[["666c519d.5242a","6a6c0e1f.bcacf"]]},{"id":"7407d6c1.ab8c98","type":"api-current-state","z":"8957e05a.44595","name":"Light Off?","server":"2fba4297.e4145e","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":true,"entity_id":"light.kuche","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":420,"y":340,"wires":[["8ba424ee.459cf8","5d466d1.23fbc94"],["3fcd1f49.8afc3"]]},{"id":"452d5c7.bb8cea4","type":"api-current-state","z":"8957e05a.44595","name":"luminance","server":"2fba4297.e4145e","version":1,"outputs":2,"halt_if":"250","halt_if_type":"num","halt_if_compare":"gt","override_topic":true,"entity_id":"sensor.avgluminance","state_type":"num","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":270,"y":340,"wires":[[],["7407d6c1.ab8c98"]]},{"id":"d1db8f43.4b8d4","type":"server-state-changed","z":"8957e05a.44595","name":"Motion Küche","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.xiaomi_motion_kitchen_occupancy","entityidfiltertype":"substring","outputinitially":true,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":340,"wires":[["452d5c7.bb8cea4"],[]]},{"id":"74710206.3c721c","type":"api-call-service","z":"8957e05a.44595","name":"Tag","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_left, light.kitchen_right, light.kitchen_top","data":"{\"kelvin\":\"2700\",\"brightness_pct\":\"100\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1170,"y":340,"wires":[[]]},{"id":"189d1c85.de9db3","type":"api-call-service","z":"8957e05a.44595","name":"Nacht","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_top","data":"{\"color_name\":\"red\",\"brightness_pct\":\"25\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1170,"y":400,"wires":[[]]},{"id":"66a2971a.2ac038","type":"server-state-changed","z":"8957e05a.44595","name":"Light Off?","server":"2fba4297.e4145e","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.kuche","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"off","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"x":100,"y":900,"wires":[["100c12da.86f2dd"],[]]},{"id":"b08ef913.0576e8","type":"api-call-service","z":"8957e05a.44595","name":"Tag Dim","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_left, light.kitchen_right, light.kitchen_top","data":"{\"kelvin\":\"2700\",\"brightness_pct\":\"50\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1180,"y":560,"wires":[[]]},{"id":"14ae7314.4279ad","type":"api-call-service","z":"8957e05a.44595","name":"Nacht Dim","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.kitchen_top","data":"{\"color_name\":\"red\",\"brightness_pct\":\"10\"}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1190,"y":620,"wires":[[]]},{"id":"78e3c5ba.0d578c","type":"api-call-service","z":"8957e05a.44595","name":"OFF","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.kitchen_left, light.kitchen_right, light.kitchen_top","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1170,"y":680,"wires":[[]]},{"id":"e58bd513.a71f28","type":"api-call-service","z":"8957e05a.44595","name":"OFF","server":"2fba4297.e4145e","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.kitchen_left, light.kitchen_right, light.kitchen_top","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1170,"y":800,"wires":[[]]},{"id":"8ba424ee.459cf8","type":"function","z":"8957e05a.44595","name":"Set Automation On","func":"flow.set(\"motion\", 1, \"storeInFile\");\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":400,"wires":[[]]},{"id":"100c12da.86f2dd","type":"function","z":"8957e05a.44595","name":"Set Automation off","func":"flow.set(\"motion\", 0, \"storeInFile\");\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":650,"y":900,"wires":[[]]},{"id":"3fcd1f49.8afc3","type":"function","z":"8957e05a.44595","name":"Automation on?","func":"var newmsg = {}\nvar motion = flow.get('motion',\"storeInFile\");\nif (motion == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n\nreturn newmsg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":460,"wires":[["5d466d1.23fbc94"]]},{"id":"cbd97dc8.64f5e","type":"function","z":"8957e05a.44595","name":"Automation on?","func":"var newmsg = {}\nvar motion = flow.get('motion',\"storeInFile\");\nif (motion == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n\nreturn newmsg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":560,"wires":[["26879474.f8338c"]]},{"id":"f9c71a1b.ac3e28","type":"function","z":"8957e05a.44595","name":"Automation on?","func":"var newmsg = {}\nvar motion = flow.get('motion',\"storeInFile\");\nif (motion == 1)\n   newmsg.payload = \"True\";\nelse (newmsg = null)\n\nvar today = new Date();\nvar date = today.getFullYear()+'-'+(today.getMonth()+1)+'-'+today.getDate();\nvar time = today.getHours() + \":\" + today.getMinutes() + \":\" + today.getSeconds();\nvar dateTime = date+' '+time;\nnode.status({fill:\"green\",shape:\"dot\",text:dateTime});\n\nreturn newmsg;\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","x":640,"y":680,"wires":[["78e3c5ba.0d578c"]]},{"id":"fd242c4a.283ea","type":"inject","z":"8957e05a.44595","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":950,"y":860,"wires":[["e58bd513.a71f28"]]},{"id":"38f11bdf.cd0904","type":"mqtt-broker","name":"Mosquitto","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":true,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""},{"id":"2fba4297.e4145e","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true}]

Have a look at this flow. (you need to have your tradfri light setup so that is goes to the on state when powered on).

[{"id":"6875337b.05aa7c","type":"server-state-changed","z":"bb98ffbd.85807","name":"Mottion Sensor","server":"d9a8f2ed.08cfe","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.hue_motion_sensor_1_motion","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":160,"y":340,"wires":[["f7ce701d.d5839","86de5739.5b8458"],["c15f53f1.908b2"]]},{"id":"c15f53f1.908b2","type":"stoptimer","z":"bb98ffbd.85807","duration":"5","units":"Minute","payloadtype":"num","payloadval":"0","name":"5 minutes timer","x":780,"y":500,"wires":[["79f6cfdc.b4ef4"],[]]},{"id":"ad3c4334.62f74","type":"change","z":"bb98ffbd.85807","name":"set playload to stop","rules":[{"t":"set","p":"payload","pt":"msg","to":"stop","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":730,"y":280,"wires":[["c15f53f1.908b2","35109689.14468a"]]},{"id":"35109689.14468a","type":"api-call-service","z":"bb98ffbd.85807","name":"light on","server":"d9a8f2ed.08cfe","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.0x00124b001b6b460e_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1020,"y":280,"wires":[[]]},{"id":"79f6cfdc.b4ef4","type":"api-call-service","z":"bb98ffbd.85807","name":"light off","server":"d9a8f2ed.08cfe","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.0x00124b001b6b460e_light","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1020,"y":520,"wires":[["c81d1be3.e44b98"]]},{"id":"f7ce701d.d5839","type":"time-range-switch","z":"bb98ffbd.85807","name":"","lat":"","lon":"","startTime":"21:00","endTime":"08:00","startOffset":0,"endOffset":0,"x":450,"y":300,"wires":[["ad3c4334.62f74"],[]]},{"id":"872bf9f2.bca958","type":"server-state-changed","z":"bb98ffbd.85807","name":"Light on (switch flipped)","server":"d9a8f2ed.08cfe","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.0x00124b001b6b460e_light","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"on","halt_if_type":"str","halt_if_compare":"is","outputs":2,"output_only_on_state_change":true,"for":0,"forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":180,"y":600,"wires":[["c15f53f1.908b2","3fb14016.42997"],[]]},{"id":"3bdae1b.0e6ca1e","type":"api-call-service","z":"bb98ffbd.85807","name":"Enable help switch..","server":"d9a8f2ed.08cfe","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_on","entityId":"input_boolean.test1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":700,"y":660,"wires":[[]]},{"id":"c81d1be3.e44b98","type":"api-call-service","z":"bb98ffbd.85807","name":"Turnoff help switch..","server":"d9a8f2ed.08cfe","version":1,"debugenabled":false,"service_domain":"input_boolean","service":"turn_off","entityId":"input_boolean.test1","data":"","dataType":"json","mergecontext":"","output_location":"","output_location_type":"none","mustacheAltTags":false,"x":1040,"y":620,"wires":[[]]},{"id":"86de5739.5b8458","type":"api-current-state","z":"bb98ffbd.85807","name":"Check helper switch","server":"d9a8f2ed.08cfe","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"input_boolean.test1","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":480,"y":220,"wires":[["ad3c4334.62f74"]]},{"id":"3fb14016.42997","type":"time-range-switch","z":"bb98ffbd.85807","name":"","lat":"","lon":"","startTime":"21:00","endTime":"08:00","startOffset":0,"endOffset":0,"x":430,"y":660,"wires":[[],["3bdae1b.0e6ca1e"]]},{"id":"d9a8f2ed.08cfe","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

Hi - I know this is an old post, but i tried your flow, and i get en error on the Mode node.

"InputError:  input_select.mode"