Probably easier than making a function node act as a gate, have you considered node-red-contrib-simple-gate?
[{"id":"125062fd02dd4e5e","type":"gate","z":"a19719d3e57004eb","name":"","controlTopic":"gate","defaultState":"closed","openCmd":"true","closeCmd":"false","toggleCmd":"toggle","defaultCmd":"default","statusCmd":"status","persist":false,"storeName":"memory","x":490,"y":140,"wires":[["fc232abf7483ba90"]]},{"id":"fc232abf7483ba90","type":"debug","z":"a19719d3e57004eb","name":"debug 232","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":670,"y":140,"wires":[]},{"id":"0e9939cfc16143e0","type":"inject","z":"a19719d3e57004eb","name":"Normal input","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":310,"y":200,"wires":[["125062fd02dd4e5e"]]},{"id":"023fc48a3c3c1bbd","type":"group","z":"a19719d3e57004eb","name":"Gate control - topic \"gate\" payload true/false","style":{"label":true},"nodes":["b6011414c26fe2b2","08ef1bdaaaf18432"],"x":114,"y":39,"w":282,"h":122},{"id":"b6011414c26fe2b2","type":"inject","z":"a19719d3e57004eb","g":"023fc48a3c3c1bbd","name":"Open the gate","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gate","payload":"true","payloadType":"bool","x":230,"y":80,"wires":[["125062fd02dd4e5e"]]},{"id":"08ef1bdaaaf18432","type":"inject","z":"a19719d3e57004eb","g":"023fc48a3c3c1bbd","name":"Close the gate","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"gate","payload":"false","payloadType":"bool","x":230,"y":120,"wires":[["125062fd02dd4e5e"]]}]
If the outputs from your HA node are not topic:"gate", payload:true/false, use change nodes to tweek them or adjust the gate settings.