How do I Extract Specific Data from Payload

Hi, I am hoping someone can help me with what i think is going to be an easy question.

I am using Node Red with Home Assistant and in the above flow I would like to extract the data.entity_id from the msg.payload and use it in the follow call service node. This changes a text helper in Home Assistant to the data.entity_id value, which is then used elsewhere.

I have tried a few different ways but I only ever get "undefined" in the debug window.

Please find the flow below

Can any one help??

Thanks

Phil

[{"id":"6107a04d8c4e8be0","type":"tab","label":"Sandbox 2","disabled":false,"info":"","env":[]},{"id":"51b246ae41a95fe0","type":"inject","z":"6107a04d8c4e8be0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":160,"y":110,"wires":[["14afbf15200ffef4"]]},{"id":"14afbf15200ffef4","type":"api-call-service","z":"6107a04d8c4e8be0","name":"Trigger Morning Scene","server":"b5fb3c40.585c7","version":3,"debugenabled":true,"service_domain":"scene","service":"turn_on","entityId":"scene.lounge_morning","data":"{\"transition\":\"2\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":170,"wires":[["7973da7b6592fd79"]]},{"id":"7973da7b6592fd79","type":"api-call-service","z":"6107a04d8c4e8be0","name":"Lounge Status","server":"b5fb3c40.585c7","version":3,"debugenabled":false,"service_domain":"input_text","service":"set_value","entityId":"input_text.lounge_scene_status","data":"{\"value\":\"This is {{payload}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":780,"y":170,"wires":[["998fc3ac303bf5e5"]]},{"id":"998fc3ac303bf5e5","type":"debug","z":"6107a04d8c4e8be0","name":"Test Debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1190,"y":170,"wires":[]},{"id":"b5fb3c40.585c7","type":"server","name":"Home Assistant - HA","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30"}]

Hi Phil.

Good you opened the message as you did.

If you make that colum on the right of the screen just a bit wider and move the mouse to the right of the name you will see some more stuff that will be handy.

Anyway, what you want to use is (from what you posted)
msg.data.entity_id

So in any nodes that want to use/see that, you point the node to that part of the message.

Example:

[{"id":"b9a9e6333a35435a","type":"switch","z":"7e987ddf260bdf0d","name":"Who?","property":"data.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"scene.loung_morning","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":270,"y":2880,"wires":[["a4a0ce43993d7391"],[]]},{"id":"a4a0ce43993d7391","type":"debug","z":"7e987ddf260bdf0d","name":"Looking for this","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":490,"y":2820,"wires":[]}]

You can open the switch node and add different tests you want to do and route the messages from there.

Hi Try to learn,

Firstly, Thanks for your help.. Very much appreciated..

When you talk about opening the column wider, I think you talking about the copy path button.. I found it...

This is exactly what I did for testing and I couldnt get it to work here.
I understand the concept behind what you are saying but it doesn't work for me...
Example below:

[{"id":"6107a04d8c4e8be0","type":"tab","label":"Sandbox 2","disabled":false,"info":"","env":[]},{"id":"51b246ae41a95fe0","type":"inject","z":"6107a04d8c4e8be0","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payloadType":"date","x":160,"y":110,"wires":[["14afbf15200ffef4"]]},{"id":"14afbf15200ffef4","type":"api-call-service","z":"6107a04d8c4e8be0","name":"Trigger Morning Scene","server":"b5fb3c40.585c7","version":3,"debugenabled":true,"service_domain":"scene","service":"turn_on","entityId":"scene.lounge_morning","data":"{\"transition\":\"2\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":450,"y":170,"wires":[["b9a9e6333a35435a"]]},{"id":"7973da7b6592fd79","type":"api-call-service","z":"6107a04d8c4e8be0","name":"Lounge Status","server":"b5fb3c40.585c7","version":3,"debugenabled":false,"service_domain":"input_text","service":"set_value","entityId":"input_text.lounge_scene_status","data":"{\"value\":\"This is {{payload}}\"}","dataType":"json","mergecontext":"","mustacheAltTags":false,"outputProperties":[],"queue":"none","x":870,"y":170,"wires":[["998fc3ac303bf5e5"]]},{"id":"998fc3ac303bf5e5","type":"debug","z":"6107a04d8c4e8be0","name":"Test Debug","active":true,"tosidebar":true,"console":false,"tostatus":true,"complete":"payload","targetType":"msg","statusVal":"payload","statusType":"auto","x":1190,"y":170,"wires":[]},{"id":"b9a9e6333a35435a","type":"switch","z":"6107a04d8c4e8be0","name":"Who?","property":"payload.data.entity_id","propertyType":"msg","rules":[{"t":"eq","v":"scene.lounge_morning","vt":"str"},{"t":"else"}],"checkall":"true","repair":false,"outputs":2,"x":660,"y":230,"wires":[["a4a0ce43993d7391","7973da7b6592fd79"],["4f2ca8c599bf14f9"]]},{"id":"a4a0ce43993d7391","type":"debug","z":"6107a04d8c4e8be0","name":"Looking for this","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1010,"y":250,"wires":[]},{"id":"4f2ca8c599bf14f9","type":"debug","z":"6107a04d8c4e8be0","name":"Looking for this","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":1020,"y":390,"wires":[]},{"id":"b5fb3c40.585c7","type":"server","name":"Home Assistant - HA","version":2,"addon":true,"rejectUnauthorizedCerts":true,"ha_boolean":"y|yes|true|on|home|open","connectionDelay":true,"cacheJson":true,"heartbeat":true,"heartbeatInterval":"30"}]

If you have a look at the picture above you can see that when I do as you describe, all that is passed through is the inject timestamp, and it is passed through to the "otherwise" debug option cause the time is not "==" to scene.lounge.morning.

Ideally I do not want to treat it this way... more chance of typo errors.

I have several scenes for different rooms all triggered during the day depending on the time and the lux levels. i am looking for a way to track and see what scene is being used at a specific time. This is information is available and can be updated when the call service that sets the scene is triggered

I would like to extract the data in the complete message directly into the call service node that sets the text helper like you can do with {{payload}} using (Mustache).

I think i am waffling now...

Thanks

OK change your Debug nodes to show the complete msg object - not just the payload and then we can see what is being sent through

Craig

Ok. Thanks for the information.

Alas I can't help you with directly handling that stuff as I don't have those nodes.

What you need to do is identify what part of the message is the crucial piece you need.
I suspect you are looking at the wrong part and so it is failing.

What triggers these scenes?

If these scenes are triggered by time, it is difficult to do what you say here:

Sorry, particularly this part:

This is information is available and can be updated when the call service that sets the scene is triggered

I think we need to understand how things are triggered.

Andrew,

Yep as he is using HA he is using the Websocket components that a 3rd party has written - this enables the state of entities (e.g. a light switch is an entity) to be recorded and made available - so he is essentially polling (or waiting for realtime) event changes from within HA - it will be difficult for anyone without a HA system and the relevant Websocket nodes to be able to assist.

(Luckily i have both)

Craig

Yes and stupid me for not realising that we needed to see the entire message.

Would you mind taking over helping as it is just not possible for me to really be helpful.

Thanks in advance.

Yeah no worries - will try and keep track

Craig

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