johnwalicki / node-red-contrib-twc-weather

Node-RED nodes for The Weather Company and Weather Underground Personal Weather Station APIs
Apache License 2.0
10 stars 11 forks source link

temperature value with one decimal place after decimal point #8

Closed milanissimo1989 closed 2 years ago

milanissimo1989 commented 2 years ago

Hello, is there a possibility that the temperature value is read out with one decimal place after the decimal point? Sorry for my bad english.

metric: object temp: 3 -----> e.g. 3,1 ? heatIndex: 3 dewpt: 2 windChill: 3 windSpeed: 3 windGust: 5 pressure: 994.14 precipRate: 0 precipTotal: 1.6 elev: 423

johnwalicki commented 2 years ago

The Node-RED node just passes thru the values from the TWC api call. It doesn't modify the value or add decimal places. Which node are you using in your flow?

milanissimo1989 commented 2 years ago

hey i using this one "pws observations"

johnwalicki commented 2 years ago

Hi - Glad that you find the TWC PWS Node-RED nodes helpful. Here is the TWC API Documentation Link : https://ibm.co/v2PWSCC The Node-RED PWS Observations node calls this API. If you want to add a decimal to a whole number, use .toFixed(1)

var formatted_temp = msg.payload.observations[0].metric.temp.toFixed(1);
johnwalicki commented 2 years ago

@milanissimo1989 - Did the above suggestion work? I'd like to close this issue.

milanissimo1989 commented 2 years ago

Where do I enter the line? In a function node? Unfortunately, I am only a beginner.

jimison commented 2 years ago

Update: added numericPrecision API feature in Pull Request.

In the TWC API Documentation:

image

I've confirmed that by appending my URL to include "&numericPrecision=decimal", several values are returned with a fixed tenths place instead of just integers. The affected values are as follows:

All other values remain unchanged.

Adding this as an Numeric Precision dropdown with options of Integer or Decimal to the API call should suffice. If Integer is selected, leave the API request as is. If Decimal is selected, append the request with "&numericPrecision=decimal".

Hope this helps!

jimison commented 2 years ago

Created pull requests for the changes to pws-current.js and pws-current.html (sorry for the separate requests).

johnwalicki commented 2 years ago

Excellent - Thanks @jimison - Closing this issue. Fixed by #10 I will bundle a node-red-contrib-twc-weather 0.5.0 and push to npmjs.