# Simple device incoming data transformations

**URL:** <https://forums.losant.com/t/simple-device-incoming-data-transformations/1044>\
**Category:** Help\
**Created:** [August 3, 2018, 4:38pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044 "2018-08-03T16:38:25Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![George\_Wayne](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@George\_Wayne](https://forums.losant.com/u/George_Wayne)\
**Post date:** [August 3, 2018, 4:38pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/1 "2018-08-03T16:38:25Z")

</div>

I have temp in C coming in from an OEM device that I sell services for. We’re US-based and need to graph temp in F on our dashboards.

How do we do this?

Thanks!

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [August 3, 2018, 8:13pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/2 "2018-08-03T20:13:11Z")

</div>

The easiest way to do this is by adding another attribute to your device for Fahrenheit and then using a workflow to convert the incoming data and store it in this new attribute. This way you always have both Celsius and Fahrenheit available.

The high-level workflow would be the following:

1. A [Device: State](https://docs.losant.com/workflows/triggers/device/) trigger that triggers whenever your device reports state data.
2. A [Conditional Node](https://docs.losant.com/workflows/logic/conditional/) that is checking that Celsius is what was reported. Since this workflow results in new state being reported, it will cause this workflow to trigger again. This check is used to skip the triggers for your already converted Fahrenheit state. The expression would be something like `{{ data.celsius }} !== undefined`, which is checking that celsius was part of the state that was reported.
3. A [Math Node](https://docs.losant.com/workflows/logic/math/) to do the conversion. The expression would look something like `{{ data.celsius }} * (9/5) + 32`. You can then store the result back on the payload at `data.fahrenheit`.
4. Lastly, add a [Device State Node](https://docs.losant.com/workflows/outputs/device-state/) to store the new Fahrenheit attribute on your device.

---

<div class="post-metadata">

**Author:** ![George\_Wayne](https://avatars.discourse-cdn.com/v4/letter/g/e47774/32.png) [@George\_Wayne](https://forums.losant.com/u/George_Wayne)\
**Post date:** [August 3, 2018, 8:32pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/3 "2018-08-03T20:32:43Z")

</div>

Thanks Brandon,

Roger that.

Best,

George Wayne | President and Chairman | Qualia Networks, Inc.

Phone: (805) 455-8036

Email: [George.Wayne@QualiaNetworks.com](mailto:George.Wayne@QualiaNetworks.com) | [http://www.QualiaNetworks.com](http://www.QualiaNetworks.com)

CONFIDENTIAL & PRIVILEGED: Both this e-mail and any attachments included with this transmission are intended solely for the use and handling of the individual or entity named above. They may contain information that is privileged, confidential, and exempt from disclosure under applicable law. If the reader of this message is not the intended recipient, or the employee or agent responsible for delivering this message to the intended recipient, any dissemination, distribution, or copying of this communication is strictly prohibited. If you have received this communication in error, please notify us immediately by telephone or e-mail and return the original message to us at the above e-mail address or via U.S. Mail, and delete and destroy any other copies of the message and attachments. Thank You.

---

<div class="post-metadata">

**Author:** ![Mark\_Nicholson](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Nicholson](https://forums.losant.com/u/Mark_Nicholson)\
**Post date:** [October 11, 2019, 8:38pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/4 "2019-10-11T20:38:32Z")

</div>

Hmm… I tried this precise setup to convert from C to F (added a new attribute to my device which is temperatureF, then run the Math Node to convert it, but I’m noticing my debug shows temperatureF without quotes while the normal temperature in C is in quotes… and thus, the dashboard can display the C fine, but zeroes out the temperatureF value when I try to use it…  
Is there something I’m missing???

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/0/05a126bd66c3ff4f7a1dbb242d6f17b5a6a3f18f.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [October 11, 2019, 8:40pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/5 "2019-10-11T20:40:56Z")

</div>

Can you please provide a screenshot of your `Device State` node’s configuration?

---

<div class="post-metadata">

**Author:** ![Mark\_Nicholson](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Nicholson](https://forums.losant.com/u/Mark_Nicholson)\
**Post date:** [October 11, 2019, 9:19pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/6 "2019-10-11T21:19:17Z")

</div>

Thx! Sure…  
temperature = {{data.body.data.fields.temperature}}  
temperatureF = {{data.body.data.fields.temperatureF}}

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/72ca667f23ffb732bf92891b503a1affaba365f5.png)

here’s the math node as well:

Expression 1: {{data.body.data.fields.temperature}} \* (9/5) + 32  
Payload result path: data.body.data.fields.temperatureF

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/c/cd09918b4ab6b1085a583e3619362e20ae7fc527.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [October 12, 2019, 9:02pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/7 "2019-10-12T21:02:26Z")

</div>

That all looks correct. Being a string vs. a number won’t impact the dashboarding since Losant handles the conversation automatically when it’s being reported as device state.

Next, I’d recommend looking at the device page and checking the state log (3rd tab on the right side device log) to see if the data is being recorded.

---

<div class="post-metadata">

**Author:** ![Mark\_Nicholson](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Nicholson](https://forums.losant.com/u/Mark_Nicholson)\
**Post date:** [October 13, 2019, 3:52am UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/8 "2019-10-13T03:52:56Z")

</div>

Ah - data looks like it’s being recorded properly:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/5/5d862fc0a59db6ffffc665a0d435cc0ab6f42c5a.png)

…but the gauge still shows 0

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/24ca8ccf2b32b02fee210cbcf73c191431fff2b5.png)

…and temperature (in C) shows up fine:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/2/28bac60e01ff3c1feb3344b3f78c52e25396e050.png)

---

<div class="post-metadata">

**Author:** ![Brandon\_Cannaday](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/brandon_cannaday/32/14_2.png) [@Brandon\_Cannaday](https://forums.losant.com/u/Brandon_Cannaday)\
**Post date:** [October 13, 2019, 1:17pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/9 "2019-10-13T13:17:21Z")

</div>

Everything looks correct here. Would you mind providing me your application ID so I can take a closer look? The application ID is available in the URL when you’re looking at the application overview page.

---

<div class="post-metadata">

**Author:** ![paul\_wareham](https://avatars.discourse-cdn.com/v4/letter/p/ed8c4c/32.png) [@paul\_wareham](https://forums.losant.com/u/paul_wareham)\
**Post date:** [October 13, 2019, 2:18pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/10 "2019-10-13T14:18:21Z")

</div>

If I recall there is actually a temperature conversion custom node in the github library

---

<div class="post-metadata">

**Author:** ![Mark\_Nicholson](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Nicholson](https://forums.losant.com/u/Mark_Nicholson)\
**Post date:** [October 14, 2019, 12:32am UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/11 "2019-10-14T00:32:48Z")

</div>

> [@Brandon\_Cannaday](#):
>
> ooking at the application overview page

Thanks! I believe this is it: 5d9258a20dc10a00065cda01

---

<div class="post-metadata">

**Author:** ![JuliaKempf](https://sea1.discourse-cdn.com/flex015/user_avatar/forums.losant.com/juliakempf/32/2446_2.png) [@JuliaKempf](https://forums.losant.com/u/JuliaKempf)\
**Post date:** [October 14, 2019, 3:28pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/12 "2019-10-14T15:28:16Z")

</div>

Hi @Mark_Nicholson,

I believe you are seeing this as state is being reported for `temperatureF` at every execution of your workflow. Since you have a Math Node doing this conversion, it is executing each time the workflow is triggered. Thus, when there is no temperature value, the conversion is producing “null” in the Math Node. Here is an example:

 ![54%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/7/77cba0b0a03cb0e7cb0be95b3e9ae682ad66564a.png)

In this screenshot, my `temperature` value was 3, so my Fahrenheit value is now 37.4.

 ![38%20AM](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/6/6974a5df742b86280c7fa472296f5a9e986424c2.png)

In this screenshot, there is no `temperature` value, which sets `working` (my Fahrenheit value) to `null`.

Since the Losant Platform is a bit “predictive” and `temperatureF` is a Number attribute, the Platform is reassigning `null` to 0. Thus, every so often you may have correct readings, but every time your Webhook is triggered and does not include a temperature value, `temperatureF` is being set to 0.

Let me know if I can explain further!  
Julia

---

<div class="post-metadata">

**Author:** ![Mark\_Nicholson](https://avatars.discourse-cdn.com/v4/letter/m/ee59a6/32.png) [@Mark\_Nicholson](https://forums.losant.com/u/Mark_Nicholson)\
**Post date:** [October 14, 2019, 4:18pm UTC](https://forums.losant.com/t/simple-device-incoming-data-transformations/1044/13 "2019-10-14T16:18:48Z")

</div>

Oh gosh … that (kind of) makes sense… at least, I now realize that incoming payloads were triggering the Math Node every time. I’m sad to hear the (new Temp) value was being overwritten each time even though each payload did not contain the original\_Temp\_C variable. Humpf… in short: annoyed (but I’m not a programmer at heart… which is why I love the node-red interface so much!), but VERY MUCH appreciative of you pointing out the logic / flow and WHY we see the 0 value. NOW that I understand this, I think I’ve fixed it (I also like closure)… so, I just added a Latch node in parallel so the Math node only fires when it sees a Temp value come in:

![image](https://us1.discourse-cdn.com/flex015/uploads/getstructure/original/2X/c/c473fb412a5f4c39f0e4c9b62b436ced60977405.png)

I just Latch when: {{data.body.data.fields.temperature}} != null  
and reset it: {{data.body.data.fields.temperature}} == null

It seems to work now as I’m finally seeing a F temp in the dashboard, woo-hoo!! Thank you!!!  
Seriously… thank you again for taking the time to review and look at this.
