I posted a solution on the old thread that you originally asked this on:
You could use a Switch node that sends the true
out on one output and the false
out on the other. Then use Change nodes in those two paths to set msg.payload to string on or off. If you don't know how to do that then I assume you are a beginner to node-red so I recommend watching this playlist: Node-RED Essentials. The videos are done by the developers of node-red. They're nice & short and to the point. You will understand a whole lot more in about 1 hour. A small investment for a lot of gain.