Hi forum. New user here
I hope there is someone out there with some creative juices and relevant coding skills (note: I have none) that could help me improve my current setup.
I have the following flow for motion-based lighting in my living room.
When motion is no longer detected, the lights are dimmed to 50% for 10 seconds, then turned off. Before dimming, the current brightness value is stored in context and then called when motion is detected again (so lights revert to 100% brightness).
Sometimes, I might turn the lights on manually and adjust the brightness before walking into the room. When motion is detected (i.e. I walk in), the brightness will then reset back to the value called by the switch node.
What I'd like to be able to do is something like this:
Motion detected > Check if timeout active (during dimming phase) > If yes, double the brightness, if not then use existing (current) brightness value.
I'd be very grateful for any suggestions. Code below:
[{"id":"f04d96250610a63c","type":"api-call-service","z":"a64cb88673a8ada8","name":"Turn on light","server":"6e6a7fd05cb77906","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights"],"data":"{\"brightness\":msg.data.attributes.brightness}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":510,"y":60,"wires":[[]]},{"id":"60a19480ee470b41","type":"api-call-service","z":"a64cb88673a8ada8","name":"Turn off light","server":"6e6a7fd05cb77906","version":5,"debugenabled":false,"domain":"light","service":"turn_off","areaId":[],"deviceId":[],"entityId":["light.living_room_lights"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":510,"y":200,"wires":[[]]},{"id":"c06ea1849c9aa913","type":"trigger-state","z":"a64cb88673a8ada8","name":"Light turn off rules","server":"6e6a7fd05cb77906","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":["input_boolean.toggle_auto_living","input_boolean.nighttime","binary_sensor.shmos_living_motion","media_player.sony_bravia_tv"],"entityidfiltertype":"list","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"input_boolean.toggle_auto_living","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"media_player.sony_bravia_tv","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"off"},{"targetType":"entity_id","targetValue":"binary_sensor.shmos_living_motion","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is_not","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"input_boolean.nighttime","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":130,"y":140,"wires":[["d6e52e666ac54149"],[]]},{"id":"a56933a07bec11b1","type":"trigger-state","z":"a64cb88673a8ada8","name":"Light turn on rules","server":"6e6a7fd05cb77906","version":2,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityid":["input_boolean.toggle_auto_living","input_boolean.nighttime","binary_sensor.shmos_living_motion"],"entityidfiltertype":"list","debugenabled":false,"constraints":[{"targetType":"entity_id","targetValue":"input_boolean.toggle_auto_living","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"input_boolean.nighttime","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"},{"targetType":"entity_id","targetValue":"binary_sensor.shmos_living_motion","propertyType":"current_state","propertyValue":"new_state.state","comparatorType":"is","comparatorValueDatatype":"str","comparatorValue":"on"}],"inputs":0,"outputs":2,"customoutputs":[],"outputinitially":false,"state_type":"str","enableInput":false,"x":130,"y":60,"wires":[["d6e52e666ac54149","be221a3e3f6ab66a"],[]]},{"id":"d6e52e666ac54149","type":"trigger","z":"a64cb88673a8ada8","name":"","op1":"dim","op2":"off","op1type":"str","op2type":"str","duration":"10","extend":false,"overrideDelay":false,"units":"s","reset":"on","bytopic":"all","topic":"topic","outputs":2,"x":330,"y":140,"wires":[["da173965314d66fc"],["60a19480ee470b41"]]},{"id":"be221a3e3f6ab66a","type":"change","z":"a64cb88673a8ada8","name":"get brightness","rules":[{"t":"set","p":"data","pt":"msg","to":"lightBrightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":60,"wires":[["f04d96250610a63c"]]},{"id":"99d231e4c9f0a000","type":"api-call-service","z":"a64cb88673a8ada8","name":"Turn on light","server":"6e6a7fd05cb77906","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":[],"deviceId":[],"entityId":["light.living_room_lights"],"data":"{\"brightness\":msg.data.attributes.brightness/2}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":670,"y":140,"wires":[[]]},{"id":"da173965314d66fc","type":"api-current-state","z":"a64cb88673a8ada8","name":"Light on?","server":"6e6a7fd05cb77906","version":3,"outputs":2,"halt_if":"on","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.living_room_lights","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"entity"},{"property":"lightBrightness","propertyType":"flow","value":"","valueType":"entity"}],"for":"0","forType":"num","forUnits":"minutes","override_topic":false,"state_location":"payload","override_payload":"msg","entity_location":"data","override_data":"msg","x":500,"y":140,"wires":[["99d231e4c9f0a000"],[]]},{"id":"6e6a7fd05cb77906","type":"server","name":"Home Assistant","version":5,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":false,"heartbeatInterval":"30","areaSelector":"friendlyName","deviceSelector":"friendlyName","entitySelector":"friendlyName","statusSeparator":"at: ","statusYear":"hidden","statusMonth":"short","statusDay":"numeric","statusHourCycle":"h23","statusTimeFormat":"h:m","enableGlobalContextStore":true}]