h_tag

OWM-Temperatur

Jan 31st, 2016
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. selfId = fibaro:getSelfId()
  2. local id = fibaro:get(70, "IPAddress")
  3. local APPID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  4. fibaro:debug(selfId);
  5.  
  6. HC3 = Net.FHttp("api.openweathermap.org")
  7. danem, statusm = HC3:GET("/data/2.5/weather?q="..id.."&units=metric&APPID="..APPID)
  8. danef, statusf = HC3:GET("/data/2.5/forecast?q="..id.."&units=metric&APPID="..APPID)
  9.  
  10. local ajson=json.decode(danem)
  11. local tempmin=ajson.main.temp_min
  12. local tempmax=ajson.main.temp_max
  13. local pressure=ajson.main.pressure
  14. local humidity=ajson.main.humidity
  15. local city=ajson.name
  16. local wind=ajson.wind.speed
  17. local tempcurr=ajson.main.temp
  18. local weather=ajson.weather[1].description
  19.  
  20. local tm=ajson.dt
  21.  
  22. local ajsonf=json.decode(danef)
  23. local n
  24. local t
  25.  
  26. for i = 1,5 do
  27.   t = ajsonf.list[i].dt
  28.   if t > tm then
  29.     n = i
  30.     break
  31.   end
  32. end
  33.  
  34. local ftempmin=ajsonf.list[n].main.temp_min
  35. local ftempmax=ajsonf.list[n].main.temp_max
  36. local fpressure=ajsonf.list[n].main.pressure
  37. local fhumidity=ajsonf.list[n].main.humidity
  38. local fwind=ajsonf.list[n].wind.speed
  39.  
  40. if ftempmin > tempmin then
  41.   fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(↑%3.1f)", tempmin, ftempmin))
  42. elseif ftempmin < tempmin then
  43.   fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(↓%3.1f)", tempmin, ftempmin))
  44. else
  45.   fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(-)", tempmin))
  46. end
  47.  
  48. if ftempmax > tempmax then
  49.   fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(↑%3.1f)", tempmax, ftempmax))
  50. elseif ftempmax < tempmax then
  51.   fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(↓%3.1f)", tempmax, ftempmax))
  52. else
  53.   fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(-)", tempmax))
  54. end
  55.  
  56. if fpressure > pressure then
  57.   fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(↑%d)", pressure, fpressure))
  58. elseif fpressure < pressure then
  59.   fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(↓%d)", pressure, fpressure))
  60. else
  61.   fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(-)", pressure))
  62. end
  63.  
  64. if fhumidity > humidity then
  65.   fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(↑%d)", humidity, "%", fhumidity))
  66. elseif fhumidity < humidity then
  67.   fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(↓%d)", humidity, "%", fhumidity))
  68. else
  69.   fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(-)", humidity, "%"))
  70. end
  71.  
  72. if fwind > wind then
  73.   fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(↑%4.1f)", wind, fwind))
  74. elseif fwind < wind then
  75.   fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(↓%4.1f)", wind, fwind))
  76. else
  77.   fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(-)", wind))
  78. end
  79.  
  80.   fibaro:call(selfId,"setProperty","ui.Label6.value",city)
  81.  
  82.   fibaro:call(selfId,"setProperty","ui.Label91.value",weather)
  83.  
  84.   fibaro:call(selfId,"setProperty","ui.Label8.value",string.format("%3.2f°C", tempcurr))
  85.   fibaro:setGlobal("OWM_Temp", tempcurr)
Add Comment
Please, Sign In to add comment