(NR) Flow to temporarily increase light brightness constantly failing, why?

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?

Making a couple of changes to the trigger node and changing the connection should fix your problem.

[{"id":"4b73c9b419648040","type":"tab","label":"Växtlampa nattetid brightness","disabled":false,"info":"","env":[]},{"id":"a27606769946ca0a","type":"server-state-changed","z":"4b73c9b419648040","name":"","server":"","version":5,"outputs":2,"exposeAsEntityConfig":"","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"}],"entityId":"binary_sensor.rorelsesensor_ovan_hall_motion","entityIdType":"exact","x":340,"y":280,"wires":[["e3127f9ee5d55aed"],["e3127f9ee5d55aed"]]},{"id":"5a2e8de8e7218666","type":"api-call-service","z":"4b73c9b419648040","name":"Increase brightness","server":"","version":5,"debugenabled":false,"areaId":["vaxtlampa_citrontrad"],"deviceId":[],"entityId":[],"data":"{\"brightness_pct\":\"100\",\"transition\":\"0\"}","dataType":"json","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","domain":"light","service":"turn_on","x":1475.9999771118164,"y":125.00000190734863,"wires":[[]]},{"id":"e3127f9ee5d55aed","type":"trigger","z":"4b73c9b419648040","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"10","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":570,"y":280,"wires":[["91c9946b79cf761a"],["1e77e37f4f876871"]]},{"id":"97ba94990ec0f948","type":"api-call-service","z":"4b73c9b419648040","name":"return brightness to previous","server":"","version":5,"debugenabled":false,"areaId":["vaxtlampa_citrontrad"],"deviceId":[],"entityId":[],"data":"{\"brightness\":data.attributes.brightness,\"transition\":0}","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","domain":"light","service":"turn_on","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":"","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"]]}]

Much appreciated!

Unfortunately that change alone didn’t fix it, the same thing happens.

But I also changed the variable cheked in the “if previous brightness != 255” node, from

flow.lightBrightness.attributes.brightness

To

$entities(‘light.extended_color_light_1_2’).attributes.brightness

I had previously used a change node to “get” a flow variable before the flow had actually set it and it seemed to work, which is why I tried something similiar here. But at least in this current flow it didn’t work which is why that node always defaulted to the “else” flow, setting the brightness without first setting the flow variable.

It works now, hopefully it’ll work in the coming days as well.

Oh and by the way, I got the $entities tip from you in a different thread regarding the same flow, so thanks a lot for your help in both threads.

Question: Why did you change the trigger this way? What is the actual difference? It seems to be that this would be more a matter of preference, but the same things happens in practice? Unless I am misunderstanding something.

Cheers!

Actually, not that I’ve used the flow for a few hours I find it’s not working. The flow variable at least seems to save like it should now but there are two issues with the flow.

[{"id":"d87dbbe3bfed051a","type":"change","z":"2d0366dc01348d0a","name":"","rules":[{"t":"set","p":"data","pt":"msg","to":"lightBrightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":480,"wires":[["4a5433a716344837","c46c83926868f531"]]}]
  1. The lights turn off even with continued motion. The reason seems to be that the motion sensor switches to “on” which starts the trigger 15 sec count. If motion keeps getting detected it simply stays on (not re-sending the on state, but simply not sending anything). This in turn makes the 15 sec trigger keep counting and trigger the “off” flow since nothing resets it and it doesn’t get new messages because the sensor is simply staying on.

  2. If the lights are at minimum brightness (1 out of 255) then the “restore previous brightness node” actually turns off the lights. Debug nodes show that flow.lightBrightness variable is set to 0 in those cases, I have no idea why because the saved brightness should be 1.

It’s interesting that there are so many problems with what I thought was going to be a very simple flow.

Motion sensors can have a cool down timer on new detections and it can be quite long.
My suggestion is to just have the trigger node and then a debug node after to see what happens.
It might trigger each 30 seconds or each minute or whatever, but that is then the lowest your delay can be.
A few motion sensor stays on and then send an off state when they decide that there is no motion. If that is the case, then you need to react to that off state to turn the light off instead.

I’m pretty sure my motion sensor is the latter example, but I’ll double check next time around.

The problem I ran into with reacting to the off state is that I couldn’t find a simple way to both react correctly to the off state but also to the on state. I always ended up somehow rewriting the flow.lightBrightness or accidentally cancelling the trigger node altogether.

I tried to fix it, but it’s still sometimes “resetting” the light to maximum brightness sometimes. It seems to be connected to when people walk in and out of the sensor during the flow, but other than that I’m not sure.

[{"id":"2d0366dc01348d0a","type":"tab","label":"Växtlampa nattetid backup","disabled":false,"info":"Stänger av sig själv trots rörelse (trigger 15s resettas inte)","env":[]},{"id":"b2c5b33ddf5ac4b5","type":"server-state-changed","z":"2d0366dc01348d0a","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":false,"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":230,"y":300,"wires":[["525a3343de132d1d"],["525a3343de132d1d"]]},{"id":"c6a1fe438877f0c1","type":"api-call-service","z":"2d0366dc01348d0a","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":1435.9999771118164,"y":165.00000190734863,"wires":[[]]},{"id":"4a5433a716344837","type":"api-call-service","z":"2d0366dc01348d0a","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":1300,"y":480,"wires":[["4c7408fbc2130ef6"]]},{"id":"927fe204ea982e74","type":"api-current-state","z":"2d0366dc01348d0a","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":1170,"y":80,"wires":[["c6a1fe438877f0c1"]]},{"id":"d87dbbe3bfed051a","type":"change","z":"2d0366dc01348d0a","name":"","rules":[{"t":"set","p":"data","pt":"msg","to":"lightBrightness","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":480,"wires":[["4a5433a716344837"]]},{"id":"4c7408fbc2130ef6","type":"debug","z":"2d0366dc01348d0a","name":"Brightness variable value?","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"data.attributes.brightness","targetType":"jsonata","statusVal":"","statusType":"auto","x":1780,"y":480,"wires":[]},{"id":"617a67e393ed18a0","type":"switch","z":"2d0366dc01348d0a","name":"If brightness != 255","property":"$entities('light.extended_color_light_1_2').attributes.brightness","propertyType":"env","rules":[{"t":"neq","v":"255","vt":"num"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":830,"y":160,"wires":[["927fe204ea982e74"],["c6a1fe438877f0c1"]]},{"id":"525a3343de132d1d","type":"trigger","z":"2d0366dc01348d0a","name":"","op1":"","op2":"off","op1type":"pay","op2type":"str","duration":"15","extend":true,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":2,"x":590,"y":300,"wires":[["617a67e393ed18a0"],["e29dc9ed073249b6"]]},{"id":"e29dc9ed073249b6","type":"api-current-state","z":"2d0366dc01348d0a","name":"Is the sensor really off?","server":"738c03d.3cc58fc","version":3,"outputs":2,"halt_if":"off","halt_if_type":"str","halt_if_compare":"is","entity_id":"binary_sensor.rorelsesensor_ovan_hall_motion","state_type":"str","blockInputOverrides":false,"outputProperties":[{"property":"payload","propertyType":"msg","value":"","valueType":"entityState"},{"property":"data","propertyType":"msg","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":590,"y":380,"wires":[["d87dbbe3bfed051a"],["525a3343de132d1d"]]},{"id":"738c03d.3cc58fc","type":"server","name":"Home Assistant","addon":true}]

Anyone have any idea what’s wrong?

Way too complicated!

I have not imported your flow, so I can not see how you store the current brightness value in that current state node. If you do not store it in a flow or global variable, then it will just be gone with the end of that flow line.