# Adding Certain data tags to a data received by a sensor

**URL:** <https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513>\
**Category:** General\
**Tags:** function-node, mqtt\
**Created:** [9 September 2022 10:07 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513 "2022-09-09T10:07:01Z")\
**Posts on this page:** 6\
**Page:** 2

<div class="post-metadata">

**Author:** ![Hossam\_Ali](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Hossam\_Ali](https://discourse.nodered.org/u/Hossam_Ali)\
**Post date:** [13 September 2022 12:05 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/21 "2022-09-13T12:05:35Z")

</div>

I believe the second one is more appropriate for what I want but I have to do this for all the variables I am having right now. Because this is only gives the output for TempHumi. One more question, this process now should be done automatically? In other words, I am receiving the data every 10 secs, the newer values will replace the old values or this might be more appropriate for static values?

---

<div class="post-metadata">

**Author:** ![jbudd](https://avatars.discourse-cdn.com/v4/letter/j/5f8ce5/32.png) [@jbudd](https://discourse.nodered.org/u/jbudd)\
**Post date:** [13 September 2022 12:36 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/22 "2022-09-13T12:36:16Z")

</div>

> [@Hossam\_Ali](#):
>
> but I have to do this for all the variables I am having right now. Because this is only gives the output for TempHumi.

I think you have been asked more than once to show us the output you want. This is what you said:

> [@Hossam\_Ali](#):
>
> what I want to get
> 
> ```auto
> "Line_1.HA20.Temperature.Temperature.TempHumi.Range": 0,
> "Line_1.HA20.Temperature.Temperature.TempHumi.Status": 0,
> "Line_1.HA20.Temperature.Temperature.TempHumi.Event": 0
> 
> ```

Now you want something more. I trust that you can work out for yourself how to extend the "Reformat" function that I posted.  
You will probably find it useful to feed your input data to a debug node, expand the objects it contains and use the "Copy path" button.

 ![Untitled 5](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/4/b/4be131e2daa2123c20e23c8f3bdb947687dbcd24.jpeg)

> [@Hossam\_Ali](#):
>
> One more question, this process now should be done automatically?

The way Node-red works is that the code in the Reformat node will be applied to whatever data you feed in to it.  
So however you get your sensor data - HTML request, MQTT, the output of an external script - feed it into Reformat and if it is the expected format, it will be reformatted.

ps  
In your original post you said this was the desired output

> I would like to change this data tags to match this format: {line}.{unit/system/function}.{device/function}[.{device/function}[...]].property

I can't recognise that format in the quote I gave above.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 September 2022 12:51 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/23 "2022-09-13T12:51:01Z")

</div>

> [@Hossam\_Ali](#):
>
> this is only gives the output for TempHumi.

You can use `Object.entries()` and iterate all the keys in the object and change the keys to the new ones. See [Object.entries() - JavaScript | MDN](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/entries)

---

<div class="post-metadata">

**Author:** ![Hossam\_Ali](https://avatars.discourse-cdn.com/v4/letter/h/ebca7d/32.png) [@Hossam\_Ali](https://discourse.nodered.org/u/Hossam_Ali)\
**Post date:** [13 September 2022 15:23 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/24 "2022-09-13T15:23:10Z")

</div>

Okay thanks, I have one more question. you told me in a previous reply it will be different if I want it as a nested function. out of curiosity, is it possible to give me an example how will it be look like?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [13 September 2022 17:17 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/25 "2022-09-13T17:17:10Z")

</div>

> [@Hossam\_Ali](#):
>
> is it possible to give me an example how will it be look like?

When you tested the code in post #15 what result did it give?  
`msg.payload = {Line_1: {HA20: {Temperature: {Temperature: msg.payload}}}}}`

---

<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:** [12 November 2022 17:18 UTC](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513/26 "2022-11-12T17:18:03Z")

</div>

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

[Previous page](https://discourse.nodered.org/t/adding-certain-data-tags-to-a-data-received-by-a-sensor/67513.md?page=1)
