This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Openweather api
#1
Openweather api
Hello
I am implementing the Openweather API in a wiser for KNX.
For now the current time I get it perfectly and I can save the data in virtual objects.
This is the script.
Code:
require('json') http = require('socket.http') escape = require('socket.url').escape key = 'xxxxxxxxxxxxxxxxxxx' location = 'city' url = 'http://api.weatherstack.com/current?access_key=%s&query=%s&lang=es' url = string.format(url, key, escape(location)) res = http.request(url) data = json.pdecode(res) if type(data) ~= 'table' then   alert('failed to load weather data')   return end if data.error then   log('error', data.error)   return end current = data.current log(current) -- temperature grp.write('32/2/10', current.temperature) -- Dirección del viento grp.write('32/2/11', current.wind_dir) -- Velocidad del viento grp.write('32/2/12', current.wind_speed) -- Humedad grp.write('32/2/13', current.humidity) -- Presión grp.write('32/2/14', current.pressure) -- Descripción grp.write('32/2/15', current.weather_descriptions) -- ¿Día/Noche? grp.write('32/2/16',current.is_day) -- ¿Índice UV? if current.uv_index <2  then   grp.write('32/2/17','Bajo')   elseif current.uv_index == 3  then     grp.write('32/2/17','Normal')     elseif current.uv_index == 4  then     grp.write('32/2/17','Normal')     elseif current.uv_index == 5  then     grp.write('32/2/17','Normal')     elseif current.uv_index == 6  then     grp.write('32/2/17','Alto')     elseif current.uv_index == 7  then     grp.write('32/2/17','Alto')     elseif current.uv_index == 8  then     grp.write('32/2/17','Muy Alto')     elseif current.uv_index == 9  then     grp.write('32/2/17','Muy Alto')     elseif current.uv_index == 10  then     grp.write('32/2/17','Muy Alto')     elseif current.uv_index >11  then     grp.write('32/2/17','Extremadamente Alto') end
This is the result on the current variable
Code:
weather 20.07.2020 13:00:38 * table: ["cloudcover"]   * number: 0 ["visibility"]   * number: 10 ["observation_time"]   * string: 10:53 AM ["uv_index"]   * number: 7 ["wind_dir"]   * string: SE ["humidity"]   * number: 59 ["weather_descriptions"]   * table:    [1]     * string: Sunny ["wind_speed"]   * number: 17 ["weather_code"]   * number: 113 ["is_day"]   * string: yes ["pressure"]   * number: 1014 ["precip"]   * number: 0 ["weather_icons"]   * table:    [1]     * string: https://assets.weatherstack.com/images/wsymbols01_png_64/wsymbol_0001_sunny.png ["feelslike"]   * number: 32 ["temperature"]   * number: 30 ["wind_degree"]   * number: 130

The problem is with weather_descriptions, I see that it is a table and I assign it to an object like the others, if I log it, the contents of the table appear to me, the object is updated but it does not show anything. It is defined as the 14 byte DPT ASCII string. How do I get that data from that table inside another table and assign it to the object?

Also I would like to know if it is possible to use in a conditional loop if a range of numbers, for example that it only be executed if it is between 8 and 10. Since I don't know how to do it I have evaluated each value independently at the end of the script. I do this so that the UV index is displayed in text instead of a number.
a greeting

Thank you very much
Reply


Messages In This Thread
Openweather api - by JRP - 20.07.2020, 11:13
RE: Openweather api - by admin - 20.07.2020, 11:16
RE: Openweather api - by JRP - 20.07.2020, 11:49
RE: Openweather api - by admin - 20.07.2020, 11:53
RE: Openweather api - by JRP - 20.07.2020, 15:43
RE: Openweather api - by JRP - 01.09.2020, 16:32
RE: Openweather api - by admin - 01.09.2020, 16:50
RE: Openweather api - by JRP - 02.09.2020, 11:01
RE: Openweather api - by admin - 02.09.2020, 11:09
RE: Openweather api - by victor.back - 14.11.2020, 20:37
RE: Openweather api - by JRP - 02.09.2020, 11:20
RE: Openweather api - by admin - 02.09.2020, 11:22
RE: Openweather api - by JRP - 02.09.2020, 11:41
RE: Openweather api - by Daniel - 02.09.2020, 11:43
RE: Openweather api - by JRP - 02.09.2020, 12:12
RE: Openweather api - by admin - 15.11.2020, 09:05
RE: Openweather api - by victor.back - 15.11.2020, 20:10
RE: Openweather api - by admin - 16.11.2020, 07:40
RE: Openweather api - by victor.back - 01.01.2021, 21:07
RE: Openweather api - by JRP - 19.04.2021, 10:20
RE: Openweather api - by admin - 19.04.2021, 10:23
RE: Openweather api - by JRP - 19.04.2021, 10:31
RE: Openweather api - by admin - 19.04.2021, 10:33
RE: Openweather api - by JRP - 19.04.2021, 10:38
RE: Openweather api - by admin - 19.04.2021, 10:41
RE: Openweather api - by JRP - 19.04.2021, 10:47
RE: Openweather api - by admin - 19.04.2021, 10:53
RE: Openweather api - by JRP - 19.04.2021, 11:04
RE: Openweather api - by davidchispas - 21.07.2021, 10:34
RE: Openweather api - by Daniel - 21.07.2021, 10:51
RE: Openweather api - by JRP - 30.08.2022, 10:28
RE: Openweather api - by admin - 30.08.2022, 10:29
RE: Openweather api - by JRP - 08.09.2022, 09:47

Forum Jump: