function sensorListener(weightRef, sensor) {
  weightRef.once('value').then(function (weightSnap) {
    let weight = weightSnap.val();
    let one = weight.empty - weight.full || 1;
    let part = weight.empty - weight.current || 1;
    // console.log(part + " / " + one);
    weightRef.update({
      current: sensor.value,
      percent: Math.round((part / one) * 100),
    });
  });
};

module.exports = sensorListener;

function sensorListener(weightRef, sensor) {
  weightRef.once('value').then(function (weightSnap) {
    const weight = weightSnap.val();
    const one = weight.empty - weight.full || 1;
    const part = weight.empty - sensor.value || 1;
    const basisPoint = Math.round((part / one) * 10000);
    const percent = Math.min(100, basisPoint / 100);
    const diff = Math.round(Math.abs(percent - weight.percent) * 100) / 100;

    if(percent != weight.percent && diff > 0.01) {
      weightRef.update({
        current: sensor.value,
        percent,
      });
    }
  });
};

module.exports = sensorListener;

Improve weight update algorithm