Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- selfId = fibaro:getSelfId()
- local id = fibaro:get(70, "IPAddress")
- local APPID="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
- fibaro:debug(selfId);
- HC3 = Net.FHttp("api.openweathermap.org")
- danem, statusm = HC3:GET("/data/2.5/weather?q="..id.."&units=metric&APPID="..APPID)
- danef, statusf = HC3:GET("/data/2.5/forecast?q="..id.."&units=metric&APPID="..APPID)
- local ajson=json.decode(danem)
- local tempmin=ajson.main.temp_min
- local tempmax=ajson.main.temp_max
- local pressure=ajson.main.pressure
- local humidity=ajson.main.humidity
- local city=ajson.name
- local wind=ajson.wind.speed
- local tempcurr=ajson.main.temp
- local weather=ajson.weather[1].description
- local tm=ajson.dt
- local ajsonf=json.decode(danef)
- local n
- local t
- for i = 1,5 do
- t = ajsonf.list[i].dt
- if t > tm then
- n = i
- break
- end
- end
- local ftempmin=ajsonf.list[n].main.temp_min
- local ftempmax=ajsonf.list[n].main.temp_max
- local fpressure=ajsonf.list[n].main.pressure
- local fhumidity=ajsonf.list[n].main.humidity
- local fwind=ajsonf.list[n].wind.speed
- if ftempmin > tempmin then
- fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(↑%3.1f)", tempmin, ftempmin))
- elseif ftempmin < tempmin then
- fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(↓%3.1f)", tempmin, ftempmin))
- else
- fibaro:call(selfId,"setProperty","ui.Label1.value", string.format("%3.1f°C(-)", tempmin))
- end
- if ftempmax > tempmax then
- fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(↑%3.1f)", tempmax, ftempmax))
- elseif ftempmax < tempmax then
- fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(↓%3.1f)", tempmax, ftempmax))
- else
- fibaro:call(selfId,"setProperty","ui.Label2.value", string.format("%3.1f°C(-)", tempmax))
- end
- if fpressure > pressure then
- fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(↑%d)", pressure, fpressure))
- elseif fpressure < pressure then
- fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(↓%d)", pressure, fpressure))
- else
- fibaro:call(selfId,"setProperty","ui.Label3.value",string.format("%dhPa(-)", pressure))
- end
- if fhumidity > humidity then
- fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(↑%d)", humidity, "%", fhumidity))
- elseif fhumidity < humidity then
- fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(↓%d)", humidity, "%", fhumidity))
- else
- fibaro:call(selfId,"setProperty","ui.Label4.value",string.format("%d%s(-)", humidity, "%"))
- end
- if fwind > wind then
- fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(↑%4.1f)", wind, fwind))
- elseif fwind < wind then
- fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(↓%4.1f)", wind, fwind))
- else
- fibaro:call(selfId,"setProperty","ui.Label5.value",string.format("%4.1fm/s(-)", wind))
- end
- fibaro:call(selfId,"setProperty","ui.Label6.value",city)
- fibaro:call(selfId,"setProperty","ui.Label91.value",weather)
- fibaro:call(selfId,"setProperty","ui.Label8.value",string.format("%3.2f°C", tempcurr))
- fibaro:setGlobal("OWM_Temp", tempcurr)
Add Comment
Please, Sign In to add comment