There is no need for all that complexity. The switch node to MQTT is already working, as I believe is the mechanical switch to MQTT. All it needs is to feed the MQTT In into the ui-switch, disable Pass Through in the node, and set it to Show State Of Input.