Mutiple outputs if statement

Hey guys!

Im on my first jurney on Java an Node Red and have experienced actually some nice stuff. But actually im stuck and the documentation dont answer my quenstions or i dont understand it.

I want to split one if statement cases to two diffrent outputs. The first to payloads (tts & id) should be pushed to output 1 and the last two ( pushTopic & pushMessage) should be pushed to the second output, because the Alexa TTS and PushNot are causing troubles if i dont split them up.

Following my actual function node.

I hope i explained well.

if(msg.payload.presence == "home")
    {
        msg.payload.tts = 'Willkommen zu Hause! Schön dich zu sehen.'
        msg.payload.id = 'serialnumber'
        msg.payload.pushTopic = 'SYSTEM'
        msg.payload.pushMessage = 'Willkommen zu Hause!'
    }
return msg;

you need to create an array to send each msg to separate outputs,
something like this

let output =[{payload:{}},{payload:{}}];
if(msg.payload.presence == "home"){
    output[0].payload.tts = 'Willkommen zu Hause! Schön dich zu sehen.'
    output[0].payload.id = 'serialnumber'
    output[1].payload.pushTopic = 'SYSTEM'
    output[1].payload.pushMessage = 'Willkommen zu Hause!'
}else{
    output = null
}
return output;
1 Like

Thanks, mate. That helped me alot.

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