Thanks' edje11 , that pointed me in the right direction.
I prefer not adding nodes, but the answers here and reviewing the node helped me to find my own solution.
[{"id":"76cf0836193ab9eb","type":"group","z":"560a48e311b7eb68","name":"Block or Enable messages to flow","style":{"stroke":"#6f2fa0","fill":"#dbcbe7","label":true,"color":"#000000"},"nodes":["36cb18b26d858526","16d906f2c36a0d37","44e1f702b6d85138","126349533dc29422","401b37ac4d521152","099ae275e7016813","f3a75c2f2eecb8e5","312034a2180d9905","465f5a4e3452cd18","b31e594af6f2b7e8"],"x":154,"y":3919,"w":992,"h":222},{"id":"36cb18b26d858526","type":"inject","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"close","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"closed","payloadType":"str","x":250,"y":3960,"wires":[["099ae275e7016813"]]},{"id":"16d906f2c36a0d37","type":"inject","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"open","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"open","payloadType":"str","x":250,"y":4000,"wires":[["099ae275e7016813"]]},{"id":"44e1f702b6d85138","type":"inject","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{ \"class\": \"red\", \"size\": 1, \"returnable\": true}","payloadType":"json","x":250,"y":4100,"wires":[["b31e594af6f2b7e8"]]},{"id":"126349533dc29422","type":"switch","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Stop when closed","property":"payload.state","propertyType":"msg","rules":[{"t":"eq","v":"closed","vt":"str"},{"t":"else"}],"checkall":"false","repair":false,"outputs":2,"x":750,"y":4100,"wires":[[],["401b37ac4d521152"]]},{"id":"401b37ac4d521152","type":"debug","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Debug when open","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":4100,"wires":[]},{"id":"099ae275e7016813","type":"function","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Save env.state","func":"\nflow.set('state', msg.payload);\n\nmsg.payload = flow.get('state')\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":3960,"wires":[["f3a75c2f2eecb8e5"]]},{"id":"f3a75c2f2eecb8e5","type":"debug","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"State","active":true,"tosidebar":false,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":710,"y":3960,"wires":[]},{"id":"312034a2180d9905","type":"inject","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Query state","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"${state}","payloadType":"env","x":270,"y":4040,"wires":[["465f5a4e3452cd18"]]},{"id":"465f5a4e3452cd18","type":"function","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Get env.state","func":"\nmsg.payload = flow.get('state')\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":490,"y":4000,"wires":[["f3a75c2f2eecb8e5"]]},{"id":"b31e594af6f2b7e8","type":"function","z":"560a48e311b7eb68","g":"76cf0836193ab9eb","name":"Inject env.state","func":"\nmsg.payload.state = flow.get('state')\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":4100,"wires":[["126349533dc29422"]]}]
thanks for the replies