Error: Invalid property expression: unexpected ' ' at position 2

Hi guys, I have nicked some flows to control my ikea lights with the ikea 5 button remote, however the flows are a few years old now and im getting the above message.
The original code was state = “OFF”; the helper suggested const state = “OFF”;
But I still have the same issue, unless it pulls from a previous Function node

var device = flow.get("activeDevice");
var currentState = device + "_state";
var current = flow.get(currentState);



if(current === "ON"){
    const state = "OFF";
    msg.topic = "zigbee2mqtt/" + device + "/set";
    msg.payload = {
        "state": state
    };
    return msg;
}

if(current === "OFF" || undefined){
    const state = "ON";
    msg.topic = "zigbee2mqtt/" + device + "/set";
    msg.payload = {
        "state": state
    };
    return msg;
}
[{"id":"ed250eb3.082ba","type":"tab","label":"IKEA remote","disabled":false,"info":""},{"id":"bd7a54e5d349b464","type":"mqtt in","z":"ed250eb3.082ba","name":"Remote IKEA","topic":"zigbee2mqtt/Jo Office Multi function Button","qos":"0","datatype":"json","broker":"867c194d39b2d479","nl":false,"rap":false,"inputs":0,"x":90,"y":120,"wires":[["92fb89f2272b056d","92701d210a4102f9"]]},{"id":"92fb89f2272b056d","type":"debug","z":"ed250eb3.082ba","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":420,"y":120,"wires":[]},{"id":"92701d210a4102f9","type":"switch","z":"ed250eb3.082ba","name":"Action","property":"payload.action","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":170,"y":280,"wires":[["caa1c0e529aa41b0"],[],[],["14be4b8994f6e394"],["beebe0d3db04c3bc"],[],[],[],[],[],[]]},{"id":"beebe0d3db04c3bc","type":"function","z":"ed250eb3.082ba","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;\n\n\nif(brightness > 255){\n    brightness = 255;\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\n\nif(brightness < 0){\n    brightness = 0;\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\nelse{\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":460,"y":300,"wires":[["7dd73b48e8a1dfb0"]]},{"id":"14be4b8994f6e394","type":"function","z":"ed250eb3.082ba","name":"Brightness UP 50","func":"var device = flow.get(\"activeDevice\");\nvar currentState = device + \"_brightness\";\nvar current = flow.get(currentState);\n\nvar brightness = current + 50;\n\n\nif(brightness > 255){\n    brightness = 255;\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\n\nif(brightness < 0){\n    brightness = 0;\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\nelse{\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"brightness\": brightness\n    };\n    return msg;\n}\n\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":450,"y":260,"wires":[["7dd73b48e8a1dfb0"]]},{"id":"7dd73b48e8a1dfb0","type":"api-call-service","z":"ed250eb3.082ba","name":"Master Bed Overhead Lamp Toggle","server":"415bd6ac1fca7222","version":5,"debugenabled":false,"domain":"light","service":"toggle","areaId":[],"deviceId":[],"entityId":["light.mb_oh_lights"],"data":"","dataType":"jsonata","mergeContext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":860,"y":240,"wires":[[]]},{"id":"25ebc92402de549e","type":"mqtt in","z":"ed250eb3.082ba","name":"spotlight","topic":"zigbee2mqtt/MB OH Lights","qos":"0","datatype":"json","broker":"867c194d39b2d479","nl":false,"rap":false,"inputs":0,"x":640,"y":80,"wires":[["9c846acd60cbb00f"]]},{"id":"9c846acd60cbb00f","type":"function","z":"ed250eb3.082ba","name":"Save Value","func":"var state = msg.payload.state;\nvar brightness = msg.payload.brightness;\n\nflow.set(\"MB_OH_Lights_brightness\", brightness);\nflow.set(\"MB_OH_Lights_state\", state);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":80,"wires":[[]]},{"id":"6ec10784533fd7a7","type":"mqtt in","z":"ed250eb3.082ba","name":"IKEA 2","topic":"zigbee2mqtt/MB OH Lights","qos":"0","datatype":"json","broker":"867c194d39b2d479","nl":false,"rap":false,"inputs":0,"x":630,"y":140,"wires":[["f8c3089fa9fc2226"]]},{"id":"f8c3089fa9fc2226","type":"function","z":"ed250eb3.082ba","name":"Save Value","func":"var state = msg.payload.state;\nvar brightness = msg.payload.brightness;\n\nflow.set(\"MB OH Lights_brightness\", brightness);\nflow.set(\"MB OH Lights_state\", state);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":140,"wires":[[]]},{"id":"67d0081273914260","type":"function","z":"ed250eb3.082ba","name":"Set devices","func":"var x = msg.payload;\nglobal.set(\"ZigbeeLights\", x);\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":830,"y":35,"wires":[[]]},{"id":"c74b697965a9cc5c","type":"inject","z":"ed250eb3.082ba","name":"Zigbee Devices","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"[\"MB OH Lights\",\"MB OH Lights\"]","payloadType":"json","x":660,"y":35,"wires":[["67d0081273914260"]]},{"id":"caa1c0e529aa41b0","type":"function","z":"ed250eb3.082ba","name":"function 1","func":"var device = flow.get(\"activeDevice\");\nvar currentState = device + \"_state\";\nvar current = flow.get(currentState);\n\n\n\nif (current === \"ON\") {\n    const state = \"OFF\";\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"state\": state\n    };\n    return msg;\n}\n\nif (current === \"OFF\" || undefined) {\n    const state = \"ON\";\n    msg.topic = \"zigbee2mqtt/\" + device + \"/set\";\n    msg.payload = {\n        \"state\": state\n    };\n    return msg;\n}\n","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":420,"y":220,"wires":[["7dd73b48e8a1dfb0"]]},{"id":"867c194d39b2d479","type":"mqtt-broker","name":"MQTT Broker KDC","broker":"192.168.2.248","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":""},{"id":"415bd6ac1fca7222","type":"server","name":"Home Assistant KDC","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}]

Cheers