Simple device incoming data transformations

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!

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 trigger that triggers whenever your device reports state data.
  2. A Conditional Node 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 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 to store the new Fahrenheit attribute on your device.

Thanks Brandon,

Roger that.

Best,

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

Phone: (805) 455-8036

Email: George.Wayne@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.

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???

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

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

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

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.

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

…but the gauge still shows 0

…and temperature (in C) shows up fine:

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.

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

1 Like

Thanks! I believe this is it: 5d9258a20dc10a00065cda01

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:

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

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

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

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.

1 Like