Change node- move, change or other

Been a while since I used Node Red and I'm struggling with a simple change :frowning:

A test inject node works sending values of on/ off in this Json:-
image

I've tried every permutation of change node I can think of to move the payload from this message to recreate the on/ off value and "status" prefix of the inject node:-
image

Could anyone help point me in the right direction?

Thanks!

If you require help first supply the data in a format that is copyable. AS it's hard to help and type everything out. Specially as node-red editor supplies an easy way to do this.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

You could also supply a example of the flow you are having issues with. How to import/export a flow

Have you tried
rule 1
move msg. payload
to msg. temp
rule 2
set msg. payload.status
to value of msg. temp

In your debug output msg.payload is a string not an object. So you cannot just set msg.payload.status to "on".
But in your change mode you can use Jsonata to move msg.payload to msg.payload.status:


[{"id":"275d48d7deedca85","type":"inject","z":"91c63d1f8d7f4855","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":470,"y":80,"wires":[["4b9ddd98677a09e9"]]},{"id":"4b9ddd98677a09e9","type":"change","z":"91c63d1f8d7f4855","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"status\": payload }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":100,"wires":[["15edac950b2a488e"]]},{"id":"15edac950b2a488e","type":"debug","z":"91c63d1f8d7f4855","name":"debug 14","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":780,"y":100,"wires":[]},{"id":"f60feb82917e4c22","type":"inject","z":"91c63d1f8d7f4855","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":470,"y":120,"wires":[["4b9ddd98677a09e9"]]}]

You can also do it in a 3 step change process without using jsonata

Thanks! I tried both but still no joy. The problem is the first line of the debug- it's not in the payload.
(ie "status" : msg : Object)

Sorry, I've forgotten so much of NR- I hope this block quote works

