How do I perform the analysis condition when I send a mqtt topic of iSpindel device temperature?

How do I perform the analysis condition when I send a mqtt topic of iSpindel device temperature?

I was able to get the maximum and minimum temperature data from the input form. I made the condition with the temperature value of the iSpindel device, but when the device sends another signal by mqtt , the condition is not fulfilled, therefore, I have to send the input form data every time I want to do the condition.The idea is actually to send the input form data, and whenever you send the iSpindel device temperature topic, perform the condition, not needing to keep sending the input form data every time.

I tried to trigger this analysis when the device sends the signal, in this case the temp_max and temp_min variables that are the maximum and minimum temperature, receive the temperature value from the device, but I don't want it to be like that, in fact I want it to do the condition to activate the relay or not.

The code I implemented was this:

const { Analysis, Device, Utils, Services } = require("@tago-io/sdk");

async function mqttPushExample(context, scope) {
 
  if (!scope.length) {
    return context.log("This analysis must be triggered by a dashboard.");
  }
  console.log("my scope:", scope);

  const my_temp_max = scope.find((x) => x.variable === "temp_max") || scope[0];

  const my_temp_min = scope.find((x) => x.variable === "temp_min") || scope[0];
 
  console.log("temp max: ",my_temp_max.value);

  console.log("temp min: ",my_temp_min.value);

  if (!my_temp_max || !my_temp_min) {
    return context.log("Couldn't find any variable in the scope.");
  }

 const env_vars = Utils.envToJson(context.environment);

  if (!env_vars.device_token) {
    return context.log("Device token not found on environment parameters");
  }
 const device_iSpindel = new Device({ token: env_vars.device_token });

 const result = await device_iSpindel.getData({variable: "temperature"});

 console.log("iSpindel: ", result[0].value);
 
 if(result[0].value > my_temp_max.value){
   console.log("\n Ligou a Geladeira");
 }else if (result[0].value < my_temp_min.value){
   console.log("\n Desligou a Geladeira");
 }

}

module.exports = new Analysis(mqttPushExample);


what can I do to resolve this situation?

I will send some pictures.