Mopeka pro checker ultra sonic gas sensor configuration

I am needing some assistance with a ultra sonic gas sensor, it sends its payload via bluetooth to a mikrotic router then I have that sending the payload via mqtt. Tring to find out if anyone else has had to do it this way

the payload that is getting sent is
“0dff5900035d3abe4724684e24090302e5fe”

I then have it going through node red to unpack the payload

process payload

let device_id = 'gastank1';
let device_name = 'Gas Tank Sensor';
let hexString = msg.payload;
let data = Buffer.from(hexString, 'hex');
msg.payload = data;

let battery = msg.payload[5];
let battery_voltage = battery / 32.0;
let battery_percentage = Math.round(Math.max(0, Math.min(100, ((battery / 32.0 - 2.2) / 0.65) * 100)));

let temp = msg.payload[6] & 0x7F;
let temp_celsius = temp - 40;

let level = ((msg.payload[8] << 3) + msg.payload[7]);
let tank_level_cm = level * 0.1;

// Prepare the output message
msg.payload = {
    device_id: device_id,
    device_name: device_name,
    battery_voltage: battery_voltage,
    temp_celsius: temp_celsius,
    tank_level_cm: tank_level_cm,
    
};

return msg;

discovery payload

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

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

// Define the discovery payload
let discovery_payload = {
    name: `${device_name} tank level cm`,
    state_topic: `homeassistant/sensor/GasTank/gastank1/state`,
    unique_id: `${device_id}_${sensor_type}`,
    device: {
        identifiers: [device_id],
        name: device_name,
        model: "EYEGAS",
        manufacturer: "EYEGAS"
    },
    value_template: "{{ value_json.tank_level_cm | float }}"
};
msg.topic = discovery_topic;
msg.payload = JSON.stringify(discovery_payload);
msg.retain = true;

return msg;

publish payload

let device_id = msg.payload.device_id;
let device_name = msg.payload.device_name;
let battery_voltage = msg.payload.battery_voltage;
let temp_celsius = msg.payload.temp_celsius;
let tank_level_cm = msg.payload.tank_level_cm;

msg.topic = `homeassistant/sensor/GasTank/${device_id}/state`;
msg.payload = JSON.stringify({
    device_name: device_name,
    battery_voltage: battery_voltage,
    temp_celsius: temp_celsius,
    tank_level_cm: tank_level_cm,
});
msg.retain = true;

return msg;

You kinda have a circular thing going with msg.payload Also the keys of your out going message are being interpreted as variables.

let hexString = msg.payload;
let data = Buffer.from(hexString, 'hex');
//msg.payload = data; Rather than reassign msg.payload use the data array

let battery = data[5];
let battery_voltage = battery / 32.0;
let battery_percentage = Math.round(Math.max(0, Math.min(100, ((battery / 32.0 - 2.2) / 0.65) * 100)));

let temp = data[6] & 0x7F;
let temp_celsius = temp - 40;

let level = ((data[8] << 3) + data[7]);
let tank_level_cm = level * 0.1;

// clear the message obj
msg = {};

// Prepare the output message
// The key needs to be in quotes otherwise it will be interpreted as a variable.
msg.payload = {
    "device_id": device_id,
    "device_name": device_name,
    "battery_voltage": battery_voltage,
    "temp_celsius": temp_celsius,
    "tank_level_cm": tank_level_cm,
    
};

return msg;

my current node red flow is working i am trying to find out if anyone else has used the sensor in node red like me because i am trying to find out if i have the correct sum working out the volume height.