Needing help with a Node Red work flow that i am using in home assistant

Good day I am in need of help so I have made a work flow in Node Red that works well bringing in the data from a Milesight UC300 but I am struggling to get the commands out to work with the digital outputs(gpio_output_1;gpio_output_2).
I apologize in advance with all the code but I am in need of help

Commands
on = {"confirmed":true,"fport":85,"data":"BwEA/w=="}
off = {"confirmed":true,"fport":85,"data":"BwAA/w=="}

these commands need to be sent to a mqtt out node

This is the function node for Process Payload

let payload = msg.payload;

let device_id = payload.devEUI;
let device_name = payload.deviceName;
let gpio_input_1 = payload.gpio_input_1;
let gpio_input_2 = payload.gpio_input_2;
let gpio_input_3 = payload.gpio_input_3;
let gpio_input_4 = payload.gpio_input_4;
let gpio_output_1 = payload.gpio_output_1;
let gpio_output_2 = payload.gpio_output_2;
let modbus_chn_1 = payload.modbus_chn_1;
let modbus_chn_2 = payload.modbus_chn_2;
let modbus_chn_3 = payload.modbus_chn_3;
let modbus_chn_4 = payload.modbus_chn_4;
let modbus_chn_5 = payload.modbus_chn_5;
let modbus_chn_6 = payload.modbus_chn_6;
let modbus_chn_7 = payload.modbus_chn_7;
let modbus_chn_8 = payload.modbus_chn_8;
let modbus_chn_9 = payload.modbus_chn_9;
let modbus_chn_10 = payload.modbus_chn_10;
let modbus_chn_11 = payload.modbus_chn_11;
let modbus_chn_12 = payload.modbus_chn_12;
let modbus_chn_13 = payload.modbus_chn_13;
let modbus_chn_14 = payload.modbus_chn_14;
let modbus_chn_15 = payload.modbus_chn_15;
let modbus_chn_16 = payload.modbus_chn_16;
let modbus_chn_17 = payload.modbus_chn_17;
let modbus_chn_18 = payload.modbus_chn_18;
let modbus_chn_19 = payload.modbus_chn_19;
let modbus_chn_20 = payload.modbus_chn_20;
let modbus_chn_21 = payload.modbus_chn_21;
let modbus_chn_22 = payload.modbus_chn_22;
let modbus_chn_23 = payload.modbus_chn_23;
let modbus_chn_24 = payload.modbus_chn_24;
let modbus_chn_25 = payload.modbus_chn_25;
let modbus_chn_26 = payload.modbus_chn_26;
let modbus_chn_27 = payload.modbus_chn_27;
let modbus_chn_28 = payload.modbus_chn_28;
let modbus_chn_29 = payload.modbus_chn_29;
let modbus_chn_30 = payload.modbus_chn_30;
let modbus_chn_31 = payload.modbus_chn_31;
let modbus_chn_32 = payload.modbus_chn_32;
let adc_1 = payload.adc_1;
let adc_2 = payload.adc_2;