[{"id":"f75612526651b66a","type":"tab","label":"Alexa Control","disabled":false,"info":"","env":[]},{"id":"3944e70d94a98631","type":"amazon-echo-hub","z":"f75612526651b66a","port":"80","processinput":0,"discovery":true,"x":170,"y":100,"wires":[["0191304a929805e2","47dfa50f495b59d3","35bcdada7997948a"]]},{"id":"0191304a929805e2","type":"amazon-echo-device","z":"f75612526651b66a","name":"Couch","topic":"\"status\"","x":370,"y":100,"wires":[["ca62ba73fe5381c8","6c14e438223505cc"]]},{"id":"445cd042.1a027","type":"hs-device","z":"f75612526651b66a","name":"Couch","device":"2460","server":"1ac8f262.75bd9e","feature":"2465","reportonstartup":true,"x":810,"y":240,"wires":[["8790e2d4741f827b"]]},{"id":"6fcee1cc.8b778","type":"inject","z":"f75612526651b66a","name":"On","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":\"on\"}","payloadType":"json","x":640,"y":220,"wires":[["445cd042.1a027","1f89085b.6e18e8"]]},{"id":"85322bf8.50d818","type":"inject","z":"f75612526651b66a","name":"Off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":\"off\"}","payloadType":"json","x":640,"y":280,"wires":[["445cd042.1a027","1f89085b.6e18e8"]]},{"id":"1f89085b.6e18e8","type":"debug","z":"f75612526651b66a","name":"Inject req'd","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":360,"wires":[]},{"id":"8790e2d4741f827b","type":"debug","z":"f75612526651b66a","name":"Couch Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":240,"wires":[]},{"id":"ca62ba73fe5381c8","type":"debug","z":"f75612526651b66a","name":"Pre-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":100,"wires":[]},{"id":"47dfa50f495b59d3","type":"amazon-echo-device","z":"f75612526651b66a","name":"Lower Hall Light","topic":"","x":400,"y":160,"wires":[[]]},{"id":"4189ed91221ed19e","type":"debug","z":"f75612526651b66a","name":"Post-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"35bcdada7997948a","type":"debug","z":"f75612526651b66a","name":"debug 3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":380,"y":40,"wires":[]},{"id":"6c14e438223505cc","type":"change","z":"f75612526651b66a","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{\"status\": \"\"}","tot":"json"},{"t":"set","p":"status","pt":"msg","to":"payload.status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":160,"wires":[["4189ed91221ed19e"]]},{"id":"46fd271edac9620c","type":"inject","z":"f75612526651b66a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":450,"y":520,"wires":[["469875e2264e8064"]]},{"id":"469875e2264e8064","type":"change","z":"f75612526651b66a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"status\": payload }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":540,"wires":[["6f6766c05aa5a3ec"]]},{"id":"6f6766c05aa5a3ec","type":"debug","z":"f75612526651b66a","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":540,"wires":[]},{"id":"fa69df1927dbfefe","type":"inject","z":"f75612526651b66a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":450,"y":560,"wires":[["469875e2264e8064"]]},{"id":"1ac8f262.75bd9e","type":"hs-server","name":"Homeseer","host":"192.168.178.230","port":"80"}]

Here is a whole raw message (from Amazon Echo-hub input node)

07/05/2024, 22:56:56node: Pre-Debug"status" : msg : Object

object

on: true

bri: 254

percentage: 100

hue: 0

sat: 254

xy: array[2]

0: 0.6484272236872118

1: 0.33085610147277794

ct: 199

rgb: array[3]

0: 254

1: 0

2: 0

colormode: "ct"

meta: object

insert: object

by: "alexa"

details: object

ip: "::ffff:192.168.178.233"

user_agent: undefined

date: "2024-05-07T21:56:44.514Z"

input: object

on: true

changes: object

empty

payload: "on"

deviceid: "0191304a929805e2"

topic: ""status""

_msgid: "5d901a6b7faa436f"

To copy (re)usable data that others can use in a demo flow, please use the copy value button.

There’s a great page in the docs (Working with messages : Node-RED) that will explain how to use the debug panel to find the right path/value for any data item.

Pay particular attention to the part about the buttons that appear under your mouse pointer when you over hover a debug message property in the sidebar.

BX00Cy7yHi

Thanks. But there's no copy on the first line- the "status" : msg : Object

In the good inject this is just msg.payload : Object

The assistance proposed above just moves the data within the payload...

I'm maybe being stupid but in the message help I can't see or remember how to vary that opening part of the message

This is the third step of my 3 step suggestion
image

And this is the third step of the "Change - 3 rules" node you posted above.

They are not the same.

But I don't know if that will resolve the issue because I am far from clear what you want to achieve and what data you start off with.

1 Like

Apologies, I'd accidentally deleted a connector when tidying up to post...

Re-added with comments on test buttons

[{"id":"f75612526651b66a","type":"tab","label":"Alexa Control","disabled":false,"info":"","env":[]},{"id":"3944e70d94a98631","type":"amazon-echo-hub","z":"f75612526651b66a","port":"80","processinput":0,"discovery":true,"x":170,"y":100,"wires":[["0191304a929805e2","47dfa50f495b59d3","35bcdada7997948a"]]},{"id":"0191304a929805e2","type":"amazon-echo-device","z":"f75612526651b66a","name":"Couch","topic":"\"status\"","x":370,"y":100,"wires":[["ca62ba73fe5381c8","6c14e438223505cc"]]},{"id":"445cd042.1a027","type":"hs-device","z":"f75612526651b66a","name":"Couch","device":"2460","server":"1ac8f262.75bd9e","feature":"2465","reportonstartup":true,"x":810,"y":240,"wires":[["8790e2d4741f827b"]]},{"id":"6fcee1cc.8b778","type":"inject","z":"f75612526651b66a","name":"On","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":\"on\"}","payloadType":"json","x":630,"y":340,"wires":[["445cd042.1a027","1f89085b.6e18e8"]]},{"id":"85322bf8.50d818","type":"inject","z":"f75612526651b66a","name":"Off","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"status\":\"off\"}","payloadType":"json","x":630,"y":400,"wires":[["445cd042.1a027","1f89085b.6e18e8"]]},{"id":"1f89085b.6e18e8","type":"debug","z":"f75612526651b66a","name":"Inject req'd","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":360,"wires":[]},{"id":"8790e2d4741f827b","type":"debug","z":"f75612526651b66a","name":"Couch Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":240,"wires":[]},{"id":"ca62ba73fe5381c8","type":"debug","z":"f75612526651b66a","name":"Pre-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":100,"wires":[]},{"id":"47dfa50f495b59d3","type":"amazon-echo-device","z":"f75612526651b66a","name":"Lower Hall Light","topic":"","x":400,"y":160,"wires":[[]]},{"id":"4189ed91221ed19e","type":"debug","z":"f75612526651b66a","name":"Post-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]},{"id":"35bcdada7997948a","type":"debug","z":"f75612526651b66a","name":"debug 3","active":false,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":380,"y":40,"wires":[]},{"id":"6c14e438223505cc","type":"change","z":"f75612526651b66a","name":"","rules":[{"t":"set","p":"status","pt":"msg","to":"payload","tot":"msg"},{"t":"set","p":"payload","pt":"msg","to":"{\"status\": \"\"}","tot":"json"},{"t":"set","p":"status","pt":"msg","to":"payload.status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":660,"y":160,"wires":[["4189ed91221ed19e","445cd042.1a027"]]},{"id":"46fd271edac9620c","type":"inject","z":"f75612526651b66a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"on","payloadType":"str","x":450,"y":520,"wires":[["469875e2264e8064"]]},{"id":"469875e2264e8064","type":"change","z":"f75612526651b66a","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"status\": payload }","tot":"jsonata"}],"action":"","property":"","from":"","to":"","reg":false,"x":620,"y":540,"wires":[["6f6766c05aa5a3ec"]]},{"id":"6f6766c05aa5a3ec","type":"debug","z":"f75612526651b66a","name":"debug 15","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":820,"y":540,"wires":[]},{"id":"fa69df1927dbfefe","type":"inject","z":"f75612526651b66a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"off","payloadType":"str","x":450,"y":560,"wires":[["469875e2264e8064"]]},{"id":"66dc7946c418ce86","type":"comment","z":"f75612526651b66a","name":"Test","info":"","x":450,"y":380,"wires":[]},{"id":"1ac8f262.75bd9e","type":"hs-server","name":"Homeseer","host":"192.168.178.230","port":"80"}]

That would probably be because you are not applying the advise correctly.

Here is an example flow

[{"id":"2578f97fb93bc8c6","type":"inject","z":"f75612526651b66a","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":500,"y":100,"wires":[["35544d8d2b3a2d27"]]},{"id":"35544d8d2b3a2d27","type":"function","z":"f75612526651b66a","name":"simulate echo node","func":"msg = {\n    \"on\":true,\n    \"bri\":254,\n    \"percentage\":100,\n    \"hue\":0,\n    \"sat\":254,\n    \"xy\":[0.6484272236872118,0.33085610147277794],\n    \"ct\":199,\n    \"rgb\":[254,0,0],\n    \"colormode\":\"ct\",\n    \"meta\":{\n        \"insert\":{\n            \"by\":\"alexa\",\n            \"details\":{\n                \"ip\":\"::ffff:192.168.1.40\",\n                \"date\":\"2024-05-07T22:51:34.881Z\"\n            }\n        },\n        \"input\":{\n            \"on\":true\n        },\n        \"changes\":{}\n    },\n    \"payload\":\"on\",\n    \"deviceid\":\"e4ab0e92b3c228\",\n    \"topic\":\"dddddd\",\n    \"_msgid\":\"ec9ee98f.ddae98\"\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":690,"y":100,"wires":[["6c14e438223505cc"]]},{"id":"6c14e438223505cc","type":"change","z":"f75612526651b66a","name":"","rules":[{"t":"move","p":"payload","pt":"msg","to":"payload.status","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":670,"y":160,"wires":[["4189ed91221ed19e"]]},{"id":"4189ed91221ed19e","type":"debug","z":"f75612526651b66a","name":"Post-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":870,"y":160,"wires":[]}]

I simulated the amazon echo nodes output.
Here is proof it woks.

1 Like

No, because that is just a label, the next thing down, "object", is the data value & that is what is important to grab the data in a usable format. Exactly like the gif I posted.

1 Like

Thanks for the help.

I'm still getting no luck so it may be some of the other payload is messing up the input node the change node is serving.

What I'm trying to do is take an on/ off command from Amazon Echo, transpose it and serve it to a connector node for a (Homeseer) Home Automation app. The on/ off inject nodes and the output have been working fine- the new additions are the Echo nodes.

I've found a post on the Homeseer forum where others have it working, they've used a switch node as well as a change node for some reason.
I'll dig into it and try to understand better when I next get a break from work.
The homeseer post is here in case anyone's searching in future:-

Alexa - Node.Red - HS - HomeSeer Message Board

Thanks again and apologies for dizziness. My memory is fading a bit...

According to that forum the amazon echo msg.payload is "on" but HS requires "On". Also looks like you need to send msg.topic to, set to "control".
something like this

[{"id":"2578f97fb93bc8c6","type":"inject","z":"d1395164b4eec73e","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":200,"y":4460,"wires":[["35544d8d2b3a2d27"]]},{"id":"35544d8d2b3a2d27","type":"function","z":"d1395164b4eec73e","name":"simulate echo node","func":"msg = {\n    \"on\":true,\n    \"bri\":254,\n    \"percentage\":100,\n    \"hue\":0,\n    \"sat\":254,\n    \"xy\":[0.6484272236872118,0.33085610147277794],\n    \"ct\":199,\n    \"rgb\":[254,0,0],\n    \"colormode\":\"ct\",\n    \"meta\":{\n        \"insert\":{\n            \"by\":\"alexa\",\n            \"details\":{\n                \"ip\":\"::ffff:192.168.1.40\",\n                \"date\":\"2024-05-07T22:51:34.881Z\"\n            }\n        },\n        \"input\":{\n            \"on\":true\n        },\n        \"changes\":{}\n    },\n    \"payload\":\"on\",\n    \"deviceid\":\"e4ab0e92b3c228\",\n    \"topic\":\"dddddd\",\n    \"_msgid\":\"ec9ee98f.ddae98\"\n}\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":390,"y":4460,"wires":[["5e03c58d3a7f5f80"]]},{"id":"5e03c58d3a7f5f80","type":"switch","z":"d1395164b4eec73e","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"on","vt":"str"},{"t":"eq","v":"off","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":170,"y":4580,"wires":[["6c14e438223505cc"],["f4d6f0d3167e2dad"]]},{"id":"6c14e438223505cc","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"status\": \"On\"}","tot":"json"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":4560,"wires":[["4189ed91221ed19e"]]},{"id":"f4d6f0d3167e2dad","type":"change","z":"d1395164b4eec73e","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"{\"status\": \"Off\"}","tot":"json"},{"t":"set","p":"topic","pt":"msg","to":"control","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":4600,"wires":[["4189ed91221ed19e"]]},{"id":"4189ed91221ed19e","type":"debug","z":"d1395164b4eec73e","name":"Post-Debug","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":570,"y":4580,"wires":[]}]

Thanks. I got there in the end, as you say it was simply setting msg.topic to control which you can do in the Echo node. The test inject nodes work without this presumably as there’s no other data in payload.

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