Getting the status of entities in Home Assistant

I am using home assistant and node-red to control my lights via a tradfri remote control.
As i want to use the center button as toggle, i made a variable that holds the state of the light to change it to the opposite when the button is pressed.
I am wondering, how can i replace the variable with a state from home assistant, to make my script better? As now my motion sensor(different flow) can also change the state of the lamp, without this function knowing it.

Also i am passing on "all events" from home assistant without filter, is there a better way of doing this, like only passing on the deconz_event and certain light states?

The separate Woonkamer node is the information that i need for the function, however i don't really want a separate event node if i don't need it.

Thanks and sorry for the newbie question.

[{"id":"8aefdff1.05c0c","type":"switch","z":"cec845b3.50f078","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":530,"y":280,"wires":[["1b64b02.0fc475"],["ac262a4f.53cff8"]]},{"id":"1b64b02.0fc475","type":"api-call-service","z":"cec845b3.50f078","name":"ON","server":"d2aa20f9.615c6","version":1,"service_domain":"light","service":"turn_on","entityId":"light.woonkamer_lamp_bank, light.woonkamer_lamp_raam","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":670,"y":260,"wires":[[]]},{"id":"ac262a4f.53cff8","type":"api-call-service","z":"cec845b3.50f078","name":"OFF","server":"d2aa20f9.615c6","version":1,"service_domain":"light","service":"turn_off","entityId":"light.woonkamer_lamp_bank, light.woonkamer_lamp_raam","data":"","dataType":"json","mergecontext":"","output_location":"payload","output_location_type":"msg","mustacheAltTags":false,"x":670,"y":300,"wires":[[]]},{"id":"59ec448d.ae0cac","type":"server-events","z":"cec845b3.50f078","name":"All Events","server":"d2aa20f9.615c6","event_type":"","x":80,"y":320,"wires":[["ee61fdee.a343a","2f367a1e.59b206"]]},{"id":"ee61fdee.a343a","type":"switch","z":"cec845b3.50f078","name":"","property":"payload.event.id","propertyType":"msg","rules":[{"t":"eq","v":"woonkamer_switch","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":260,"wires":[["7c6fb1af.d27da"]]},{"id":"7c6fb1af.d27da","type":"function","z":"cec845b3.50f078","name":"Knoppen","func":"knop = msg.payload.event.event;\n\n//const globalHomeAssistant = global.get('homeassistant');\n\n//msg.payload = globalHomeAssistant.homeAssistant.states[\"group.verlichting_woonkamer\"].state;\n//node.log(msg.payload);\n\nvar state1=context.get('state1') || \"OFF\";\n\n\n\nif(knop=='1002'){\n    if(state1 == 'ON'){\n        state1 = \"OFF\";\n    }else if(state1 == \"OFF\"){\n        state1 = \"ON\";\n    }\n    context.set('state1', state1);\n    return [{payload: state1}, null, null, null, null];\n}","outputs":5,"noerr":0,"x":380,"y":320,"wires":[["8aefdff1.05c0c"],[],[],[],[]]},{"id":"8dd47588.6ee0e8","type":"server-state-changed","z":"cec845b3.50f078","name":"Woonkamer","server":"d2aa20f9.615c6","version":1,"entityidfilter":"group.verlichting_woonkamer","entityidfiltertype":"exact","outputinitially":true,"state_type":"str","haltifstate":"","halt_if_type":"str","halt_if_compare":"is","outputs":1,"output_only_on_state_change":false,"x":90,"y":440,"wires":[[]]},{"id":"2f367a1e.59b206","type":"debug","z":"cec845b3.50f078","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":380,"y":460,"wires":[]},{"id":"d2aa20f9.615c6","type":"server","z":"","name":"Home Assistant"}]

Please export your flow again, read this post and edit your post.

Done, sorry and thanks!