msg.payload = {
    device_id: device_id,
    device_name: device_name,
    gpio_input_1: payload.gpio_input_1,
    gpio_input_2: payload.gpio_input_2,
    gpio_input_3: payload.gpio_input_3,
    gpio_input_4: payload.gpio_input_4,
    gpio_output_1: payload.gpio_output_1,
    gpio_output_2: payload.gpio_output_2,
    modbus_chn_1: payload.modbus_chn_1,
    modbus_chn_2: payload.modbus_chn_2,
    modbus_chn_3: payload.modbus_chn_3,
    modbus_chn_4: payload.modbus_chn_4,
    modbus_chn_5: payload.modbus_chn_5,
    modbus_chn_6: payload.modbus_chn_6,
    modbus_chn_7: payload.modbus_chn_7,
    modbus_chn_8: payload.modbus_chn_8,
    modbus_chn_9: payload.modbus_chn_9,
    modbus_chn_10: payload.modbus_chn_10,
    modbus_chn_11: payload.modbus_chn_11,
    modbus_chn_12: payload.modbus_chn_12,
    modbus_chn_13: payload.modbus_chn_13,
    modbus_chn_14: payload.modbus_chn_14,
    modbus_chn_15: payload.modbus_chn_15,
    modbus_chn_16: payload.modbus_chn_16,
    modbus_chn_17: payload.modbus_chn_17,
    modbus_chn_18: payload.modbus_chn_18,
    modbus_chn_19: payload.modbus_chn_19,
    modbus_chn_20: payload.modbus_chn_20,
    modbus_chn_21: payload.modbus_chn_21,
    modbus_chn_22: payload.modbus_chn_22,
    modbus_chn_23: payload.modbus_chn_23,
    modbus_chn_24: payload.modbus_chn_24,
    modbus_chn_25: payload.modbus_chn_25,
    modbus_chn_26: payload.modbus_chn_26,
    modbus_chn_27: payload.modbus_chn_27,
    modbus_chn_28: payload.modbus_chn_28,
    modbus_chn_29: payload.modbus_chn_29,
    modbus_chn_30: payload.modbus_chn_30,
    modbus_chn_31: payload.modbus_chn_31,
    modbus_chn_32: payload.modbus_chn_32,
    adc_1: payload.adc_1,
    adc_2: payload.adc_2,

};

return msg;

This is the function node for Discovery Payload

let device_id = msg.payload.device_id;
let device_name = msg.payload.device_name;
let gpio_output_1 = msg.payload.gpio_output_1
let sensor_type = "gpio_output_1";

// Define the discovery topic
let discovery_topic = `homeassistant/switch/UC300/${device_id}_${sensor_type}/config`;

// Define the discovery payload
let discovery_payload = {
    name: `${device_name} GPIO Output 1`,
    command_topic: `homeassistant/milesight/downlink/24e124445d016017`,
    state_topic: `homeassistant/switch/UC300/${device_id}/state`,
    unique_id: `${device_id}_${sensor_type}`,
    device: {
        identifiers: [device_id],
        name: device_name,
        model: "Milesight Sensor",
        manufacturer: "Milesight"
    },
    // Define the payloads as JSON strings
    payload_on: `1`,
    payload_off: `0`,
    value_template: "{{ value_json.gpio_output_1 }}",
};

msg.topic = discovery_topic;
msg.payload = JSON.stringify(discovery_payload);
msg.retain = true;

return msg;

This is the function node for Command payload

let device_id = msg.payload.device_id;
let gpio_output_1 = msg.payload.gpio_output_1;  // "1" for on, "0" for off

let payload;

// Check if gpio_output_2 is defined and process the command
if (gpio_output_1 !== undefined) {
    if (gpio_output_1 === 1) {
        // Command to turn on GPIO output 2
        payload = Buffer.from([0x07, 0x01, 0x00, 0xff]);
    } else if (gpio_output_1 === 0) {
        // Command to turn off GPIO output 2
        payload = Buffer.from([0x07, 0x00, 0x00, 0xff]);
    } else {
        // If the command is not recognized, return without doing anything
        node.warn("Unknown command received: " + JSON.stringify(gpio_output_1));
        return null;
    }
    
    // Set the MQTT topic and payload
    msg.topic = `homeassistant/milesight/downlink/24e124445d016017`;
    msg.payload = payload;

    return msg;
} else {
    node.warn("GPIO Output command is undefined");
    return null;
}

This is the function node for publish payload

let device_id = msg.payload.device_id;
let device_name = msg.payload.device_name;
let gpio_output_1 = msg.payload.gpio_output_1;
let gpio_output_2 = msg.payload.gpio_output_2;

msg.topic = `homeassistant/switch/UC300/${device_id}/state`;
msg.payload = JSON.stringify({
    device_name: device_name,
    gpio_output_1: gpio_output_1,
    gpio_output_2: gpio_output_2,
});

return msg;

