# How do I Extract Specific Data from Payload

**URL:** <https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492>\
**Category:** General\
**Created:** [12 January 2022 00:24 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492 "2022-01-12T00:24:32Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![nld77](https://avatars.discourse-cdn.com/v4/letter/n/bcef8e/32.png) [@nld77](https://discourse.nodered.org/u/nld77)\
**Post date:** [12 January 2022 00:24 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/1 "2022-01-12T00:24:32Z")

</div>

![Image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/8/9/8900f4446f49e69d5449a5682fdec737aeeae77f.png)

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

```auto
[{"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"}]

```

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 January 2022 00:35 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/2 "2022-01-12T00:35:49Z")

</div>

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:

```auto
[{"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.

---

<div class="post-metadata">

**Author:** ![nld77](https://avatars.discourse-cdn.com/v4/letter/n/bcef8e/32.png) [@nld77](https://discourse.nodered.org/u/nld77)\
**Post date:** [12 January 2022 01:16 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/3 "2022-01-12T01:16:47Z")

</div>

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:

```auto
[{"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"}]

```

 ![Capture-0112](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/2/c2402acc60b61e354437dca6904ec23a5fe0cd74.png)

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

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 January 2022 06:15 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/4 "2022-01-12T06:15:06Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 January 2022 06:15 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/5 "2022-01-12T06:15:21Z")

</div>

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:

> [@nld77](#):
>
> 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

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.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 January 2022 06:24 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/6 "2022-01-12T06:24:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Trying\_to\_learn](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/trying_to_learn/32/28400_2.png) [@Trying\_to\_learn](https://discourse.nodered.org/u/Trying_to_learn)\
**Post date:** [12 January 2022 06:34 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/7 "2022-01-12T06:34:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![craigcurtin](https://avatars.discourse-cdn.com/v4/letter/c/94ad74/32.png) [@craigcurtin](https://discourse.nodered.org/u/craigcurtin)\
**Post date:** [12 January 2022 06:38 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/8 "2022-01-12T06:38:00Z")

</div>

Yeah no worries - will try and keep track

Craig

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 March 2022 06:38 UTC](https://discourse.nodered.org/t/how-do-i-extract-specific-data-from-payload/56492/9 "2022-03-13T06:38:41Z")

</div>

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