UI scheduler node for different json payloads on HTTP requests

Can someone give me a tip on how to incorporate using the UI scheduler node to send out different different JSON payloads that get rolled into the body of an HTTP GET requests?

The equipment that I am scheduling through ui scheduler handles rest API.

For example when UI scheduler node is True from the schedule or the slider I need this JSON payload to start a motor:

{
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
}

When UI scheduler node is False from the schedule or the slider, with a slightly different value:

{
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "50",
    "priority": "11"
}

The slider from the ui called MyDevice works fine either on or off. I have this add json function where the MyDevice values from on or off come through in the msg.payload in Boolean True or False.

This is where I am stuck, on the ON or OFF function any tips greatly appreciated, Im still learning javascript.

var payload = msg.payload

if (payload==True){
    
    // JSON PAYLOAD FOR MOTOR ON
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }
}

if (payload==False){

    // JSON PAYLOAD FOR MOTOR OFF
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }

}

return msg;

This is the add json header function for what its worth can the two functions be combined?

msg.headers={"content-type": "application/json"};
return msg;

As mentioned in another topic... use true false not True False

var payload = msg.payload

if (payload==true){
    
    // JSON PAYLOAD FOR MOTOR ON
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "100",
    "priority": "11"
    }
}

if (payload==false){

    // JSON PAYLOAD FOR MOTOR OFF
    
    msg.payload = {
    "address": "12345:2",
    "object_type": "analogValue",
    "object_instance": "302",
    "value": "0",
    "priority": "11"
    }

}

return msg;

Thank you!

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.