I need to "function" node to send information only what i wrote in code and nothing else!
How to block everything else that "flies" through it after the node "mqtt"?
The code that I need to send!
var button_corridor = flow.get('button_corridor') || ""; //Что бы отслеживалось состояние кнопки.
if (button_corridor === "ON") { // Включаем возможность изменения яркости!
msg.enabled = true;
return msg;
}
else if (msg.payload === "Off"){
msg.enabled = false;
msg.brightness = null;
return msg;
}
else {
msg.brightness = null;
return null;
}
And this is the message that he passes through himself every time!
At beginning of code set msg = {}; That will set whole message to an empty object. This will affect msg.payload, so if you need it in your if statement, set var hold = msg; before you overwrite msg. Then use if(hold.payload = ... in your if statement.
No, that isn't the message, that is what is in msg.payload, because that is what you have configured the debug node to show. If you set the debug node to Show Full Message then you will see that msg.enabled and msg.brightness (which is not the same as msg.payload.brightness) should have been set as your code dictates. Perhaps you meant msg.payload = {enabled: true}
and msg.payload = {enabled: false, brightness: null}
If you don't understand then have a look at the node-red docs page Working with Messages which should help.