Why do something manually, which can happen automatically?
When entering the kitchen, for example, we want the light to turn on automatically, and as long as we are in the kitchen, it is on. When we leave the kitchen, the light should turn off after a while.
This can be solved by using small automation, for example, Node-RED.
The first thing we do is check if there is any motion in the area. To do this in Node-RED we use a node called “event: states”. This checks whether an entity in Home Assistant changes its status. In our case, it should be changed to “on”
When this is changed to “on”, the light in the kitchen is turned on.
In this example, the brightness is set to 90% illumination. We have also added a transition on one second here.
When there is no motion in the area anymore, the automation waits for 3 minutes before checking again if there is any motion in the area. If it is still motion, it only ensures that the light is still on. If there is no motion, the light is dimmed to 25% brightness.
The automation then waits for another minute, before checking again if there is any motion in the area. If there is no motion now, then turn off the light completely.
The automation from Node Node-RED – Copy/Paste
[{"id":"640b7f57.3d556","type":"tab","label":"Flow 2","disabled":false,"info":""},{"id":"fc162a84.38ab58","type":"server-state-changed","z":"640b7f57.3d556","name":"Motion kitchen","server":"7d84d6a9.3d98f8","version":3,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"binary_sensor.node_121_home_security_motion_detection","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":"","forType":"num","forUnits":"minutes","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":false,"ignoreCurrentStateUnavailable":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":110,"y":160,"wires":[["4a1b40a0.c7665"],["f9b3b4c3.63a688"]]},{"id":"f9b3b4c3.63a688","type":"stoptimer","z":"640b7f57.3d556","duration":"3","units":"Minute","payloadtype":"num","payloadval":"0","name":"3 min","x":390,"y":200,"wires":[["1cafb42b.1776fc"],[]]},{"id":"94da0d23.6a49","type":"api-call-service","z":"640b7f57.3d556","name":"Light kitchen 25%","server":"7d84d6a9.3d98f8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.taklys_kjokken_level_light_color_on_off","data":"{\"transition\":10,\"brightness\": \"60\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":200,"wires":[["43aee31e.501efc"]]},{"id":"59bd6e6a.5004c","type":"api-call-service","z":"640b7f57.3d556","name":"Turn off light kitchen","server":"7d84d6a9.3d98f8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_off","entityId":"light.taklys_kjokken_level_light_color_on_off","data":"{\"transition\":10}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":900,"y":260,"wires":[[]]},{"id":"43aee31e.501efc","type":"stoptimer","z":"640b7f57.3d556","duration":"1","units":"Minute","payloadtype":"num","payloadval":"0","name":"1 min","x":390,"y":260,"wires":[["dae2cf18.d13ec"],[]]},{"id":"4a1b40a0.c7665","type":"api-call-service","z":"640b7f57.3d556","name":"Light kitchen on 90%","server":"7d84d6a9.3d98f8","version":3,"debugenabled":false,"service_domain":"light","service":"turn_on","entityId":"light.taklys_kjokken_level_light_color_on_off","data":"{\"transition\":1, \"brightness_pct\": \"90\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":880,"y":120,"wires":[[]]},{"id":"1cafb42b.1776fc","type":"api-current-state","z":"640b7f57.3d556","name":"No motion","server":"7d84d6a9.3d98f8","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.node_121_home_security_motion_detection","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":550,"y":200,"wires":[["94da0d23.6a49"],["4a1b40a0.c7665"]]},{"id":"dae2cf18.d13ec","type":"api-current-state","z":"640b7f57.3d556","name":"No motion","server":"7d84d6a9.3d98f8","version":2,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.node_121_home_security_motion_detection","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"}],"x":530,"y":260,"wires":[["59bd6e6a.5004c"],["4a1b40a0.c7665"]]},{"id":"7d84d6a9.3d98f8","type":"server","name":"Home Assistant"}]