Complete beginner - how to extract specific values from yaml data

I am using node red in Home Assistant and will need to use login data for many nodes that are stored in a yaml file.

This is my first node-red flow and I have managed to read a file and seemingly create a list of variable names and data.

[{"id":"07e3500b31e99eb0","type":"tab","label":"Flow 1","disabled":false,"info":"","env":[]},{"id":"4df03d8eb7fd62e1","type":"group","z":"07e3500b31e99eb0","style":{"stroke":"#999999","stroke-opacity":"1","fill":"none","fill-opacity":"1","label":true,"label-position":"nw","color":"#a4a4a4"},"nodes":["f231967.0251a68","8f8f31b7.1f916","104b80e2.51068f","5326f9221556621a"],"x":94,"y":639,"w":712,"h":82},{"id":"f231967.0251a68","type":"inject","z":"07e3500b31e99eb0","g":"4df03d8eb7fd62e1","name":"YAML String","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"a\":1}","payloadType":"str","x":210,"y":680,"wires":[["5326f9221556621a"]]},{"id":"8f8f31b7.1f916","type":"debug","z":"07e3500b31e99eb0","g":"4df03d8eb7fd62e1","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":690,"y":680,"wires":[]},{"id":"104b80e2.51068f","type":"yaml","z":"07e3500b31e99eb0","g":"4df03d8eb7fd62e1","property":"payload","name":"","x":530,"y":680,"wires":[["8f8f31b7.1f916"]]},{"id":"5326f9221556621a","type":"file in","z":"07e3500b31e99eb0","g":"4df03d8eb7fd62e1","name":"secrets","filename":"/config/secretstest.yaml","filenameType":"str","format":"utf8","chunk":false,"sendError":false,"encoding":"none","allProps":false,"x":380,"y":680,"wires":[["104b80e2.51068f"]]}]

This has resulted in the following payload

{"tplink_user":"","tplink_password":"-password-","email_sender":"","email_receiver":"","email_password":"Bovril","tablet_info":"some text","homeassistant_email_user":"","homeassistant_email_password":"Boris","ifttt_key":"xxxxxxxxxx"}

So now, if I want to get the value for email_sender and homeassistant_email_password, and be able to use these values as variables in later nodes, how do I do this?

If you look at the result in the sidebar, you can copy the path to the information that you want.


Copy it and paste it in a change node, like this...


and that should give you the data that you need.

Or to use as a variable in a function node...

const emailSender = msg.payload.email_sender

and do the same for the other password.

Thanks. I will give that a go and update this when i have tried it.

I have noticed that i seem to have had the email addresses changed since I posted, probably for security reasons. If it was human intervention, they were not real and were just gibberish that came into my mind when posting. I will stick with the firmat if that is posting standards. Not just a novice at node red but also posting on this forum!

1 Like

Yes. that was me!
You said that you are a complete beginner, and an alarm sounded when I saw the "tplink_password" & email addresses.
Now we are doubly sure that your privacy is protected :laughing:

Paul - Moderator

1 Like

You said you will use these mail and password multiple times in future.
My advice would be to store them in a context variable.
You can use flow context or global context.
There are functions to set and retrieve context variables in change node and in function node…