Forum użytkowników automatyki budynkowej
Z-wave => Fibaro - urządzenia wirtualne, pluginy => Wątek zaczęty przez: gomark w Styczeń 17, 2018, 08:54:08 pm
-
Prośba o pomoc.
Jakich zmian dokonać, żeby odświeżało pobieranie danych.
W ty stanie tylko ręcznie pobiera dane.
local delay_second = 10;
selfId = fibaro:getSelfId();
HC2 = Net.FHttp("monitor.pogodynka.pl")
dane, status = HC2:GET("/api/station/hydro/?id=152200130")
ajson=json.decode(dane)
fibaro:debug("dane:"..dane);
stan=ajson.status.currentValue
fibaro:debug("stan:"..stan);
waring=ajson.status.warningValue
alert=ajson.status.alarmValue
fibaro:debug("alert:"..alert);
trend=ajson.status.trend
fibaro:debug("trend:"..trend);
fibaro:call(selfId,"setProperty","ui.Label1.value",stan)
if (tonumber(stan)<tonumber(alert))
then
if (tonumber(stan)<tonumber(waring))
then
fibaro:call(selfId,"setProperty","ui.Label2.value","stan optymalny")
fibaro:log("stan optymalny "..stan)
else
fibaro:call(selfId,"setProperty","ui.Label2.value","stan ostrzegawczy przekroczony")
fibaro:log("stan ostrzegawczy przekroczony")
end
else
fibaro:call(selfId,"setProperty","ui.Label2.value","stan alarmowy przekroczony")
fibaro:log("stan alarmowy przekroczony")
end
if ( tonumber(trend) == 0) then
fibaro:call(selfId,"setProperty","ui.Label3.value","bez zmian")
elseif ( tonumber(trend) > 0) then
fibaro:call(selfId,"setProperty","ui.Label3.value","rosnący")
elseif ( tonumber(trend) < 0) then
fibaro:call(selfId,"setProperty","ui.Label3.value","malejący")
end
fibaro:sleep( delay_second * 1000 )
HC3 = Net.FHttp("monitor.pogodynka.pl")
danem, statusm = HC3:GET("/api/station/meteo/?id=252200120")
ajsonm=json.decode(danem)
opadg=ajsonm.status.precip.value
opadd=ajsonm.status.precipDaily.value
opad6=ajsonm.status.precip6HoursSum
fibaro:call(selfId,"setProperty","ui.Label4.value",string.format(" %g ", opadg))
fibaro:call(selfId,"setProperty","ui.Label5.value",string.format(" %g ", opad6))
fibaro:call(selfId,"setProperty","ui.Label6.value",string.format(" %g ", opadd))
fibaro:setGlobal('rzekaNarew', stan)
-
masz trzy opcje:
1) piszesz kod w urzadzeniu wirtualnym w petli glownej,
2) robisz guzik aktualizuj, ktory wykouje calosc kodu i piszesz scene ktora co zadany okres czasu "naciska" guzik
3) przepisujesz urzadzenie wirtualne na scene korzystajac z
self.http:request(controlUrl, {
options={
headers = self.controlHeaders,
data = requestBody,
method = 'POST',
timeout = 5000
},
success = function(status)
local result = json.decode(status.data)
if result[1] then
if result[1].error then
print ("ERROR")
print (" type: " .. result[1].error.type)
print (" address: " .. result[1].error.address)
print (" description: " .. result[1].error.description)
elseif result[1].success then
self:updateProperty("userName", result[1].success.username)
else
print ("unknown response structure: ")
print(status)
end
else
print ("unknown response structure: ")
print(status)
end
end,
error = function(error)
print "ERROR"
print(error)
end
})