I'm sure the answer to this is so simple yet my lack of programming knowledge is letting me down.
I want to build a flow that collects the bollean status from the Switch component on a dashboard and passes that status, together a variable name, into a widget. For example, {"variable_name": false}. I am guessing I should use the Function widget to do the magic but I can never seem to get the coding right as my debug outputs never produce the right syntax/structure.
How would that work? I need to change the boolean status of the variable that passed to the widget dependant upon the status of the switch; I'd need to build a mini-script to do the manipulation. I'd also like to learn how to do that as I'm sure it will come in very handy as my use of the platform expands and hopefully saves me from posting such humiliating questions on here in the future!
Add a debug node to the switch output to see what the output looks like, but it should be msg.payload
I'm guessing variable-name is known you can then use the change node to set msg."variable" to msg.payload
But Node-RED generally works by passing a javascript object (msg) between nodes with the important part as msg.payload
Do you really mean that you want the payload to contain a string containing something like {"on":1}
rather than a javascript object such as would be generated by the code msg.payload = {on: msg.payload};
No need for humiliation, everyone starts somewhere. As previously mentioned you could also do this in a Change node set to Move msg.payload To msg.payload.on as in