0
votes

I have a function that takes input from dashboard text input as a time selection and it calculates hours and minutes, and it sets other variables and returns the msg object to the Schedex node but it's not setting the time or the other variables when the flow is executed. I have red the documentation multiple times and followed it to my best understanding and it's still not configuring my Schedex node. Schedex documentation mentions two ways to send configuration to Schedex node, the first way is to set msg.palyload.variable or send all the configuration as one string in mgs.payload I will post the two versions of the function code below. if you would like to read the documentation for Schedex can be found below https://www.npmjs.com/package/node-red-contrib-schedex

    msgTemp = msg.payload;
    time = msgTemp / 1000;
    // calculates hour from seconds input
    h = Math.floor(time / 3600); 
    // calculates minutes from remainder 
    m = Math.floor(time % 3600 / 60); 
    // ontime formatted for Schedex standards
    ontime = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
    //setting ontime
    msg.payload.ontime = ontime;
    //setting onpayload
    msg.payload.onpayload = "1";
    //enabling schedule for every time of the week
    msg.payload.mon = true;
    msg.payload.tue = true;
    msg.payload.wed = true;
    msg.payload.thu = true;
    msg.payload.fri = true;
    msg.payload.sat = true;
    msg.payload.sun = true;
    //the documentations mentions that to set the variables from the ui 
    //it has to be in programmatic control, I have put this in the 
    //payload and it's not working.
    //i think my issue is with the line below but i can't figure it out
    msg.payload = "'## Programmatic Control";
    return msg;

here is the other version where all the configurations are stored on msg.payload as one string

    msgTemp = msg.payload;
    time = msgTemp / 1000;
    // calculates hour from seconds input
    h = Math.floor(time / 3600); 
    // calculates minutes from remainder 
    m = Math.floor(time % 3600 / 60); 
    ontime = "onetime " + ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2) 
    + " ";
    onpayload = "onpayload 1 ";
    mon = "mon true ";
    tue = "tue true ";
    wed = "wed true ";
    thu = "thu true ";
    fri = "fri true ";
    sat = "sat true ";
    sun = "sun true ";
    msg.payload = ontime + onpayload + mon + tue + wed + thu + fri + sat 
    + sun;
    return msg;

your help is greatly appreciated

1

1 Answers

0
votes

The last line before the return on your first example wipes out all the changes you made to the msg.payload object by replacing that object with a string "'## Programmatic Control"