OpenWeather Fahrenheit Calcularion Incorrect?

Discussions about Z-Way software and Z-Wave technology in general
Post Reply
islipfd19
Posts: 126
Joined: 07 Jul 2014 03:35

OpenWeather Fahrenheit Calcularion Incorrect?

Post by islipfd19 »

I selected the OpenWeather module and entered my desired info and selected Fahrenheit as the display type. I noticed that the temperarure was off by a few degrees. I looked into the index.js file itself and found it odd on how the calculation was being performed. The line below is from the original index.js file

Code: Select all

var temp = Math.round((self.config.units === "celsius" ? res.data.main.temp - 273.15 : res.data.main.temp) * 10) / 10,
Now, OpenWeather.org provides the temperature in measurement of Kelvin, the formula to convert Kelvin to Celsius is straight forward. K - 273.15. And as you see in the above line of code; if Celsius is selected it performs that math correctly. But the Fahrenheit formula being used here is (K * 10) / 10 when the actual formula is (K * 9) / 5 - 459.67 (yes I did google it and there are a couple of ways to convert Kelvin to Fahrenheit but I found this method to implement to be the easiest).

My new line of code is provided below.

Code: Select all

var temp = Math.round(self.config.units === "celsius" ? res.data.main.temp - 273.15 : res.data.main.temp * 9) / 5 - 459.67,
I did make PoltoS aware of this. It will be verified, he also wanted me to share it here.
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Post by PoltoS »

If OpenWeather always provide data in Kelvin degrees, the correct formula would be:

Code: Select all

var temp = Math.round((res.data.main.temp - 273.15) * (self.config.units === "celsius" ? 1.0 : 1.8) * 10) / 10
n0ahg
Posts: 87
Joined: 08 May 2013 23:41

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Post by n0ahg »

OpenWeatherMap can provide the temperature in the correct format with no client side conversion required. I had a fix if you want me to submit it to github.
User avatar
PoltoS
Posts: 7571
Joined: 26 Jan 2011 19:36

Re: OpenWeather Fahrenheit Calcularion Incorrect?

Post by PoltoS »

Why not. But as far as I see, current version should work OK.
Post Reply