Change node not working as expected!

It's been a long day, so this could be something stupid, so I'll apologise first!

I have an output from a node-red-contrib-google-smarthome node;

topic: ""
device_name: "driveway alert"
command: "OnOff"
params: object
payload: object
online: true
on: true
_msgid: "656fb6dc47400779"

...which I'm feeding into a change node which sets the msg.payload to the value of msg.payload.on
I expected that the payload from the change node would be true, but there is no output from the node, nothing...

Here's a quick video


If it’s already an object you can’t just set it to a new type, use move instead as that does a delete/replace

Hmm, not sure about that. My instinct is I would expect this to work.

There certainly are issues going the other way... Setting sub-properties of a non object type. But replacing payload should be okay.

Would need to try it out

Move does not work either

I might be tired as well but I see no msg.payload.on

I see msg.on

There's some indentation missing in the pasted message output that makes them all appear to be at the top level. The screenshot shows it is msg.payload.on

1 Like

Here is the full output from the contrib node;

   "device_name":"driveway alert",

I'm getting payload.on by right clicking on on: true in debug and selecting/copying it's path.


Strange thing is, if I copy the whole output from the contrib node, then paste it into a function node like this works OK, and I get the expected output - true???

[{"id":"9566b6e6bd3614e2","type":"function","z":"f8cf7ea5344d6287","name":"","func":"msg = { \"topic\": \"\", \"device_name\": \"driveway alert\", \"command\": \"OnOff\", \"params\": { \"on\": true }, \"payload\": { \"online\": true, \"on\": true }, \"_msgid\": \"6fd9bbe90bfd4906\" }\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":535,"y":1225,"wires":[["685a8731f1ec3bad"]]},{"id":"ff97bb624a7b3820","type":"inject","z":"f8cf7ea5344d6287","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":390,"y":1225,"wires":[["9566b6e6bd3614e2"]]},{"id":"43cbd11c92216a6b","type":"debug","z":"f8cf7ea5344d6287","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":885,"y":1225,"wires":[]},{"id":"685a8731f1ec3bad","type":"change","z":"f8cf7ea5344d6287","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"payload.on","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":710,"y":1225,"wires":[["43cbd11c92216a6b"]]}]

What is the difference?

what software do you use to get this video ?

I'm using LICEcap for Windows, but let's keep on topic please.

1 Like

What version of NR, node.js and what platform?

I'm using;

  • node-RED v2.1.3
  • node.js v14.18.1
  • OS Raspbian (Linux 5.10.63-v7+ arm LE)
  • Raspberry Pi 3b+

If you use a function node with
right after your google-home node
do you notice any weird characters or extra spaces in the property names ?

[EDIT] here is a modified version of your test flow that shows what i mean

[{"id":"9566b6e6bd3614e2","type":"function","z":"5847b7aa62131d37","name":"","func":"msg = { \"topic\": \"\", \"device_name\": \"driveway alert\", \" command \": \" OnOff \", \"params\": { \"on\": true }, \"payload\": { \"online\": true, \"on\": true }, \"_msgid\": \"6fd9bbe90bfd4906\" }\n\nnode.warn(JSON.stringify(msg))\n\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","libs":[],"x":540,"y":1920,"wires":[["b070be71099eec5e","50bfcbdd103cbeb2"]]},{"id":"ff97bb624a7b3820","type":"inject","z":"5847b7aa62131d37","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":380,"y":1920,"wires":[["9566b6e6bd3614e2"]]},{"id":"b070be71099eec5e","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":710,"y":1880,"wires":[]},{"id":"50bfcbdd103cbeb2","type":"debug","z":"5847b7aa62131d37","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"command","targetType":"msg","statusVal":"","statusType":"auto","x":730,"y":1940,"wires":[]}]

i modified the "command" property to have extra spaces
in the debug window those are not rendered and the msg property value is actually accesible only with extra spaces msg[" command "]
its a long shot but if its the case it would show with stringify


Paul, What do you see if you set the second debug to display the complete msg.object?
and what happens if you check the 'deep copy' option in the change node?

1 Like

This is what I get using the output from the contrib node and your function node (edited to use the incoming msg)

return msg;


the msg looks clean ... dont know :roll_eyes:

AAaah!! I've just deleted the entire flow, recreated and for some unknown reason it's now working!

As you can see from the video above, it was not working last night, and I spent an hour this morning where it still did not work.
Up until the point where I recreated the flow, I had not updated or changed anything, either in my flows or the system.

I can offer no explanation... but thank for trying to help.

1 Like

There must have been something weird in the original message because I tried it in an inject node (which was happy that it was valid JSON) and, like you, got nothing out of the switch node. I even tried using the params version of "on". (I also tried the deep copy) and nothing worked. It would be interesting to try a copy of the output you are getting now.

1 Like

At last, a believer!!!
Although it seems functional, it's still not working as expected, although I've been reluctant to post here...
Take a look at the attached gif, it shows no output from the contrib node, yet the change node successfully changes the global context.

There are no other references to this elsewhere in my flows.

still here

Paul, if you have a MQTT broker available, try this. Send the output of the 'Switch Garden Alert' to a mqtt-out node (with an appropriate topic) and disconnect it from the change node. Add a mqtt-in node (subscribing to the topic) and connect it to the change node and see what happens.

Just grasping to see if it's something with the msg the 'Switch Garden Alert' node is generating.