# Convert mqtt output to number

**URL:** <https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038>\
**Category:** General\
**Created:** [31 January 2025 16:39 UTC](https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038 "2025-01-31T16:39:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![rojas489](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rojas489/32/98486_2.png) [@rojas489](https://discourse.nodered.org/u/rojas489)\
**Post date:** [31 January 2025 16:39 UTC](https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038/1 "2025-01-31T16:39:23Z")

</div>

I have an mqtt output of this type {“ts”: “2025-01-31T16:24:29Z”, “humidity”:56} and I am unable to convert it to number to make it readable in influxdb or grafana which is my ultimate goal. Any help on this?

---

<div class="post-metadata">

**Author:** ![rojas489](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/rojas489/32/98486_2.png) [@rojas489](https://discourse.nodered.org/u/rojas489)\
**Post date:** [31 January 2025 16:41 UTC](https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038/2 "2025-01-31T16:41:29Z")

</div>

The output comes from meraki sensors. With this topic meraki/v1/mt/L\_3698581193978019842/ble/C4:8B:A3:FC:63:36/humidity

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [31 January 2025 17:12 UTC](https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038/3 "2025-01-31T17:12:35Z")

</div>

The output is a JSON , if you set the mqtt node to auto detect object, then the output would be a Javascript object. Then msg.payload.humidity would be a number. If you require the ts as a millisecond timestamp (epoch) then you can use a function node and the [date() constructor and getTime() method](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)

```auto
msg.payload.timestamp = Date(msg.payload.ts).getTime();
return msg;

```

You can then format your payload for influxDb

p.s. Welcome to the forum.

---

<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:** [1 May 2025 17:13 UTC](https://discourse.nodered.org/t/convert-mqtt-output-to-number/95038/4 "2025-05-01T17:13:06Z")

</div>

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