06.03.2022, 12:13
Sorry for the late reply.
@admin: Many thanks for your idea.
Here is my actual script which calculates the forecast for the next 24h, today and tomorrow. I hope somebody can use it to progress with it.
@admin: Many thanks for your idea.
Here is my actual script which calculates the forecast for the next 24h, today and tomorrow. I hope somebody can use it to progress with it.
Code:
require('json')
https = require 'ssl.https'
appid = 'xxx'
lat = '52.436225'
lon ='10.42526'
azi = '170'
hours = '48'
format = 'json'
tilt = '33'
capa = '8'
url = 'https://api.solcast.com.au/world_pv_power/forecasts?latitude=%s&longitude=%s&hours=%s&format=%s&tilt=%s&capacity=%s&azimuth=%s&api_key=%s'
url = string.format(url, lat, lon, hours, format, tilt, capa, azi, appid)
res, code, headers, status = ssl.https.request(url)
log (code, status, headers)
data = json.pdecode(res)
--Fault messages:
if not data then
alert('Error converting data')
return
end
if not res then
alert('Error collecting data')
return
end
data = data.forecasts
-- PV Forecast Calculation***************************************************************************
now = os.date('*t')
hour = now.hour
i=1
j=2
k=1
forecastsum=0
rest_hour = 24 - hour
repeat
forecast = data[i].pv_estimate + data[j].pv_estimate
forecastsum = forecastsum + forecast
-- next 24h
if k == 24 then
forecast_24h = forecastsum
grp.write('43/4/25', forecast_24h)
end
-- today
if rest_hour == k then
forecast_today = forecastsum
grp.write('43/4/26', forecast_today)
end
-- tomorrow
if (rest_hour + 24) == k then
forecast_tomorrow = forecastsum - forecast_today
grp.write('43/4/27', forecast_tomorrow)
end
-- hourly forecasts next 24h
if k < 25 then
grp.write('43/4/'..k, forecast)
end
i = i + 2
j = j + 2
k = k + 1
until k > (rest_hour + 24)
-- *************************************************************************************************