Here is the export of my work flow to help show where i have gone wrong

[{"id":"eb86f5a92d01a413","type":"tab","label":"UC300 switch flow","disabled":false,"info":"","env":[]},{"id":"9e0b292cbd92e1ee","type":"mqtt in","z":"eb86f5a92d01a413","name":"","topic":"homeassistant/milesight/uplink","qos":"0","datatype":"json","broker":"024346bb511cf5e0","nl":false,"rap":true,"rh":0,"inputs":0,"x":200,"y":40,"wires":[["e4b8decee4e16ef9","22338d4d2d8a0e8f"]]},{"id":"e4b8decee4e16ef9","type":"debug","z":"eb86f5a92d01a413","name":"debug 125","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":40,"wires":[]},{"id":"e898bba3c696720b","type":"debug","z":"eb86f5a92d01a413","name":"debug 126","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1210,"y":480,"wires":[]},{"id":"5a4734ddbca3f263","type":"debug","z":"eb86f5a92d01a413","name":"debug 128","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":630,"y":120,"wires":[]},{"id":"22338d4d2d8a0e8f","type":"function","z":"eb86f5a92d01a413","name":"Process Payload","func":"let payload = msg.payload;\n\nlet device_id = payload.devEUI;\nlet device_name = payload.deviceName;\nlet gpio_output_1 = payload.gpio_output_1;\nlet gpio_output_2 = payload.gpio_output_2;\n\nmsg.payload = {\n    device_id: device_id,\n    device_name: device_name,\n    gpio_output_1: payload.gpio_output_1,\n    gpio_output_2: payload.gpio_output_2,\n\n};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":230,"y":120,"wires":[["5a4734ddbca3f263","718b4288ffe587f1"]]},{"id":"bb4d8e46dae2a80b","type":"function","z":"eb86f5a92d01a413","name":"Create Discovery Payload gpio_output_1","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_1 = msg.payload.gpio_output_1\nlet sensor_type = \"gpio_output_1\";\n\n// Define the discovery topic\nlet discovery_topic = `homeassistant/switch/UC300/${device_id}_${sensor_type}/config`;\n\n// Define the discovery payload\nlet discovery_payload = {\n    name: `${device_name} GPIO Output 1`,\n    command_topic: `homeassistant/milesight/downlink/24e124445d016017`,\n    state_topic: `homeassistant/switch/UC300/${device_id}/state`,\n    unique_id: `${device_id}_${sensor_type}`,\n    device: {\n        identifiers: [device_id],\n        name: device_name,\n        model: \"Milesight Sensor\",\n        manufacturer: \"Milesight\"\n    },\n    // Define the payloads as JSON strings\n    payload_on: `1`,\n    payload_off: `0`,\n    value_template: \"{{ value_json.gpio_output_1 }}\",\n};\n\nmsg.topic = discovery_topic;\nmsg.payload = JSON.stringify(discovery_payload);\nmsg.retain = true;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":440,"wires":[["e898bba3c696720b","05396752e27c1eaf"]]},{"id":"71f3e3101ca33c8c","type":"function","z":"eb86f5a92d01a413","name":"Create Discovery Payload gpio_output_2","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_2 = msg.payload.gpio_output_2;\nlet sensor_type = \"gpio_output_2\";\n\n// Define the discovery topic\nlet discovery_topic = `homeassistant/switch/UC300/${device_id}_${sensor_type}/config`;\n\n// Define the discovery payload\nlet discovery_payload = {\n    name: `${device_name} GPIO Output 2`,\n    command_topic: `homeassistant/milesight/downlink/24e124445d016017`,\n    state_topic: `homeassistant/switch/UC300/${device_id}/state`,\n    unique_id: `${device_id}_${sensor_type}`,\n    device: {\n        identifiers: [device_id],\n        name: device_name,\n        model: \"Milesight Sensor\",\n        manufacturer: \"Milesight\"\n    },\n    // Define the payloads as JSON strings\n    payload_on: `1`,\n    payload_off: `0`,\n    value_template: \"{{ value_json.gpio_output_2 }}\",\n    optimistic: false,\n    qos: 0\n};\n\nmsg.topic = discovery_topic;\nmsg.payload = JSON.stringify(discovery_payload);\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":720,"y":480,"wires":[["e898bba3c696720b","05396752e27c1eaf"]]},{"id":"718b4288ffe587f1","type":"switch","z":"eb86f5a92d01a413","name":"","property":"payload.device_id","propertyType":"msg","rules":[{"t":"eq","v":"24e124445d016017","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":230,"y":320,"wires":[["bb4d8e46dae2a80b","71f3e3101ca33c8c","36a6fd223f578b28","f27043b937d644f1","8f6ae93a7892059d","51a22ab4f24c93b8"]]},{"id":"36a6fd223f578b28","type":"debug","z":"eb86f5a92d01a413","name":"debug 129","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":210,"y":440,"wires":[]},{"id":"f27043b937d644f1","type":"function","z":"eb86f5a92d01a413","name":"Command Digital Output 1","func":"let device_id = msg.payload.device_id;\nlet gpio_output_1 = msg.payload.gpio_output_1;  // \"1\" for on, \"0\" for off\n\nlet payload;\n\n// Check if gpio_output_2 is defined and process the command\nif (gpio_output_1 !== undefined) {\n    if (gpio_output_1 === 1) {\n        // Command to turn on GPIO output 2\n        payload = Buffer.from([0x07, 0x01, 0x00, 0xff]);\n    } else if (gpio_output_1 === 0) {\n        // Command to turn off GPIO output 2\n        payload = Buffer.from([0x07, 0x00, 0x00, 0xff]);\n    } else {\n        // If the command is not recognized, return without doing anything\n        node.warn(\"Unknown command received: \" + JSON.stringify(gpio_output_1));\n        return null;\n    }\n    \n    // Set the MQTT topic and payload\n    msg.topic = `homeassistant/milesight/downlink/24e124445d016017`;\n    msg.payload = payload;\n\n    return msg;\n} else {\n    node.warn(\"GPIO Output command is undefined\");\n    return null;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":320,"wires":[["7246de110284dc61","7aecdd2da72429c4"]]},{"id":"8f6ae93a7892059d","type":"function","z":"eb86f5a92d01a413","name":"Command Digital Output 2","func":"let device_id = msg.payload.device_id;\nlet gpio_output_2 = msg.payload.gpio_output_2;  // \"1\" for on, \"0\" for off\n\nlet payload;\n\n// Check if gpio_output_2 is defined and process the command\nif (gpio_output_2 !== undefined) {\n    if (gpio_output_2 === 1) {\n        // Command to turn on GPIO output 2\n        payload = Buffer.from([0x07, 0x01, 0x00, 0xff]);\n    } else if (gpio_output_2 === 0) {\n        // Command to turn off GPIO output 2\n        payload = Buffer.from([0x07, 0x00, 0x00, 0xff]);\n    } else {\n        // If the command is not recognized, return without doing anything\n        node.warn(\"Unknown command received: \" + JSON.stringify(gpio_output_2));\n        return null;\n    }\n\n    // Set the MQTT topic and payload\n    msg.topic = `homeassistant/milesight/downlink/24e124445d016017`;\n    msg.payload = payload;\n\n    return msg;\n} else {\n    node.warn(\"GPIO Output command is undefined\");\n    return null;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":360,"wires":[["7246de110284dc61","7aecdd2da72429c4"]]},{"id":"7246de110284dc61","type":"mqtt out","z":"eb86f5a92d01a413","name":"","topic":"homeassistant/milesight/downlink/$deveui","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1300,"y":360,"wires":[]},{"id":"7aecdd2da72429c4","type":"debug","z":"eb86f5a92d01a413","name":"debug 130","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":320,"wires":[]},{"id":"51a22ab4f24c93b8","type":"function","z":"eb86f5a92d01a413","name":"Publish Switch Data","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_1 = msg.payload.gpio_output_1;\nlet gpio_output_2 = msg.payload.gpio_output_2;\n\nmsg.topic = `homeassistant/switch/UC300/${device_id}/state`;\nmsg.payload = JSON.stringify({\n    device_name: device_name,\n    gpio_output_1: gpio_output_1,\n    gpio_output_2: gpio_output_2,\n});\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":660,"y":240,"wires":[["aa1a322e3924726f","3dc2462b4bdabe78"]]},{"id":"aa1a322e3924726f","type":"mqtt out","z":"eb86f5a92d01a413","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1190,"y":260,"wires":[]},{"id":"3dc2462b4bdabe78","type":"debug","z":"eb86f5a92d01a413","name":"debug 131","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1210,"y":220,"wires":[]},{"id":"05396752e27c1eaf","type":"mqtt out","z":"eb86f5a92d01a413","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1190,"y":440,"wires":[]},{"id":"024346bb511cf5e0","type":"mqtt-broker","name":"","broker":"192.168.100.246","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

People do not have access to your mqtt broker, it would be best to delete the mqtt nodes and add inject nodes to simulate the mqtt in nodes output. That way people can run your flow, to work out what the issue may be.

You do not need to convert the payload to a JSON(string) the mqtt nodes will do that for you.

thanks for the heads up will edit a flow with and inject node rather than a mqtt in node.
and thanks for that info will change edit that.

A little bit more of a break down of the problem I am having.
So the first problem I am having when I click the switch in home assistant it does not go into the opposite state which is one of the issues.
And with that happening I think that is preventing the command to be pushed to the mqtt topic.
is there a different Node Red node that should be used for on off switches in home assistant to work?
I will try create just the node red work flow of just the nodes I have for the switch command if that will help figure out where I have gone wrong.

here is a screan shot of how my work flow is also not sure if this helps

hope that is the correct node that i have used in the beginning of the flow.

[{"id":"83712220f645d15a","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"b2c9e17cc883f59b","type":"debug","z":"83712220f645d15a","name":"debug 132","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":40,"wires":[]},{"id":"3eea9efd90999fb7","type":"debug","z":"83712220f645d15a","name":"debug 133","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":1170,"y":440,"wires":[]},{"id":"82ae25c9b272e458","type":"debug","z":"83712220f645d15a","name":"debug 134","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":590,"y":120,"wires":[]},{"id":"35020de89578adcb","type":"function","z":"83712220f645d15a","name":"Process Payload","func":"let payload = msg.payload;\n\nlet device_id = payload.devEUI;\nlet device_name = payload.deviceName;\nlet gpio_output_1 = payload.gpio_output_1;\nlet gpio_output_2 = payload.gpio_output_2;\n\nmsg.payload = {\n    device_id: device_id,\n    device_name: device_name,\n    gpio_output_1: payload.gpio_output_1,\n    gpio_output_2: payload.gpio_output_2,\n\n};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":190,"y":120,"wires":[["82ae25c9b272e458","46d03a4fb1c2136f"]]},{"id":"7eb7966ef842d787","type":"function","z":"83712220f645d15a","name":"Create Discovery Payload gpio_output_1","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_1 = msg.payload.gpio_output_1\nlet sensor_type = \"gpio_output_1\";\n\n// Define the discovery topic\nlet discovery_topic = `homeassistant/switch/UC300/${device_id}_${sensor_type}/config`;\n\n// Define the discovery payload\nlet discovery_payload = {\n    name: `${device_name} GPIO Output 1`,\n    command_topic: `homeassistant/milesight/downlink/24e124445d016017`,\n    state_topic: `homeassistant/switch/UC300/${device_id}/state`,\n    unique_id: `${device_id}_${sensor_type}`,\n    device: {\n        identifiers: [device_id],\n        name: device_name,\n        model: \"Milesight Sensor\",\n        manufacturer: \"Milesight\"\n    },\n    // Define the payloads as JSON strings\n    payload_on: `1`,\n    payload_off: `0`,\n    value_template: \"{{ value_json.gpio_output_1 }}\",\n};\n\nmsg.topic = discovery_topic;\nmsg.payload = JSON.stringify(discovery_payload);\nmsg.retain = true;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":440,"wires":[["3eea9efd90999fb7","c599273b2214f329"]]},{"id":"830fda4202aae52a","type":"function","z":"83712220f645d15a","name":"Create Discovery Payload gpio_output_2","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_2 = msg.payload.gpio_output_2;\nlet sensor_type = \"gpio_output_2\";\n\n// Define the discovery topic\nlet discovery_topic = `homeassistant/switch/UC300/${device_id}_${sensor_type}/config`;\n\n// Define the discovery payload\nlet discovery_payload = {\n    name: `${device_name} GPIO Output 2`,\n    command_topic: `homeassistant/milesight/downlink/24e124445d016017`,\n    state_topic: `homeassistant/switch/UC300/${device_id}/state`,\n    unique_id: `${device_id}_${sensor_type}`,\n    device: {\n        identifiers: [device_id],\n        name: device_name,\n        model: \"Milesight Sensor\",\n        manufacturer: \"Milesight\"\n    },\n    // Define the payloads as JSON strings\n    payload_on: `1`,\n    payload_off: `0`,\n    value_template: \"{{ value_json.gpio_output_2 }}\",\n    optimistic: false,\n    qos: 0\n};\n\nmsg.topic = discovery_topic;\nmsg.payload = JSON.stringify(discovery_payload);\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":680,"y":480,"wires":[["3eea9efd90999fb7","c599273b2214f329"]]},{"id":"46d03a4fb1c2136f","type":"switch","z":"83712220f645d15a","name":"","property":"payload.device_id","propertyType":"msg","rules":[{"t":"eq","v":"24e124445d016017","vt":"str"}],"checkall":"true","repair":false,"outputs":1,"x":190,"y":320,"wires":[["7eb7966ef842d787","830fda4202aae52a","791509da9e50fce6","b77229ef1dbb6591","462ad02c0e93b099","bd8077f79434ed30"]]},{"id":"791509da9e50fce6","type":"debug","z":"83712220f645d15a","name":"debug 135","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":170,"y":440,"wires":[]},{"id":"b77229ef1dbb6591","type":"function","z":"83712220f645d15a","name":"Command Digital Output 1","func":"let device_id = msg.payload.device_id;\nlet gpio_output_1 = msg.payload.gpio_output_1;  // \"1\" for on, \"0\" for off\n\nlet payload;\n\n// Check if gpio_output_2 is defined and process the command\nif (gpio_output_1 !== undefined) {\n    if (gpio_output_1 === 1) {\n        // Command to turn on GPIO output 2\n        payload = Buffer.from([0x07, 0x01, 0x00, 0xff]);\n    } else if (gpio_output_1 === 0) {\n        // Command to turn off GPIO output 2\n        payload = Buffer.from([0x07, 0x00, 0x00, 0xff]);\n    } else {\n        // If the command is not recognized, return without doing anything\n        node.warn(\"Unknown command received: \" + JSON.stringify(gpio_output_1));\n        return null;\n    }\n    \n    // Set the MQTT topic and payload\n    msg.topic = `homeassistant/milesight/downlink/24e124445d016017`;\n    msg.payload = payload;\n\n    return msg;\n} else {\n    node.warn(\"GPIO Output command is undefined\");\n    return null;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":320,"wires":[["a4f4a29d7709963b","6bc947bf2da9ef37"]]},{"id":"462ad02c0e93b099","type":"function","z":"83712220f645d15a","name":"Command Digital Output 2","func":"let device_id = msg.payload.device_id;\nlet gpio_output_2 = msg.payload.gpio_output_2;  // \"1\" for on, \"0\" for off\n\nlet payload;\n\n// Check if gpio_output_2 is defined and process the command\nif (gpio_output_2 !== undefined) {\n    if (gpio_output_2 === 1) {\n        // Command to turn on GPIO output 2\n        payload = Buffer.from([0x07, 0x01, 0x00, 0xff]);\n    } else if (gpio_output_2 === 0) {\n        // Command to turn off GPIO output 2\n        payload = Buffer.from([0x07, 0x00, 0x00, 0xff]);\n    } else {\n        // If the command is not recognized, return without doing anything\n        node.warn(\"Unknown command received: \" + JSON.stringify(gpio_output_2));\n        return null;\n    }\n\n    // Set the MQTT topic and payload\n    msg.topic = `homeassistant/milesight/downlink/24e124445d016017`;\n    msg.payload = payload;\n\n    return msg;\n} else {\n    node.warn(\"GPIO Output command is undefined\");\n    return null;\n}","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":640,"y":360,"wires":[["a4f4a29d7709963b","6bc947bf2da9ef37"]]},{"id":"a4f4a29d7709963b","type":"mqtt out","z":"83712220f645d15a","name":"","topic":"homeassistant/milesight/downlink/$deveui","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1260,"y":360,"wires":[]},{"id":"6bc947bf2da9ef37","type":"debug","z":"83712220f645d15a","name":"debug 136","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":320,"wires":[]},{"id":"bd8077f79434ed30","type":"function","z":"83712220f645d15a","name":"Publish Switch Data","func":"let device_id = msg.payload.device_id;\nlet device_name = msg.payload.device_name;\nlet gpio_output_1 = msg.payload.gpio_output_1;\nlet gpio_output_2 = msg.payload.gpio_output_2;\n\nmsg.topic = `homeassistant/switch/UC300/${device_id}/state`;\nmsg.payload = JSON.stringify({\n    device_name: device_name,\n    gpio_output_1: gpio_output_1,\n    gpio_output_2: gpio_output_2,\n});\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":620,"y":240,"wires":[["66c3a65c3979d536","e3b2c7ae682dc79b"]]},{"id":"66c3a65c3979d536","type":"debug","z":"83712220f645d15a","name":"debug 137","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1170,"y":220,"wires":[]},{"id":"c599273b2214f329","type":"mqtt out","z":"83712220f645d15a","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1150,"y":480,"wires":[]},{"id":"9c2e8ddf22d003d4","type":"inject","z":"83712220f645d15a","name":"","props":[{"p":"payload"},{"p":"topic","v":"","vt":"json"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":180,"y":40,"wires":[["35020de89578adcb","b2c9e17cc883f59b"]]},{"id":"e3b2c7ae682dc79b","type":"mqtt out","z":"83712220f645d15a","name":"","topic":"","qos":"","retain":"","respTopic":"","contentType":"","userProps":"","correl":"","expiry":"","broker":"024346bb511cf5e0","x":1170,"y":260,"wires":[]},{"id":"024346bb511cf5e0","type":"mqtt-broker","name":"","broker":"192.168.100.246","port":"1883","clientid":"","autoConnect":true,"usetls":false,"protocolVersion":"4","keepalive":"60","cleansession":true,"autoUnsubscribe":true,"birthTopic":"","birthQos":"0","birthRetain":"false","birthPayload":"","birthMsg":{},"closeTopic":"","closeQos":"0","closeRetain":"false","closePayload":"","closeMsg":{},"willTopic":"","willQos":"0","willRetain":"false","willPayload":"","willMsg":{},"userProps":"","sessionExpiry":""}]

You will find that not many people on this forum use HA and the Webhook nodes that come with it. There is a dedicated Node Red sub forum on the HA Forum list.

At a guess (as it is a common one i see with a lot of HA users) - make sure you are keying in on the correct state change - is the switch in HA set as a Binary switch ? If so make sure you are monitoring (using the webhook nodes) the change of state of the binary sensor.

If you open up the developer console and look at the logbook in HA you can see which entity (and what it is) that is changing state when you toggle the physical switch

Craig