Motion flow with lumination delay "If it was on..."

Hey I’m trying a flow for my Hallway with an Motion Sensor and Lumination Sensor.
It works pretty well with one tiny issue. If the light turns off and I join the hallway 1 sec later -nothing happens because my Lumination Sensor needs ~2 sec.

So I need a function or something like this with a “was the light on for the last 2 seconds?”
My skills are limited and I have no cloue how to handle this.

Thanks for any advise and help :slight_smile:

[{"id":"aeb907cd.6f0168","type":"switch","z":"f431c46a.84ab58","name":"motion on/off?","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":360,"y":360,"wires":[["ecc8799d.9897a8","9e961e19.a9aa3"],["ecc8799d.9897a8"]]},{"id":"9e961e19.a9aa3","type":"api-current-state","z":"f431c46a.84ab58","name":"Dark?","server":"fefd8095.1f637","version":1,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"sensor.lichtsensor","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":690,"y":220,"wires":[["25c1c62c.b7cdca"]]},{"id":"25c1c62c.b7cdca","type":"switch","z":"f431c46a.84ab58","name":"","property":"payload","propertyType":"msg","rules":[{"t":"lt","v":"8","vt":"num"},{"t":"gt","v":"8","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":930,"y":220,"wires":[["e753feb8.21a25","236e49cf.56e9c6"],[]]},{"id":"e753feb8.21a25","type":"time-range-switch","z":"f431c46a.84ab58","name":"22:30 - Sunrise","lat":"52.207329","lon":"9.555720","startTime":"22:30","endTime":"09:30","startOffset":0,"endOffset":0,"x":1160,"y":200,"wires":[["ceebe219.248c1"],["aec6a70f.4e97d8"]]},{"id":"ceebe219.248c1","type":"api-call-service","z":"f431c46a.84ab58","name":"Dimm-lights 3%","server":"fefd8095.1f637","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.flur_unten_2","data":"{\"brightness\":3, \"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1380,"y":260,"wires":[["9adb6719.fe0d98"]]},{"id":"aec6a70f.4e97d8","type":"api-call-service","z":"f431c46a.84ab58","name":"Light","server":"fefd8095.1f637","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.flur_unten","data":"{\"brightness\":200, \"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1350,"y":340,"wires":[["9adb6719.fe0d98"]]},{"id":"b8d1bfb2.40c37","type":"server-state-changed","z":"f431c46a.84ab58","name":"Motion","server":"fefd8095.1f637","version":1,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.presence_manu","entityidfiltertype":"substring","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"for":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"x":110,"y":360,"wires":[["aeb907cd.6f0168"]]},{"id":"9adb6719.fe0d98","type":"debug","z":"f431c46a.84ab58","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1640,"y":340,"wires":[]},{"id":"ecc8799d.9897a8","type":"stoptimer","z":"f431c46a.84ab58","duration":"30","units":"Second","payloadtype":"num","payloadval":"0","name":"","x":590,"y":400,"wires":[["a9b783bf.9f949"],[]]},{"id":"a9b783bf.9f949","type":"api-current-state","z":"f431c46a.84ab58","name":"motion?","server":"fefd8095.1f637","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"binary_sensor.presence_manu","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":800,"y":400,"wires":[[],["9c00bbed.f6bb58"]]},{"id":"c37e530c.3f992","type":"api-call-service","z":"f431c46a.84ab58","name":"Off","server":"fefd8095.1f637","version":1,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.flur_unten","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1250,"y":420,"wires":[[]]},{"id":"9c00bbed.f6bb58","type":"api-current-state","z":"f431c46a.84ab58","name":"Lights On?","server":"fefd8095.1f637","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.flur_unten","state_type":"str","state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","blockInputOverrides":false,"x":1010,"y":400,"wires":[[],["c37e530c.3f992"]]},{"id":"3fb18031.ab363","type":"comment","z":"f431c46a.84ab58","name":"Flur Licht bewegung","info":"","x":150,"y":260,"wires":[]},{"id":"236e49cf.56e9c6","type":"time-range-switch","z":"f431c46a.84ab58","name":"20:30 - Sunrise","lat":"52.207329","lon":"9.555720","startTime":"20:30","endTime":"22:30","startOffset":0,"endOffset":0,"x":1160,"y":120,"wires":[["333159c3.9d2146"],[]]},{"id":"333159c3.9d2146","type":"api-call-service","z":"f431c46a.84ab58","name":"Dimm-lights 10%","server":"fefd8095.1f637","version":1,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.flur_unten","data":"{\"brightness\":10, \"transition\":1}","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":1390,"y":180,"wires":[[]]},{"id":"fefd8095.1f637","type":"server","name":"Home Assistant","legacy":false,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true}]

First flow checks whether the light has been on for more than 2 seconds

Second flow checks whether the light has been off for less than 2 seconds

I hope at least one will suit you

[{"id":"8068a261.8740a","type":"api-current-state","z":"808ee9a3.faef88","name":"On?","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.your_light","state_type":"str","state_location":"lightState","override_payload":"msg","entity_location":"lightData","override_data":"msg","blockInputOverrides":true,"x":340,"y":160,"wires":[["641c55c0.ba30dc"],[]]},{"id":"641c55c0.ba30dc","type":"switch","z":"808ee9a3.faef88","name":"over more than 2 seconds?","property":"lightData.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"gte","v":"2000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":540,"y":160,"wires":[["af11ea7d.61df18"]]},{"id":"d1386972.3bbc88","type":"inject","z":"808ee9a3.faef88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":190,"y":160,"wires":[["8068a261.8740a"]]},{"id":"af11ea7d.61df18","type":"debug","z":"808ee9a3.faef88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":730,"y":160,"wires":[]},{"id":"550886e9.47d128","type":"api-current-state","z":"808ee9a3.faef88","name":"Off?","server":"9405c3fe.d0a6c","version":1,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","override_topic":false,"entity_id":"light.your_light","state_type":"str","state_location":"lightState","override_payload":"msg","entity_location":"lightData","override_data":"msg","blockInputOverrides":true,"x":330,"y":240,"wires":[["5ff80221.20f8dc"],[]]},{"id":"5ff80221.20f8dc","type":"switch","z":"808ee9a3.faef88","name":"for less than 2 seconds?","property":"lightData.timeSinceChangedMs","propertyType":"msg","rules":[{"t":"lte","v":"2000","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":520,"y":240,"wires":[["2056464e.dc20ca"]]},{"id":"59507ca7.e8a984","type":"inject","z":"808ee9a3.faef88","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":240,"wires":[["550886e9.47d128"]]},{"id":"2056464e.dc20ca","type":"debug","z":"808ee9a3.faef88","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":240,"wires":[]},{"id":"9405c3fe.d0a6c","type":"server","name":"Home Assistant","addon":true}]
1 Like

That helped a lot! Thank you

1 Like