Msg.property are lost between nodes

Great Nodered users.

I've the below flow where the msg is supposed to have multiple properties, but it seems the properties are lost in between nodes !

[
    {
        "id": "a9eb292a6233f9f1",
        "type": "inject",
        "z": "129b235eefae568b",
        "name": "",
        "props": [
            {
                "p": "topic",
                "vt": "str"
            },
            {
                "p": "state",
                "v": "OFF",
                "vt": "str"
            },
            {
                "p": "background",
                "v": "RED",
                "vt": "str"
            },
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": 0.1,
        "topic": "inverter",
        "payload": "false",
        "payloadType": "bool",
        "x": 110,
        "y": 60,
        "wires": [
            [
                "2437fb407f0c0b44",
                "234ba221963d2297"
            ]
        ]
    },
    {
        "id": "9079ecab67bcd03b",
        "type": "change",
        "z": "129b235eefae568b",
        "name": "",
        "rules": [
            {
                "t": "change",
                "p": "background",
                "pt": "msg",
                "from": "RED",
                "fromt": "str",
                "to": "GREEN",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "state",
                "pt": "msg",
                "from": "OFF",
                "fromt": "str",
                "to": "ON",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "background",
                "pt": "msg",
                "from": "GREEN",
                "fromt": "str",
                "to": "RED",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "state",
                "pt": "msg",
                "from": "ON",
                "fromt": "str",
                "to": "OFF",
                "tot": "str"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "true",
                "fromt": "bool",
                "to": "false",
                "tot": "bool"
            },
            {
                "t": "change",
                "p": "payload",
                "pt": "msg",
                "from": "false",
                "fromt": "bool",
                "to": "true",
                "tot": "bool"
            }
        ],
        "action": "",
        "property": "",
        "from": "",
        "to": "",
        "reg": false,
        "x": 480,
        "y": 60,
        "wires": [
            [
                "d685e5a3ea2915fc",
                "2437fb407f0c0b44"
            ]
        ]
    },
    {
        "id": "d685e5a3ea2915fc",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 1",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 660,
        "y": 60,
        "wires": []
    },
    {
        "id": "2437fb407f0c0b44",
        "type": "ui_button",
        "z": "129b235eefae568b",
        "name": "",
        "group": "d488c32a39e6b090",
        "order": 1,
        "width": 0,
        "height": 0,
        "passthru": false,
        "label": "{{msg.state}}",
        "tooltip": "",
        "color": "",
        "bgcolor": "{{msg.background}}",
        "className": "",
        "icon": "",
        "payload": "false",
        "payloadType": "bool",
        "topic": "inverter",
        "topicType": "msg",
        "x": 250,
        "y": 60,
        "wires": [
            [
                "9079ecab67bcd03b",
                "565d1c11f6297a74"
            ]
        ]
    },
    {
        "id": "565d1c11f6297a74",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 2",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 460,
        "y": 20,
        "wires": []
    },
    {
        "id": "234ba221963d2297",
        "type": "debug",
        "z": "129b235eefae568b",
        "name": "debug 3",
        "active": true,
        "tosidebar": true,
        "console": false,
        "tostatus": false,
        "complete": "true",
        "targetType": "full",
        "statusVal": "",
        "statusType": "auto",
        "x": 260,
        "y": 20,
        "wires": []
    },
    {
        "id": "d488c32a39e6b090",
        "type": "ui_group",
        "name": "dashboard_group_1",
        "tab": "a7d5e487503829e6",
        "order": 1,
        "disp": true,
        "width": "6",
        "collapse": false,
        "className": ""
    },
    {
        "id": "a7d5e487503829e6",
        "type": "ui_tab",
        "name": "dashboard_tab_1",
        "icon": "dashboard",
        "disabled": false,
        "hidden": false
    }
]

What do I do wrong ?
The button is supposed to change background colour on each click as the msg.state is supposed to swap from true to false or false to true.

Hi @hary.

I don't use dashboard - But I'm sure, by default, it doesn't send everything it was simply set with, i.e, it will only send a payload (and maybe topic) - therefore, your change node is not finding the properties it needs to change - and when sending it back through, you are only changing the payload and topic.

I could be wrong of course - and sure it can be configured to do so.

You are using the change node wrongly.
First you change RED to GREEN, then you go on to change GREEN to RED.

One way around this is to use a temporary third value:

Hi , this example may help the payload is stored in context, as the button will not pass the state and background. Also colour and state are set using payload.
e.g.

[{"id":"a9eb292a6233f9f1","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"topic","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"inverter","payload":"false","payloadType":"bool","x":130,"y":4100,"wires":[["9079ecab67bcd03b"]]},{"id":"9079ecab67bcd03b","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"background","pt":"msg","to":"$$.payload = true ?  \"red\" :\"green\"","tot":"jsonata"},{"t":"set","p":"state","pt":"msg","to":"$$.payload = true ? \"ON\": \"OFF\" ","tot":"jsonata"},{"t":"set","p":"switch_state","pt":"flow","to":"$$.payload = true ? false : true","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":340,"y":4140,"wires":[["2437fb407f0c0b44"]]},{"id":"2437fb407f0c0b44","type":"ui_button","z":"65617ffeb779f51c","name":"","group":"d488c32a39e6b090","order":1,"width":0,"height":0,"passthru":false,"label":"{{msg.state}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","className":"","icon":"","payload":"switch_state","payloadType":"flow","topic":"inverter","topicType":"msg","x":510,"y":4140,"wires":[["d685e5a3ea2915fc","9079ecab67bcd03b"]]},{"id":"d685e5a3ea2915fc","type":"debug","z":"65617ffeb779f51c","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":700,"y":4100,"wires":[]},{"id":"d488c32a39e6b090","type":"ui_group","name":"dashboard_group_1","tab":"a7d5e487503829e6","order":1,"disp":true,"width":"6","collapse":false,"className":""},{"id":"a7d5e487503829e6","type":"ui_tab","name":"dashboard_tab_1","icon":"dashboard","disabled":false,"hidden":false}]

You can do similar without context, but it means adding the payload to the topic as that is the only msg var that can be set in the button node.
e.g.

[{"id":"55bedbea4e6bb0fd","type":"inject","z":"65617ffeb779f51c","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"inverter1","payload":"false","payloadType":"bool","x":150,"y":4160,"wires":[["49cfd617ccad660e"]]},{"id":"49cfd617ccad660e","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"topic","pt":"msg","to":"[$$.topic, $$.payload = true ? false : true]","tot":"jsonata"},{"t":"set","p":"background","pt":"msg","to":"$$.topic[1] = true ?  \"green\" :\"red\"","tot":"jsonata"},{"t":"set","p":"state","pt":"msg","to":"$$.topic[1] = true ? \"OFF\"  : \"ON\"","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":4160,"wires":[["39ecebf2b74fe56b"]]},{"id":"6486c21cea76bea6","type":"change","z":"65617ffeb779f51c","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"topic[1]","tot":"msg"},{"t":"move","p":"topic[0]","pt":"msg","to":"topic","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":4160,"wires":[["49cfd617ccad660e","b0e246c0a40c9096"]]},{"id":"39ecebf2b74fe56b","type":"ui_button","z":"65617ffeb779f51c","name":"","group":"2d4fe667.28f8ba","order":1,"width":0,"height":0,"passthru":false,"label":"{{msg.state}}","tooltip":"","color":"","bgcolor":"{{msg.background}}","className":"","icon":"","payload":"inverter1","payloadType":"str","topic":"topic","topicType":"msg","x":530,"y":4160,"wires":[["6486c21cea76bea6"]]},{"id":"b0e246c0a40c9096","type":"debug","z":"65617ffeb779f51c","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":720,"y":4120,"wires":[]},{"id":"2d4fe667.28f8ba","type":"ui_group","name":"demo","tab":"1caa8458.b17814","order":2,"disp":true,"width":"12","collapse":false},{"id":"1caa8458.b17814","type":"ui_tab","name":"Demo","icon":"dashboard","order":1,"disabled":false,"hidden":false}]

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