One way is to know when the sun shines and how much the global radiation intensity is in Watt per m2
At Meteoserver the data can be obtained like
Code: Select all
https://data.meteoserver.nl/api/solar.php?locatie=Utrecht&key=abcd1234
The API allows 500 free calls per month, like one call per 2 hours.
My suggestion
Can you build a Meteoserver sun radiation hardware addon like the Enever addon
PS
I can build something python or something dzVents but I don't know how and cannot find how I can create a sensor like the Enever one with bar charts. PPS
Here is a dzVents script that fills a text Sensor
You can edit the name of the textSensor, the API key and the local threshold = 400 -- Minimal 400 W/m² to be "Sunny" gelden
Code: Select all
return {
on = {
timer = {'every 2 hours'},
httpResponses = {'meteoserver_api_call'}
},
data = {
lastUpdate = { initial = '' }
},
execute = function(domoticz, item)
local api_url = "https://data.meteoserver.nl/api/solar.php?locatie=Utrecht&key=abcd1234"
-- Functie om tijdvakken met hoge straling te vinden
local function findSunnyPeriods(forecastData)
local threshold = 400 -- Minimaal 400 W/m² om als "zonnig" te gelden
local sunnyHours = {}
-- Identificeer alle uren boven de drempelwaarde
for _, hour in ipairs(forecastData) do
if tonumber(hour.gr_w) >= threshold then
table.insert(sunnyHours, {
time = hour.time,
cet = hour.cet,
gr_w = hour.gr_w
})
end
end
-- Groepeer aaneengesloten uren
local periods = {}
if #sunnyHours > 0 then
local startTime = sunnyHours[1].time
local endTime = startTime
local currentGr = sunnyHours[1].gr_w
for i = 2, #sunnyHours do
if sunnyHours[i].time - sunnyHours[i-1].time <= 3600 then -- Max 1 uur verschil
endTime = sunnyHours[i].time
currentGr = currentGr + sunnyHours[i].gr_w
else
table.insert(periods, {
start = os.date("%H:%M", startTime),
eind = os.date("%H:%M", endTime),
straling = math.floor(currentGr / ((endTime - startTime)/3600 + 1)) -- Gemiddelde W/m²
})
startTime = sunnyHours[i].time
endTime = startTime
currentGr = sunnyHours[i].gr_w
end
end
-- Voeg laatste periode toe
table.insert(periods, {
start = os.date("%H:%M", startTime),
eind = os.date("%H:%M", endTime),
straling = math.floor(currentGr / ((endTime - startTime)/3600 + 1))
})
end
-- Sorteer periodes op stralingsintensiteit (hoog naar laag)
table.sort(periods, function(a, b) return a.straling > b.straling end)
return periods
end
-- API-aanvraag bij timer-event
if (item.isTimer) then
domoticz.openURL({
url = api_url,
method = 'GET',
callback = 'meteoserver_api_call'
})
-- Verwerk API-respons
elseif (item.isHTTPResponse and item.ok) then
local json = item.json
if (json and json.current and json.current[1]) then
local current = json.current[1]
local now = os.date("%H:%M")
-- Bouw basisbericht
local sensor_text = "🌡️ Nu: " .. current.temp .. "°C | "
sensor_text = sensor_text .. "☁️ " .. current.tc .. "% | "
sensor_text = sensor_text .. "☀️ " .. current.gr_w .. " W/m²\n\n"
-- Voeg komende 3 uur toe (vandaag)
sensor_text = sensor_text .. "⏳ Komende uren:\n"
local hours_added = 0
for _, hour in ipairs(json.forecast) do
if os.date("%Y-%m-%d", hour.time) == os.date("%Y-%m-%d") then
sensor_text = sensor_text .. os.date("%H:%M", hour.time) .. ": " .. hour.gr_w .. " W/m²\n"
hours_added = hours_added + 1
if hours_added >= 3 then break end
end
end
-- Analyseer morgen
local tomorrow_forecast = {}
for _, hour in ipairs(json.forecast) do
if os.date("%Y-%m-%d", hour.time) == os.date("%Y-%m-%d", os.time() + 86400) then
table.insert(tomorrow_forecast, hour)
end
end
local sunny_periods = findSunnyPeriods(tomorrow_forecast)
-- Voeg beste zonperiodes toe
sensor_text = sensor_text .. "\n🔆 Morgen optimaal:\n"
if #sunny_periods > 0 then
for i, period in ipairs(sunny_periods) do
if i <= 3 then -- Toon max 3 beste periodes
sensor_text = sensor_text .. period.start .. "-" .. period.eind .. ": " .. period.straling .. " W/m² gem.\n"
end
end
else
sensor_text = sensor_text .. "Geen sterke zonneschijn verwacht\n"
end
-- Update sensor
domoticz.devices("Zonnestraling").updateText(sensor_text)
domoticz.log("Zonnestraling bijgewerkt om " .. now, domoticz.LOG_INFO)
end
end
end
}