Hi. I'm learning NodeRED (in HomeAssistant) and trying to create simple flow for dimming lights with single button. Seems like noob task. Right now I'm ignoring long/short press functionality, instead I want to achieve dimming toggled up/down on hold. So on first button hold it will set brightness up, on second down, on third up etc. To do that I'm using flow variable. So on press with switch node I'm checking previous dimming direction, and then in change node I'm changing it to opposite direction. But I have no idea why this does not work. On every click it's dimming down. Flow variable is not stored between start/end of flow?
I probably can simplify that by installing toggle node, or just use ready flow, but that's not the point. I just want to know what I did wrong
[{"id":"27cee93afcf45c24","type":"server-state-changed","z":"afc2c32c7f4bbb52","name":"","server":"60f2db74.303074","version":4,"exposeToHomeAssistant":false,"haConfig":[{"property":"name","value":""},{"property":"icon","value":""}],"entityidfilter":"light.living_room_cabinet_light_dimmer_switch_l1","entityidfiltertype":"exact","outputinitially":false,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":true,"for":"0","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":230,"y":440,"wires":[["b791bbb9cca25b37"]]},{"id":"4d5b76d9615eb99d","type":"switch","z":"afc2c32c7f4bbb52","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1130,"y":460,"wires":[["fb733d490a5b45cc"],["235a0988af0df69f"]]},{"id":"7d7a0d7bb7d97bfc","type":"mqtt out","z":"afc2c32c7f4bbb52","name":"","topic":"zigbee2mqtt/kitchen-countertop-light-power-supply/set","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"eca6af44.5297b","x":2040,"y":440,"wires":[]},{"id":"020964a3bb283ff6","type":"change","z":"afc2c32c7f4bbb52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"brightness_move\": 40}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1520,"y":320,"wires":[["7d7a0d7bb7d97bfc","3a9e265d0ccecff3"]]},{"id":"235a0988af0df69f","type":"change","z":"afc2c32c7f4bbb52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"brightness_move\": 0}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1340,"y":480,"wires":[["7d7a0d7bb7d97bfc","3a9e265d0ccecff3"]]},{"id":"591c166261892b8a","type":"change","z":"afc2c32c7f4bbb52","name":"set direction up","rules":[{"t":"set","p":"direction","pt":"flow","to":"up","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":920,"y":500,"wires":[["4d5b76d9615eb99d"]]},{"id":"b791bbb9cca25b37","type":"switch","z":"afc2c32c7f4bbb52","name":"last direction","property":"direction","propertyType":"flow","rules":[{"t":"eq","v":"up","vt":"str"},{"t":"eq","v":"down","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":3,"x":610,"y":440,"wires":[["19d7f28611a06903","c162d98f2e1fcd1e"],["591c166261892b8a","c162d98f2e1fcd1e"],[]]},{"id":"19d7f28611a06903","type":"change","z":"afc2c32c7f4bbb52","name":"set direction down","rules":[{"t":"set","p":"direction","pt":"flow","to":"down","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":910,"y":420,"wires":[["4d5b76d9615eb99d"]]},{"id":"fb733d490a5b45cc","type":"switch","z":"afc2c32c7f4bbb52","name":"","property":"direction","propertyType":"flow","rules":[{"t":"eq","v":"up","vt":"str"},{"t":"eq","v":"down","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":1330,"y":340,"wires":[["020964a3bb283ff6"],["2871a0109e9f845b"]]},{"id":"2871a0109e9f845b","type":"change","z":"afc2c32c7f4bbb52","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"brightness_move\": -40}","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1520,"y":360,"wires":[["7d7a0d7bb7d97bfc","3a9e265d0ccecff3"]]},{"id":"3a9e265d0ccecff3","type":"debug","z":"afc2c32c7f4bbb52","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1900,"y":340,"wires":[]},{"id":"c162d98f2e1fcd1e","type":"debug","z":"afc2c32c7f4bbb52","name":"debug 7","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1020,"y":260,"wires":[]},{"id":"4f6bd72b987b29c6","type":"inject","z":"afc2c32c7f4bbb52","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":230,"y":240,"wires":[["b791bbb9cca25b37"]]},{"id":"586620399cde0dcf","type":"inject","z":"afc2c32c7f4bbb52","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":230,"y":280,"wires":[["b791bbb9cca25b37"]]},{"id":"60f2db74.303074","type":"server","name":"Home Assistant","version":4,"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"},{"id":"eca6af44.5297b","type":"mqtt-broker","name":"MQTT","broker":"homeassistant.local","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]