I am trying to save the brightness data from the Current_state node and use it in an automation where you increase and decrease the brightness by a percentage.
Where i am stuck is saving the current brightness and state of device.
You can also find my flow below:
[{“id”:“ba081bb8.8696c8”,“type”:“tab”,“label”:“IKEA remote v2”,“disabled”:false,“info”:""},{“id”:“7029c8e8.0d1b28”,“type”:“switch”,“z”:“ba081bb8.8696c8”,“name”:“Action”,“property”:“payload”,“propertyType”:“msg”,“rules”:[{“t”:“eq”,“v”:“toggle”,“vt”:“str”},{“t”:“eq”,“v”:“arrow_right_click”,“vt”:“str”},{“t”:“eq”,“v”:“arrow_left_click”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_up_click”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_down_click”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_up_hold”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_up_release”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_down_hold”,“vt”:“str”},{“t”:“eq”,“v”:“brightness_down_release”,“vt”:“str”},{“t”:“eq”,“v”:“arrow_right_release”,“vt”:“str”},{“t”:“eq”,“v”:“arrow_left_release”,“vt”:“str”}],“checkall”:“true”,“repair”:false,“outputs”:11,“x”:350,“y”:390,“wires”:[[“1ca5f47f.03ee5c”],[“8ecffc87.3259a”],[“55f55d58.d6bb54”],[“985a53ca.f50c2”],[“61b92a1b.088854”],[“41d080e7.13669”,“ae8ff38a.544aa”],[“91759de8.b98cf”],[“41d080e7.13669”,“e22c7081.0a47c”],[“91759de8.b98cf”],[“12db6c47.dd0874”],[“12db6c47.dd0874”]]},{“id”:“1ca5f47f.03ee5c”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Toggle1”,“func”:“var device = flow.get(“activeDevice”);\nmsg.payload={“service”:“toggle”, “entity_id”:device};\nreturn msg;\n\n\n\n”,“outputs”:1,“noerr”:0,“x”:870,“y”:270,“wires”:[[“a570b72c.a34f58”,“2a9106bb.3e2afa”]]},{“id”:“61b92a1b.088854”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Brightness DOWN 50”,“func”:“var device = flow.get(“activeDevice”);\nvar currentState = device + “_brightness”;\nvar current = flow.get(currentState);\n\n\nvar brightness = current - 50;\nbrightness = 256\n\nif(brightness > 255){\n brightness = 100;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\n\n\nif(brightness < 0){\n brightness = 0;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\nelse{\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\n”,“outputs”:1,“noerr”:0,“x”:910,“y”:345,“wires”:[[“2a9106bb.3e2afa”,“c799c691.721ab8”]]},{“id”:“985a53ca.f50c2”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Brightness UP 50”,“func”:“var device = flow.get(“activeDevice”);\nvar currentState = device + “_brightness”;\nvar current = flow.get(currentState);\n\nvar brightness = current + 50;\nbrightness = 256\n\nif(brightness > 255){\n brightness = 255;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\n\nif(brightness < 0){\n brightness = 0;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\nelse{\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\n\n”,“outputs”:1,“noerr”:0,“x”:900,“y”:315,“wires”:[[“2a9106bb.3e2afa”,“c799c691.721ab8”]]},{“id”:“55f55d58.d6bb54”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“toggle devices --”,“func”:“var devices = global.get(“ZigbeeLights”);\n\nvar x = devices.length - 1;\nvar count = flow.get(“count”);\nvar y = isNaN(count);\n\nif(y === true ){\n count = 0;\n flow.set(“count”, count);\n}\n\nvar currentDevice = devices[count];\ncount–;\n\nif(count < 0){\n count = x;\n}\n\nflow.set(“count”, count);\nflow.set(“activeDevice”, currentDevice);\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:545,“y”:270,“wires”:[[]]},{“id”:“8ecffc87.3259a”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“toggle devices ++”,“func”:“var devices = global.get(“ZigbeeLights”);\n\nvar x = devices.length - 1;\nvar count = flow.get(“count”);\nvar y = isNaN(count);\n\nif(y === true ){\n count = 0;\n flow.set(“count”, count);\n}\n\nvar currentDevice = devices[count];\ncount++;\n\nif(count > x){\n count = 0;\n}\n\nflow.set(“count”, count);\nflow.set(“activeDevice”, currentDevice);\n\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:555,“y”:225,“wires”:[[]]},{“id”:“675b4312.f8843c”,“type”:“delay”,“z”:“ba081bb8.8696c8”,“name”:"",“pauseType”:“delay”,“timeout”:“500”,“timeoutUnits”:“milliseconds”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“x”:1060,“y”:510,“wires”:[[“4c460d0c.6a34f4”]]},{“id”:“cd5e817.5e4948”,“type”:“delay”,“z”:“ba081bb8.8696c8”,“name”:"",“pauseType”:“delay”,“timeout”:“500”,“timeoutUnits”:“milliseconds”,“rate”:“1”,“nbRateUnits”:“1”,“rateUnits”:“second”,“randomFirst”:“1”,“randomLast”:“5”,“randomUnits”:“seconds”,“drop”:false,“x”:1060,“y”:540,“wires”:[[“2bb124ce.f9522c”]]},{“id”:“ae8ff38a.544aa”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Brightness up”,“func”:“var device = flow.get(“activeDevice”);\nvar currentState = device + “_brightness”;\nvar current = flow.get(currentState);\n\nvar brightness = current + 30;\n\n\nif(brightness > 255 || msg.feeedback == 255){\n brightness = 255;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n msg.feedback = {\n “brightness”: brightness\n };\n return msg;\n}\n\nif(brightness < 0 || msg.feeedback === 0){\n brightness = 0;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n msg.feedback = {\n “brightness”: brightness\n };\n return msg;\n}\nelse{\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n msg.feedback = {\n “brightness”: brightness\n };\n return msg;\n}\n”,“outputs”:1,“noerr”:0,“x”:890,“y”:390,“wires”:[[“2480aefe.53c362”,“2a9106bb.3e2afa”]]},{“id”:“e22c7081.0a47c”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Brightness down”,“func”:“var device = flow.get(“activeDevice”);\nvar currentState = device + “_brightness”;\nvar current = flow.get(currentState);\n\n\nvar brightness = current - 30;\n\n\nif(brightness > 255 || msg.feeedback == 255){\n brightness = 255;\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\n\nif(brightness < 0|| msg.feeedback === 0){\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n return msg;\n}\nelse{\n msg.payload = {“service”:“turn_on”, “entity_id”:device, “brightness”: brightness};\n msg.feedback = {\n “brightness”: brightness\n };\n return msg;\n}”,“outputs”:1,“noerr”:0,“x”:900,“y”:420,“wires”:[[“167aace4.04f2e3”,“2a9106bb.3e2afa”]]},{“id”:“2bb124ce.f9522c”,“type”:“switch”,“z”:“ba081bb8.8696c8”,“name”:“HoldUP”,“property”:“press”,“propertyType”:“flow”,“rules”:[{“t”:“true”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:1215,“y”:540,“wires”:[[“ae8ff38a.544aa”]]},{“id”:“4c460d0c.6a34f4”,“type”:“switch”,“z”:“ba081bb8.8696c8”,“name”:“HoldUP”,“property”:“press”,“propertyType”:“flow”,“rules”:[{“t”:“true”}],“checkall”:“true”,“repair”:false,“outputs”:1,“x”:1215,“y”:510,“wires”:[[“e22c7081.0a47c”]]},{“id”:“167aace4.04f2e3”,“type”:“change”,“z”:“ba081bb8.8696c8”,“name”:“msg.feedback”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“feedback”,“tot”:“msg”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:890,“y”:510,“wires”:[[“675b4312.f8843c”]]},{“id”:“2480aefe.53c362”,“type”:“change”,“z”:“ba081bb8.8696c8”,“name”:“msg.feedback”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“feedback”,“tot”:“msg”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:890,“y”:540,“wires”:[[“cd5e817.5e4948”]]},{“id”:“41d080e7.13669”,“type”:“change”,“z”:“ba081bb8.8696c8”,“name”:“start”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“true”,“tot”:“bool”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:515,“y”:525,“wires”:[[“cee3023c.be0b8”]]},{“id”:“91759de8.b98cf”,“type”:“change”,“z”:“ba081bb8.8696c8”,“name”:“stop”,“rules”:[{“t”:“set”,“p”:“payload”,“pt”:“msg”,“to”:“false”,“tot”:“bool”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:515,“y”:570,“wires”:[[“cee3023c.be0b8”]]},{“id”:“cee3023c.be0b8”,“type”:“change”,“z”:“ba081bb8.8696c8”,“name”:“Hold UP”,“rules”:[{“t”:“set”,“p”:“press”,“pt”:“flow”,“to”:“payload”,“tot”:“msg”}],“action”:"",“property”:"",“from”:"",“to”:"",“reg”:false,“x”:675,“y”:540,“wires”:[[]]},{“id”:“12db6c47.dd0874”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Fav Devices”,“func”:“var x = msg.payload.action;\n\nif(x === “arrow_right_release”){\n flow.set(“activeDevice”, “light.led_kitchen”); \n}\n\nif(x === “arrow_left_release”){\n flow.set(“activeDevice”, “light.led_hallway”); \n}\nreturn msg;”,“outputs”:1,“noerr”:0,“x”:535,“y”:465,“wires”:[[]]},{“id”:“ae7b13d8.753ac”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Set devices”,“func”:“var x = msg.payload;\nglobal.set(“ZigbeeLights”, x);\n”,“outputs”:1,“noerr”:0,“x”:370,“y”:60,“wires”:[[]]},{“id”:“d8e27aae.6083f8”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:“Yeelight Devices”,“topic”:"",“payload”:"[“light.led_kitchen”,“light.led_hallway”]",“payloadType”:“json”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:200,“y”:60,“wires”:[[“ae7b13d8.753ac”]]},{“id”:“a570b72c.a34f58”,“type”:“api-call-service”,“z”:“ba081bb8.8696c8”,“name”:"",“server”:“710f5d9e.1377e4”,“version”:1,“debugenabled”:false,“service_domain”:“homeassistant”,“service”:"",“entityId”:"{{payload.entity_id}}",“data”:"",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1330,“y”:220,“wires”:[[]]},{“id”:“980b76b6.fb0358”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:"",“topic”:"",“payload”:“toggle”,“payloadType”:“str”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:90,“y”:380,“wires”:[[“7029c8e8.0d1b28”]]},{“id”:“ccc7c1de.f2e77”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:"",“topic”:"",“payload”:“arrow_right_release”,“payloadType”:“str”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:110,“y”:440,“wires”:[[“7029c8e8.0d1b28”]]},{“id”:“2b2fc3ca.47789c”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:"",“topic”:"",“payload”:“arrow_right_click”,“payloadType”:“str”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:160,“y”:520,“wires”:[[“7029c8e8.0d1b28”]]},{“id”:“2a9106bb.3e2afa”,“type”:“api-call-service”,“z”:“ba081bb8.8696c8”,“name”:"",“server”:“710f5d9e.1377e4”,“version”:1,“debugenabled”:false,“service_domain”:“homeassistant”,“service”:"",“entityId”:"{{payload.entity_id}}",“data”:"{“brightness”:{{payload.brightness}}}",“dataType”:“json”,“mergecontext”:"",“output_location”:"",“output_location_type”:“none”,“mustacheAltTags”:false,“x”:1330,“y”:360,“wires”:[[]]},{“id”:“cdf3ce46.088c9”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Save Value”,“func”:“var state = msg.payload.state;\nvar brightness = msg.payload.brightness;\n\nflow.set(“light.led_hallway_brightness”, brightness);\nflow.set(“light.led_hallway_state”, state);”,“outputs”:1,“noerr”:0,“x”:390,“y”:125,“wires”:[[]]},{“id”:“3d26682e.f1fa98”,“type”:“function”,“z”:“ba081bb8.8696c8”,“name”:“Save Value”,“func”:“var state = msg.payload.state;\nvar brightness = msg.payload.brightness;\n\nflow.set(“light.led_kitchen_brightness”, brightness);\nflow.set(“light.led_kitchen_state”, state);\n”,“outputs”:1,“noerr”:0,“x”:380,“y”:185,“wires”:[[]]},{“id”:“e6d1402c.226b”,“type”:“api-current-state”,“z”:“ba081bb8.8696c8”,“name”:"",“server”:“710f5d9e.1377e4”,“version”:1,“outputs”:1,“halt_if”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“override_topic”:false,“entity_id”:“light.led_hallway”,“state_type”:“num”,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“blockInputOverrides”:false,“x”:160,“y”:125,“wires”:[[“cdf3ce46.088c9”]]},{“id”:“6f21d36a.3e0b7c”,“type”:“api-current-state”,“z”:“ba081bb8.8696c8”,“name”:"",“server”:“710f5d9e.1377e4”,“version”:1,“outputs”:1,“halt_if”:"",“halt_if_type”:“str”,“halt_if_compare”:“is”,“override_topic”:false,“entity_id”:“light.led_kitchen”,“state_type”:“num”,“state_location”:“payload”,“override_payload”:“msg”,“entity_location”:“data”,“override_data”:“msg”,“blockInputOverrides”:false,“x”:160,“y”:185,“wires”:[[“3d26682e.f1fa98”]]},{“id”:“7c4a407a.1a2d7”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:"",“topic”:"",“payload”:“brightness_up_click”,“payloadType”:“str”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:150,“y”:620,“wires”:[[“7029c8e8.0d1b28”]]},{“id”:“c799c691.721ab8”,“type”:“debug”,“z”:“ba081bb8.8696c8”,“name”:"",“active”:true,“tosidebar”:true,“console”:false,“tostatus”:false,“complete”:“false”,“x”:1370,“y”:440,“wires”:[]},{“id”:“c711eabf.7ab5c8”,“type”:“inject”,“z”:“ba081bb8.8696c8”,“name”:"",“topic”:"",“payload”:“brightness_down_click”,“payloadType”:“str”,“repeat”:"",“crontab”:"",“once”:false,“onceDelay”:0.1,“x”:140,“y”:660,“wires”:[[“7029c8e8.0d1b28”]]},{“id”:“710f5d9e.1377e4”,“type”:“server”,“z”:"",“name”:“Home Assistant”,“addon”:true}]