I created a flow that is supposed to temporarily increase the brightness of a group of lamps upon a motion sensor trigger, and after a while reset the brightness.
[{"id":"4b73c9b419648040","type":"tab","label":"Växtlampa nattetid brightness","disabled":false,"info":"","env":[]},{"id":"a27606769946ca0a","type":"server-state-changed","z":"4b73c9b419648040","name":"","server":"738c03d.3cc58fc","version":5,"outputs":2,"exposeAsEntityConfig":"","entityId":"binary_sensor.rorelsesensor_ovan_hall_motion","entityIdType":"exact","outputInitially":false,"stateType":"str","ifState":"on","ifStateType":"str","ifStateOperator":"is","outputOnlyOnStateChange":true,"for":"","forType":"num","forUnits":"seconds","ignorePrevStateNull":false,"ignorePrevStateUnknown":false,"ignorePrevStateUnavailable":false,"ignoreCurrentStateUnknown":true,"ignoreCurrentStateUnavailable":true,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","value":"","valueType":"eventData"},{"property":"topic","propertyType":"msg","value":"","valueType":"triggerId"}],"x":450,"y":280,"wires":[["91c9946b79cf761a"],["e3127f9ee5d55aed"]]},{"id":"5a2e8de8e7218666","type":"api-call-service","z":"4b73c9b419648040","name":"Increase brightness","server":"738c03d.3cc58fc","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":["vaxtlampa_citrontrad"],"deviceId":[],"entityId":[],"data":"{\"brightness_pct\":\"100\",\"transition\":\"0\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1475.9999771118164,"y":125.00000190734863,"wires":[[]]},{"id":"e3127f9ee5d55aed","type":"trigger","z":"4b73c9b419648040","name":"","op1":"","op2":"off","op1type":"str","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":850,"y":460,"wires":[["1e77e37f4f876871"]]},{"id":"97ba94990ec0f948","type":"api-call-service","z":"4b73c9b419648040","name":"return brightness to previous","server":"738c03d.3cc58fc","version":5,"debugenabled":false,"domain":"light","service":"turn_on","areaId":["vaxtlampa_citrontrad"],"deviceId":[],"entityId":[],"data":"{\"brightness\":data.attributes.brightness,\"transition\":0}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":1520,"y":460,"wires":[["f1e9a107263c786a"]]},{"id":"da177a6cf90533c4","type":"debug","z":"4b73c9b419648040","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1500,"y":580,"wires":[]},{"id":"24cbb73e5d47669a","type":"api-current-state","z":"4b73c9b419648040","name":"Save previous brightness","server":"738c03d.3cc58fc","version":3,"outputs":1,"halt_if":"","halt_if_type":"str","halt_if_compare":"is","entity_id":"light.extended_color_light_1_2","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":1210,"y":40,"wires":[["5a2e8de8e7218666"]]},{"id":"faf1cb82832941a4","type":"change","z":"4b73c9b419648040","name":"","rules":[{"t":"set","p":"data","pt":"msg","to":"lightBrightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1270,"y":460,"wires":[["97ba94990ec0f948","da177a6cf90533c4"]]},{"id":"f1e9a107263c786a","type":"debug","z":"4b73c9b419648040","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"\"brightness\"","targetType":"jsonata","statusVal":"","statusType":"auto","x":1760,"y":460,"wires":[]},{"id":"1e77e37f4f876871","type":"switch","z":"4b73c9b419648040","name":"Check for off message","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":1060,"y":460,"wires":[["faf1cb82832941a4"]]},{"id":"91c9946b79cf761a","type":"switch","z":"4b73c9b419648040","name":"If previous brightness != 255","property":"lightBrightness.attributes.brightness","propertyType":"flow","rules":[{"t":"neq","v":"255","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":900,"y":120,"wires":[["24cbb73e5d47669a"],["5a2e8de8e7218666"]]},{"id":"738c03d.3cc58fc","type":"server","name":"Home Assistant","addon":true}]
It worked for a day or two, but now it’s constantly failing. What happens is that the lights are not reset to the original brightness.
The top part of the flow where the motion sensor triggers increased brightness works, its the bottom part of the flow with the reset that constantly fails.
I know one bug came from the fact that the motion sensor switched off, and if it was triggered again during the 10 sec wait then it overwrote the previous brightness variable with the current brightness (100%) which caused it to stay bright. That’s what I was trying to fix with the condition (if previous brightness != 255).
I also had to add the “Check for off message” because the trigger sent the value “1” as soon as it started the wait and the “set msg.data” overwrote the number 1 with the previous brightness variable which then made the flow continue as soon as the motion sensor turned off, skipping the wait.
Any ideas?