# Remove “{"power":00000}” from payload

**URL:** <https://discourse.nodered.org/t/remove-power-00000-from-payload/26618>\
**Category:** General\
**Created:** [13 May 2020 20:42 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618 "2020-05-13T20:42:58Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 20:42 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/1 "2020-05-13T20:42:59Z")

</div>

I need to change the following MQTT output from

```auto
{"power":3463}

```

to

```auto
3463

```

Where the 3463 is a changing number after reading a power sensor. So it could be 0 up to 72000.

Reading the forum read this can be done in several ways so I started with the change node and

```auto
$substring(payload,6,11)

```

Changed to

```auto
$substring(payload,1,2,3,4,5,6,7,8,9,14)

```

But I seem to have this wrong? Any advice please?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 May 2020 20:48 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/2 "2020-05-13T20:48:57Z")

</div>

That payload is a valid JSON string. That means you can pass it to a JSON node which will convert it to the JavaScript object equivalent. That allows you to address the individual properties of the object directly.

Then you will be able to use a Change node to set `msg.payload` to the value of `msg.payload.power`.

There's a page in the docs that explains some of these ideas: [https://nodered.org/docs/user-guide/messages](https://nodered.org/docs/user-guide/messages)

---

<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 May 2020 21:11 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/3 "2020-05-13T21:11:02Z")

</div>

In fact if, in the mqtt node settings, you select the Output as Parsed JSON, then the node will automatically convert it from JSON to a javascript object, which you can feed straight into the Change node. However you may not even need to do that. What are you going to do with it after you have passed on the message with it in the payload.

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 21:23 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/4 "2020-05-13T21:23:23Z")

</div>

Thanks ok have got working with the change node. I have built a ESP32 Smart Power Meter from GitHub. Issue is I cant figure how to slow down the MQTT state changes as they are very sec and this is loading my PI running Home Assistant. I use Node Red on this PI and want to delay (added a delay node/limiting) the Power reading to 1 every 30s. So I created a NR MQTT flow and now want to end up with just the numeric numbers as they change but 1 reading every 30s.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 May 2020 21:37 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/5 "2020-05-13T21:37:27Z")

</div>

You can use the Delay node to do this. Configure it to be in "rate limiting" mode and pick the rate for the messages. Make sure you click the "drop intermediate messages" box.

[https://cookbook.nodered.org/basic/rate-limit-messages](https://cookbook.nodered.org/basic/rate-limit-messages)

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 21:40 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/6 "2020-05-13T21:40:19Z")

</div>

Thanks sorry I have completed that its working. I need now to only have the returned message as a numeric number example 3463 from {"power":3463} with the understanding that the number can range from 0 to 7200.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 May 2020 21:44 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/7 "2020-05-13T21:44:29Z")

</div>

I'm gonna guess you didn't read & absorb the link posted twice by 2 people.

#### {"power":3463} is JSON == JavaScript object notation.

Pass the data to a json node then you WILL get the value as a number. Because it is a number.

[This video](https://youtu.be/z-mwVUBhcL4) cleanly explains what we were saying

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [13 May 2020 22:16 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/8 "2020-05-13T22:16:01Z")

</div>

Dropping 29 out of 30 samples is not that nice.  
You can miss vital information. What if sample 18-23 is a current peak?

Better feed the 30 samples in the calculator node and release the mean value after 30 samples. You get then 1 output in 30 sec with the average of the last 30sec.

# node-red-contrib-calculate

Sorry I'm on my tablet and can't give you a example now.

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 22:51 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/9 "2020-05-13T22:51:05Z")

</div>

> [@edje11](#):
>
> node-red-contrib-calculate

Nice added the palette and this is averaging reading every 30s so thank you.

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 23:27 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/10 "2020-05-13T23:27:47Z")

</div>

Passing it to a JSON node gives me the following 4002 but in the debug is power:4002 and the flow debug reports Topic removed, non numerical value found. if I copy the path I see payload.power and the value is 4002 but the flow reports non numerical value found. Watched the video and I still dont see what I am doing wrong?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [13 May 2020 23:32 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/11 "2020-05-13T23:32:31Z")

</div>

Without a screenshot or your flow it is difficult to tell but I suspect where ever you're sending it to wants the value to be in payload. So add a change node after the JSON node, set msg.payload to msg.palyload.power then send it to where it needs to go.

Ps, that video is part of a series. They are nice short 2m easily digestible & hugely beneficial to watch. Honestly, invest 20mins watching the series. All of what I said above just clicks into place.

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [13 May 2020 23:36 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/12 "2020-05-13T23:36:38Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/e/fe5c2eb5084c024701320039259b274c4e00f250.png)

Top flow works with change node  
Bottom flow with delay / json node path payload and value is 3671 which is correct. So I want to replace the change node with the json which throws the error of non numerical value found which I suspect is power: portion. Will also watch the videos...

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [14 May 2020 01:11 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/13 "2020-05-14T01:11:49Z")

</div>

> [@droidblast](#):
>
> So I want to replace the change node with the json which throws the error of non numerical value found which I suspect is power: portion

So pretty much exactly as I said...

> [@Steve-Mcl](#):
>
> add a change node after the JSON node, set msg.payload to msg.palyload.power then send it to where it needs to go

---

<div class="post-metadata">

**Author:** ![droidblast](https://avatars.discourse-cdn.com/v4/letter/d/cdc98d/32.png) [@droidblast](https://discourse.nodered.org/u/droidblast)\
**Post date:** [28 May 2020 22:02 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/14 "2020-05-28T22:02:31Z")

</div>

Thanks its now working. Whats the best way to change payload 66.0909090909091 limit to four numbers so its 66.09?

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [28 May 2020 22:15 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/15 "2020-05-28T22:15:09Z")

</div>

Well if it's a number you can use toFixed or round

Some good info [here](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary)

---

<div class="post-metadata">

**Author:** ![JGKK](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/jgkk/32/18515_2.png) [@JGKK](https://discourse.nodered.org/u/JGKK)\
**Post date:** [29 May 2020 05:27 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/17 "2020-05-29T05:27:46Z")

</div>

You can use a change node with a [jsonata round function](http://docs.jsonata.org/numeric-functions#round). This gives you the option to round it to any precision you would like just with a change node and no function or additional node needed.

---

<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:** [29 May 2020 14:26 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/18 "2020-05-29T14:26:03Z")

</div>

If you want to round it for display in the dashboard that is better done in the ui widget itself. You can use  
`{{value | number:2}}`

---

<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:** [28 July 2020 14:26 UTC](https://discourse.nodered.org/t/remove-power-00000-from-payload/26618/19 "2020-07-28T14:26:03Z")

</div>

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