Modifying Min, Max, Average analysis

Modifying Min, Max, Average analysis

I am trying to modify the Minimum, Maximum, Average analysis to subtract the Min from the Max and store the result as a new variable. I stripped out the average calculation because I don't need it. I also commented out adding the min and max variables to the device using .sendData because I don't need those either. It seems like it should be a simple const declaration and formula but I keep getting errors:. Here's the code I'm using:

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

// The function myAnalysis will run when you execute your analysis
async function myAnalysis(context) {
  // reads the values from the environment and saves it in the variable env_vars
  const env_vars = Utils.envToJson(context.environment);
  if (!env_vars.device_token) {
    return context.log("Device token not found on environment parameters");
  }

  const device = new Device({ token: env_vars.device_token });

  // This is a filter to get the minimum value of the variable temperature in the last day
  const minFilter = {
    variable: "count",
    query: "min",
    start_date: "1 day",
  };

  // Now we use the filter for the device to get the data
  // check if the variable min has any value
  // if so, we crete a new object to send to TagoIO
  const [min] = await device.getData(minFilter);
 // if (min) {
 //   const minValue = {
 //     variable: "count_minimum",
 //     value: min.value,
 //     unit: "in",
 //   };

    // Now we send the new object with the minimum value
 //   await device
 //     .sendData(minValue)
 //     .then(context.log("Count Minimum Updated"));
 // } else {
 //   context.log("Minimum value not found");
 // }

  // This is a filter to get the maximum value of the variable temperature in the last day
  const maxFilter = {
    variable: "count",
    query: "max",
    start_date: "1 day",
  };

  const [max] = await device.getData(maxFilter);

//  if (max) {
//    const maxValue = {
//      variable: "count_maximum",
//      value: max.value,
//      unit: "in",
//    };

//    await device
//      .sendData(maxValue)
//      .then(context.log("Count Maximum Updated"));
//  } else {
//    context.log("Maximum value not found");
//  }
  const daily = max.value - min.value;
  await device.sendData({variable:"Daily Total",value:daily.value,})
    .then(console.log)
    .catch(console.log);
}
module.exports = new Analysis(myAnalysis);




Here's the error:
Error on object parse: {'variable':[{'message':'Invalid variable name','path':['variable']}]}


EDIT:  Changing the .sendData command to the following solved the problem:

await device.sendData({variable:"Daily_Total",value:daily,})