timer picker dashboard for Schedex


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


For object type of configuration:

This line is not needed at all.

After you get the data from your incoming msg.payload , it should be cleaned up and then add all needed properties to it.

ontime = ('0' + h).slice(-2) + ":" + ('0' + m).slice(-2);
//clean up the msg.payload object
msg.payload = {};
//setting ontime
msg.payload.ontime = ontime;
//add other properties 


Thanks for your response hotNipi I did what you have suggested and i'm getting unsupported input error in the schedex node. I think the reason is because msg.payload still has a number that is passed as an input from the time picker in the dashboard which is the on time in seconds. I tried making it an empty string but it still gave me the same error.


If you declare msg.payload = {}; there is no number anymore.

You should debug the ontime value after calculations. I think it does not do the right thing.
PS. Calculations are correct. The formatting needs attention.


you can display a variable in the the middle of a function by using node.warn("ontime=" + ontime);
This will display in the debug tab of the sidebar


so schedex asks for time in 24 hour format like so 0:00, is that correct? and my ontime holds the time after calculation in the same format 00:00 I tested it to verify.


Might be better to deal with actual data. Can you place debug node after your function node and set it to show complete msg and then share the output. With real data input if possible. Also it helps if you share the complete function node content.


Hey hotNipi, I miss read your first post, it worked like you said. after i got what i needed from the msg.payload, I cleared the object per your suggestion and then set all my variables and i didn't get an unsupported input error like before, I will set some timers and see if it works like it's suppose to. Thanks for your help again


Yeah. I was already deeply digging in the schedex node sources :smiley: