# Storing float from MQTT \> Influx

**URL:** <https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388>\
**Category:** General\
**Tags:** node-red-dashboard\
**Created:** [18 December 2021 13:26 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388 "2021-12-18T13:26:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![mynoderocks](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@mynoderocks](https://discourse.nodered.org/u/mynoderocks)\
**Post date:** [18 December 2021 13:26 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/1 "2021-12-18T13:26:19Z")

</div>

Hi all,  
I have a MQTT topic that seems to be storing a float as a string. Example:  
It is a reading from a electricity consumption monitor and stores 33.2 or 45.3 in MQTT as a string. I have no control of how its doing this.

I have a simple flow in node red that does:  
MQTT Electricity Topic \> Influx (Measurement)

The issue is it creates a measurement with the following Field Keys:  
Time , Value (as string)

I went into the Influx CLI and created my own measurement with Time, Value (Float) but of course (and I expected this) when I reroute the flow to that new measurement, I get the following error:

```auto

Error: A 400 Bad Request error occurred: {"error":"partial write: field type conflict: input field \"value\" on measurement \"B14023Device0Study\" is type string, already exists as type float dropped=1"

```

Which tells me of course that the flow is trying to pass a string value to a field key pairing that requires float.

**My question**

How I am thinking of it is that in the flow there is going to be a need for me to convert the value coming out of the MQTT topic as string to float, then pass that value to the influx db measurement I created with the field key pairing with the float.

So:

1. Is my thinking correct
2. What would be the easiest way to do this conversion of the string value out of the MQTT topic into a float before I pass it to the influx node to write into that measurement? From the research I found this article [Convert](https://discourse.nodered.org/t/string-to-number/988/20?page=2) I can pretty much make out how to convert it. Just want to check my thinking on point 1 first.

Would really appreciate the guidance.

---

<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:** [18 December 2021 13:39 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/2 "2021-12-18T13:39:22Z")

</div>

Insert a function node before the influx node and in there put

```auto
msg.payload = Number(msg.payload)
return msg

```

Feed it into a debug node before you connect it to the influx node to check it now shows it as a number, not a string.

---

<div class="post-metadata">

**Author:** ![mynoderocks](https://avatars.discourse-cdn.com/v4/letter/m/e274bd/32.png) [@mynoderocks](https://discourse.nodered.org/u/mynoderocks)\
**Post date:** [18 December 2021 14:25 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/3 "2021-12-18T14:25:46Z")

</div>

Thank you very much @Colin I will test that. Thank you once again I really do appreciate it.

---

<div class="post-metadata">

**Author:** ![Becker](https://avatars.discourse-cdn.com/v4/letter/b/c77e96/32.png) [@Becker](https://discourse.nodered.org/u/Becker)\
**Post date:** [19 December 2021 11:06 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/4 "2021-12-19T11:06:11Z")

</div>

Or try this:  
 ![grafik](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/a/2a9cd6aec77f2f94fbdc05070e0d4af14e204bb1.png)

---

<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:** [19 December 2021 11:48 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/5 "2021-12-19T11:48:26Z")

</div>

Yes, much better. I didn't think that worked if the data is a string containing just a number, but it does. If ever the string is not a valid number (or other valid json) then it generates an error, but that can be caught by a Catch node if necessary.

---

<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:** [17 February 2022 11:49 UTC](https://discourse.nodered.org/t/storing-float-from-mqtt-influx/55388/6 "2022-02-17T11:49:20Z")

</div>

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