I Want a value of a variabel to not exceed an other value of an other variable

How to make the value of the variable in one incremental step dont exceed the value of an other variabel in other incremental step.

Exemple:

My user willl select ther max value and the minimum value, I dont want the system to let him put the minimum bigger ou equal the maximum.

There is any way to do this ?

Hi Gabriel,

How does your user send data?
Did you check if the method you’re using already has a native limiter?

If it doesn’t, you could always create an analysis that will do any checks for your before continuing the rest of your process.

So there are multiple ways you can achieve this, I need more information though.

Hi Freddy,

The users send the information by an Input Form, and chose the maximun value and the minimum value by two diferents incremental steps.

As the image shows I want the “Umidade Mínima” not to exceed the “Umidade Máxima”.

Hi Gabriel,

Great! So from what I understood, you can fix this by running an Analysis, the Analysis would then verify if the minimum humidity is below the maximum humidity.

Does this input form already trigger an Analysis when you submit data?

Heres an example of an Analysis that could acheive this, its using the device-token but you can use “scope[0].device” if you wish to use the device you configured in the input form.

const { Analysis, Resources, Utils, Services } = require(“@tago-io/sdk”);

/**

* Analysis to validate and process humidity data from an input form.

* @param {TagoContext} context - The Tago context object.

* @param {Data} scope - The scope containing data from the dashboard and actions.

*/

async function humidityAnalysis(context, scope) {

// Assuming ‘max_humidity’ and ‘min_humidity’ are passed in the scope.

const maxHumidityData = scope.find((data) => data.variable === ‘max_humidity’);

const minHumidityData = scope.find((data) => data.variable === ‘min_humidity’);

if (!maxHumidityData || !minHumidityData) {

console.error(“Max or Min Humidity data not found.”);

return;

}

const maxHumidity = Number(maxHumidityData.value);

const minHumidity = Number(minHumidityData.value);

// Check if the max humidity is not bigger than the min humidity.

if (minHumidity >= maxHumidity) {

// Notify the user of the error.

const notificationService = new Services({ token: context.token }).notification;

await notificationService.send({

title: “Humidity Data Error”,

message: “Min humidity cannot be higher or equal to max humidity.”,

});

console.error(“Min humidity cannot be higher or equal to max humidity.”);

return;

}

// If there’s no error, add the data to the device.

const deviceID = “enter-your-device-id-here”; // Replace with your actual device ID.

await Resources.devices.sendDeviceData(deviceID, [

{ variable: “max_humidity”, value: maxHumidity },

{ variable: “min_humidity”, value: minHumidity },

]);

console.info(“Humidity data successfully added to the device.”);

}

Analysis.use(humidityAnalysis);

Hi Freddy,

That help me a lot, but I was thinking if we could make pop a warning in the screen when the user makes the min Humidity Greater than the max humidity like in the picture