In case you want to generate daily forecasts with the data provided by a free OpenWeatherMap account without relying on Jython, here’s what I did.
I create a number of proxy items that will contain the computed forecast values. These values are updated whenever a new forecast is provided by OWM or at midnight (to overcome the today → tomorrow case for forecasts).
The code below provides the following forecast data per day for up to 3 days in advance:
- Rain (total daily forecast)
- Snow (total daily forecast)
- Temperature (low / high)
- Max wind speed
- Pressure (low / high)
- Humidity (low / high)
The data are computed by assigning forecast data to the proper day. Forecast values for the current day are computed, taking into account the current measurement values.
Define the following OWM items:
DateTime Weather_OWM_Current_ObservationTime "Observation time [%1$tY-%1$tm-%1$td]"
(gWeatherCurrent) {
channel="openweathermap:weather-and-forecast:c06828c6:local:current#time-stamp"
}
// The following Items will store the computed daily forecast values
Number:Length Weather_OWM_Forecast_Rain_Day0 "Rain Total [%.1f mm]" <rain>
Number:Length Weather_OWM_Forecast_Rain_Day1 "Rain Total [%.1f mm]" <rain>
Number:Length Weather_OWM_Forecast_Rain_Day2 "Rain Total [%.1f mm]" <rain>
Number:Length Weather_OWM_Forecast_Rain_Day3 "Rain Total [%.1f mm]" <rain>
Number:Length Weather_OWM_Forecast_Snow_Day0 "Snow Total [%.1f mm]" <snow>
Number:Length Weather_OWM_Forecast_Snow_Day1 "Snow Total [%.1f mm]" <snow>
Number:Length Weather_OWM_Forecast_Snow_Day2 "Snow Total [%.1f mm]" <snow>
Number:Length Weather_OWM_Forecast_Snow_Day3 "Snow Total [%.1f mm]" <snow>
Number:Temperature Weather_OWM_Forecast_Temperature_Min_Day0 "Temperature Low [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Min_Day1 "Temperature Low [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Min_Day2 "Temperature Low [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Min_Day3 "Temperature Low [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Max_Day0 "Temperature High [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Max_Day1 "Temperature High [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Max_Day2 "Temperature High [%.1f °C]" <temperature>
Number:Temperature Weather_OWM_Forecast_Temperature_Max_Day3 "Temperature High [%.1f °C]" <temperature>
Number:Speed Weather_OWM_Forecast_Wind_Speed_Max_Day0 "Max Wind Speed [%.0f km/h]" <wind>
Number:Speed Weather_OWM_Forecast_Wind_Speed_Max_Day1 "Max Wind Speed [%.0f km/h]" <wind>
Number:Speed Weather_OWM_Forecast_Wind_Speed_Max_Day2 "Max Wind Speed [%.0f km/h]" <wind>
Number:Speed Weather_OWM_Forecast_Wind_Speed_Max_Day3 "Max Wind Speed [%.0f km/h]" <wind>
Number:Pressure Weather_OWM_Forecast_Pressure_Min_Day0 "Pressure Low [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Min_Day1 "Pressure Low [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Min_Day2 "Pressure Low [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Min_Day3 "Pressure Low [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Max_Day0 "Pressure High [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Max_Day1 "Pressure High [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Max_Day2 "Pressure High [%.1f hPa]" <pressure>
Number:Pressure Weather_OWM_Forecast_Pressure_Max_Day3 "Pressure High [%.1f hPa]" <pressure>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Min_Day0 "Humidity Low [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Min_Day1 "Humidity Low [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Min_Day2 "Humidity Low [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Min_Day3 "Humidity Low [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Max_Day0 "Humidity High [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Max_Day1 "Humidity High [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Max_Day2 "Humidity High [%d %unit%]" <humidity>
Number:Dimensionless Weather_OWM_Forecast_Humidity_Max_Day3 "Humidity High [%d %unit%]" <humidity>
In your sitemap:
Text item=Weather_OWM_Forecast_Time_72h label="Forecast (3 days) [until %1$tA]" icon="sun_clouds" {
Frame item=Weather_OWM_Current_ObservationTime label="Today [%1$tA, %1$tb %1$td]" icon="calendar" {
Default item=Weather_OWM_Forecast_Temperature_Min_Day0 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Temperature_Max_Day0 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Rain_Day0
Default item=Weather_OWM_Forecast_Snow_Day0
Default item=Weather_OWM_Forecast_Wind_Speed_Max_Day0
Default item=Weather_OWM_Forecast_Humidity_Min_Day0
Default item=Weather_OWM_Forecast_Humidity_Max_Day0
Default item=Weather_OWM_Forecast_Pressure_Min_Day0
Default item=Weather_OWM_Forecast_Pressure_Max_Day0
}
Frame item=Weather_OWM_Forecast_Time_24h label="Tomorrow [%1$tA, %1$tb %1$td]" icon="calendar" {
Default item=Weather_OWM_Forecast_Temperature_Min_Day1 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Temperature_Max_Day1 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Rain_Day1
Default item=Weather_OWM_Forecast_Snow_Day1
Default item=Weather_OWM_Forecast_Wind_Speed_Max_Day1
Default item=Weather_OWM_Forecast_Humidity_Min_Day1
Default item=Weather_OWM_Forecast_Humidity_Max_Day1
Default item=Weather_OWM_Forecast_Pressure_Min_Day1
Default item=Weather_OWM_Forecast_Pressure_Max_Day1
}
Frame item=Weather_OWM_Forecast_Time_48h label="In 2 days [%1$tA, %1$tb %1$td]" icon="calendar" {
Default item=Weather_OWM_Forecast_Temperature_Min_Day2 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Temperature_Max_Day2 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Rain_Day2
Default item=Weather_OWM_Forecast_Snow_Day2
Default item=Weather_OWM_Forecast_Wind_Speed_Max_Day2
Default item=Weather_OWM_Forecast_Humidity_Min_Day2
Default item=Weather_OWM_Forecast_Humidity_Max_Day2
Default item=Weather_OWM_Forecast_Pressure_Min_Day2
Default item=Weather_OWM_Forecast_Pressure_Max_Day2
}
Frame item=Weather_OWM_Forecast_Time_72h label="In 3 days [%1$tA, %1$tb %1$td]" icon="calendar" {
Default item=Weather_OWM_Forecast_Temperature_Min_Day3 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Temperature_Max_Day3 valuecolor=[
>=30="red", >=25="orange", >=15="green", 0="silver", <0="purple", <15="blue"
]
Default item=Weather_OWM_Forecast_Rain_Day3
Default item=Weather_OWM_Forecast_Snow_Day3
Default item=Weather_OWM_Forecast_Wind_Speed_Max_Day3
Default item=Weather_OWM_Forecast_Humidity_Min_Day3
Default item=Weather_OWM_Forecast_Humidity_Max_Day3
Default item=Weather_OWM_Forecast_Pressure_Min_Day3
Default item=Weather_OWM_Forecast_Pressure_Max_Day3
}
}
Now comes the (rather verbose) rule that takes care of computing the forecasts for daily rain and snow, and daily low and high temperatures:
rule "Update forecast data"
when
// Time cron "0/15 * * * * ?" or // Only for debug purposes: display results every 15 seconds
Time cron "0 0 0 * * ?" or
Item Weather_OWM_Forecast_Time_03h changed
then
val String ruleTitle = "UpdateOWMForecastInfo"
val DateTime dtNow = now
val Number now_d = dtNow.getDayOfMonth
val Number now_m = dtNow.getMonthOfYear
val Number now_h = dtNow.getHourOfDay
val DateTime dtForecast_03h = (new DateTime(Weather_OWM_Forecast_Time_03h.state.toString)).toDateTime
val Number forecast_03h_d = dtForecast_03h.getDayOfMonth
val Number forecast_03h_m = dtForecast_03h.getMonthOfYear
val Number forecast_03h_h = dtForecast_03h.getHourOfDay
logInfo(ruleTitle, "Update forecast info - today is {}/{} - 03h forecast is for {}/{} at {}h", now_d, now_m, forecast_03h_d, forecast_03h_m, forecast_03h_h)
var Number forecastDayOffset = 0
if (forecast_03h_d > now_d) { // No forecast for today
logInfo(ruleTitle, "No forecast for today ({}/{} - at or after {}h", now_d, now_m, now_h)
forecastDayOffset = 1
}
var Number i = 3
var Number rain_day_0 = 0|mm
var Number snow_day_0 = 0|mm
var Number wind_speed_max_day_0 = 0|"km/h"
var Number temp_min_day_0 = 100|°C // Make it a very high (!) temperature so it gets updated instantly
var Number temp_max_day_0 = -100|°C // Make it a very low (!) temperature so it gets updated instantly
var Number humidity_min_day_0 = 100 // Make it a 100% so it gets updated instantly
var Number humidity_max_day_0 = 0 // Make it 0% so it gets updated instantly
var Number pressure_min_day_0 = 2000|"hPa" // Make it very high (!) so it gets updated instantly
var Number pressure_max_day_0 = 0|"hPa" // Make it 0 so it gets updated instantly
if (forecastDayOffset == 0) { // Forecast data still today: set min and max to current values as a starting point
temp_min_day_0 = Weather_OWM_Current_Temperature.state as Number
temp_max_day_0 = temp_min_day_0
humidity_min_day_0 = Weather_OWM_Current_Humidity.state as Number
humidity_max_day_0 = humidity_min_day_0
pressure_min_day_0 = Weather_OWM_Current_Pressure.state as Number
pressure_max_day_0 = pressure_min_day_0
}
while ( forecast_03h_h + i - 3 <= 24 ) {
// Rain: total
val String rainItemName = "Weather_OWM_Forecast_Rain_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number rain = ScriptServiceUtil.getItemRegistry.getItem(rainItemName).state as Number
rain_day_0 = rain_day_0 + rain
// Snow: total
val String snowItemName = "Weather_OWM_Forecast_Snow_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number snow = ScriptServiceUtil.getItemRegistry.getItem(snowItemName).state as Number
snow_day_0 = snow_day_0 + snow
// Wind speed: max
val String windSpeedItemName = "Weather_OWM_Forecast_Wind_Speed_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number wind_speed = ScriptServiceUtil.getItemRegistry.getItem(windSpeedItemName).state as Number
if (wind_speed_max_day_0 < wind_speed) wind_speed_max_day_0 = wind_speed
// Temperature: min, max
val String tempItemName = "Weather_OWM_Forecast_Temperature_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number temp = ScriptServiceUtil.getItemRegistry.getItem(tempItemName).state as Number
if (temp_max_day_0 < temp) temp_max_day_0 = temp
if (temp_min_day_0 > temp) temp_min_day_0 = temp
// Humidity: min, max
val String humidityItemName = "Weather_OWM_Forecast_Humidity_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number humidity = ScriptServiceUtil.getItemRegistry.getItem(humidityItemName).state as Number
if (humidity_max_day_0 < humidity) humidity_max_day_0 = humidity
if (humidity_min_day_0 > humidity) humidity_min_day_0 = humidity
// Pressure: min, max
val String pressureItemName = "Weather_OWM_Forecast_Pressure_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number pressure = ScriptServiceUtil.getItemRegistry.getItem(pressureItemName).state as Number
if (pressure_max_day_0 < pressure) pressure_max_day_0 = pressure
if (pressure_min_day_0 > pressure) pressure_min_day_0 = pressure
logDebug(ruleTitle,
"Weather forecast for 'today + {} day(s)' at {}h ({}h + {}h) -- {} = {}, rain: {}, snow: {}, wind speed: {}, pressure: {}, humidity: {}",
forecastDayOffset, forecast_03h_h + i - 3, forecast_03h_h, i - 3,
tempItemName, temp, rain, snow, wind_speed, pressure, humidity)
i = i + 3
}
logInfo(ruleTitle,
"Forecast in {} days: temperature: {} - {}, rain: {}, snow: {}, wind speed: {}, pressure: {} - {}, humidity: {} - {}",
0 + forecastDayOffset,
temp_min_day_0, temp_max_day_0, rain_day_0, snow_day_0, wind_speed_max_day_0,
pressure_min_day_0, pressure_max_day_0, humidity_min_day_0, humidity_max_day_0)
var Number rain_day_1 = 0|mm
var Number snow_day_1 = 0|mm
var Number wind_speed_max_day_1 = 0|"km/h"
var Number temp_min_day_1 = 100|°C // Make it a very high (!) temperature so it gets updated instantly
var Number temp_max_day_1 = -100|°C // Make it a very low (!) temperature so it gets updated instantly
var Number humidity_min_day_1 = 100 // Make it a 100% so it gets updated instantly
var Number humidity_max_day_1 = 0 // Make it 0% so it gets updated instantly
var Number pressure_min_day_1 = 2000|"hPa" // Make it a 100% so it gets updated instantly
var Number pressure_max_day_1 = 0|"hPa" // Make it 0% so it gets updated instantly
while ( forecast_03h_h + i - 3 <= 48 ) {
// Rain: total
val String rainItemName = "Weather_OWM_Forecast_Rain_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number rain = ScriptServiceUtil.getItemRegistry.getItem(rainItemName).state as Number
rain_day_1 = rain_day_1 + rain
// Snow: total
val String snowItemName = "Weather_OWM_Forecast_Snow_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number snow = ScriptServiceUtil.getItemRegistry.getItem(snowItemName).state as Number
snow_day_1 = snow_day_1 + snow
// Wind speed: max
val String windSpeedItemName = "Weather_OWM_Forecast_Wind_Speed_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number wind_speed = ScriptServiceUtil.getItemRegistry.getItem(windSpeedItemName).state as Number
if (wind_speed_max_day_1 < wind_speed) wind_speed_max_day_1 = wind_speed
// Temperature: min, max
val String tempItemName = "Weather_OWM_Forecast_Temperature_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number temp = ScriptServiceUtil.getItemRegistry.getItem(tempItemName).state as Number
if (temp_max_day_1 < temp) temp_max_day_1 = temp
if (temp_min_day_1 > temp) temp_min_day_1 = temp
// Humidity: min, max
val String humidityItemName = "Weather_OWM_Forecast_Humidity_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number humidity = ScriptServiceUtil.getItemRegistry.getItem(humidityItemName).state as Number
if (humidity_max_day_1 < humidity) humidity_max_day_1 = humidity
if (humidity_min_day_1 > humidity) humidity_min_day_1 = humidity
// Pressure: min, max
val String pressureItemName = "Weather_OWM_Forecast_Pressure_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number pressure = ScriptServiceUtil.getItemRegistry.getItem(pressureItemName).state as Number
if (pressure_max_day_1 < pressure) pressure_max_day_1 = pressure
if (pressure_min_day_1 > pressure) pressure_min_day_1 = pressure
logDebug(ruleTitle,
"Weather forecast for 'today + {} day(s)' at {}h ({}h + {}h) -- {} = {}, rain: {}, snow: {}, wind speed: {}, pressure: {}, humidity: {}",
1 + forecastDayOffset, forecast_03h_h + i - 3 - 24, forecast_03h_h, i - 3 - 24,
tempItemName, temp, rain, snow, wind_speed, pressure, humidity)
i = i + 3
}
logInfo(ruleTitle,
"Forecast in {} days: temperature: {} - {}, rain: {}, snow: {}, wind speed: {}, pressure: {} - {}, humidity: {} - {}",
1 + forecastDayOffset,
temp_min_day_1, temp_max_day_1, rain_day_1, snow_day_1, wind_speed_max_day_1,
pressure_min_day_1, pressure_max_day_1, humidity_min_day_1, humidity_max_day_1)
var Number rain_day_2 = 0|mm
var Number snow_day_2 = 0|mm
var Number wind_speed_max_day_2 = 0|"km/h"
var Number temp_min_day_2 = 100|°C // Make it a very high (!) temperature so it gets updated instantly
var Number temp_max_day_2 = -100|°C // Make it a very low (!) temperature so it gets updated instantly
var Number humidity_min_day_2 = 100 // Make it a 100% so it gets updated instantly
var Number humidity_max_day_2 = 0 // Make it 0% so it gets updated instantly
var Number pressure_min_day_2 = 2000|"hPa" // Make it a 100% so it gets updated instantly
var Number pressure_max_day_2 = 0|"hPa" // Make it 0% so it gets updated instantly
while ( forecast_03h_h + i - 3 <= 72 ) {
// Rain: total
val String rainItemName = "Weather_OWM_Forecast_Rain_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number rain = ScriptServiceUtil.getItemRegistry.getItem(rainItemName).state as Number
rain_day_2 = rain_day_2 + rain
// Snow: total
val String snowItemName = "Weather_OWM_Forecast_Snow_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number snow = ScriptServiceUtil.getItemRegistry.getItem(snowItemName).state as Number
snow_day_2 = snow_day_2 + snow
// Wind speed: max
val String windSpeedItemName = "Weather_OWM_Forecast_Wind_Speed_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number wind_speed = ScriptServiceUtil.getItemRegistry.getItem(windSpeedItemName).state as Number
if (wind_speed_max_day_2 < wind_speed) wind_speed_max_day_2 = wind_speed
// Temperature: min, max
val String tempItemName = "Weather_OWM_Forecast_Temperature_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number temp = ScriptServiceUtil.getItemRegistry.getItem(tempItemName).state as Number
if (temp_max_day_2 < temp) temp_max_day_2 = temp
if (temp_min_day_2 > temp) temp_min_day_2 = temp
// Humidity: min, max
val String humidityItemName = "Weather_OWM_Forecast_Humidity_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number humidity = ScriptServiceUtil.getItemRegistry.getItem(humidityItemName).state as Number
if (humidity_max_day_2 < humidity) humidity_max_day_2 = humidity
if (humidity_min_day_2 > humidity) humidity_min_day_2 = humidity
// Pressure: min, max
val String pressureItemName = "Weather_OWM_Forecast_Pressure_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number pressure = ScriptServiceUtil.getItemRegistry.getItem(pressureItemName).state as Number
if (pressure_max_day_2 < pressure) pressure_max_day_2 = pressure
if (pressure_min_day_2 > pressure) pressure_min_day_2 = pressure
logDebug(ruleTitle,
"Weather forecast for 'today + {} day(s)' at {}h ({}h + {}h) -- {} = {}, rain: {}, snow: {}, wind speed: {}, pressure: {}, humidity: {}",
2 + forecastDayOffset, forecast_03h_h + i - 3 - 48, forecast_03h_h, i - 3 - 48,
tempItemName, temp, rain, snow, wind_speed, pressure, humidity)
i = i + 3
}
logInfo(ruleTitle,
"Forecast in {} days: temperature: {} - {}, rain: {}, snow: {}, wind speed: {}, pressure: {} - {}, humidity: {} - {}",
2 + forecastDayOffset,
temp_min_day_2, temp_max_day_2, rain_day_2, snow_day_2, wind_speed_max_day_2,
pressure_min_day_2, pressure_max_day_2, humidity_min_day_2, humidity_max_day_2)
var Number rain_day_3 = 0|mm
var Number snow_day_3 = 0|mm
var Number wind_speed_max_day_3 = 0|"km/h"
var Number temp_min_day_3 = 100|°C // Make it a very high (!) temperature so it gets updated instantly
var Number temp_max_day_3 = -100|°C // Make it a very low (!) temperature so it gets updated instantly
var Number humidity_min_day_3 = 100 // Make it a 100% so it gets updated instantly
var Number humidity_max_day_3 = 0 // Make it 0% so it gets updated instantly
var Number pressure_min_day_3 = 2000|"hPa" // Make it a 100% so it gets updated instantly
var Number pressure_max_day_3 = 0|"hPa" // Make it 0% so it gets updated instantly
while ( forecast_03h_h + i - 3 <= 96 ) {
// Rain: total
val String rainItemName = "Weather_OWM_Forecast_Rain_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number rain = ScriptServiceUtil.getItemRegistry.getItem(rainItemName).state as Number
rain_day_3 = rain_day_3 + rain
// Snow: total
val String snowItemName = "Weather_OWM_Forecast_Snow_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number snow = ScriptServiceUtil.getItemRegistry.getItem(snowItemName).state as Number
snow_day_3 = snow_day_3 + snow
// Wind speed: max
val String windSpeedItemName = "Weather_OWM_Forecast_Wind_Speed_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number wind_speed = ScriptServiceUtil.getItemRegistry.getItem(windSpeedItemName).state as Number
if (wind_speed_max_day_3 < wind_speed) wind_speed_max_day_3 = wind_speed
// Temperature: min, max
val String tempItemName = "Weather_OWM_Forecast_Temperature_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number temp = ScriptServiceUtil.getItemRegistry.getItem(tempItemName).state as Number
if (temp_max_day_3 < temp) temp_max_day_3 = temp
if (temp_min_day_3 > temp) temp_min_day_3 = temp
// Humidity: min, max
val String humidityItemName = "Weather_OWM_Forecast_Humidity_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number humidity = ScriptServiceUtil.getItemRegistry.getItem(humidityItemName).state as Number
if (humidity_max_day_3 < humidity) humidity_max_day_3 = humidity
if (humidity_min_day_3 > humidity) humidity_min_day_3 = humidity
// Pressure: min, max
val String pressureItemName = "Weather_OWM_Forecast_Pressure_" + (if(i<10) {"0" + i.toString } else { i.toString }) + "h"
val Number pressure = ScriptServiceUtil.getItemRegistry.getItem(pressureItemName).state as Number
if (pressure_max_day_3 < pressure) pressure_max_day_3 = pressure
if (pressure_min_day_3 > pressure) pressure_min_day_3 = pressure
logDebug(ruleTitle,
"Weather forecast for 'today + {} day(s)' at {}h ({}h + {}h) -- {} = {}, rain: {}, snow: {}, wind speed: {}, pressure: {}, humidity: {}",
3 + forecastDayOffset, forecast_03h_h + i - 3 - 72, forecast_03h_h, i - 3 - 72,
tempItemName, temp, rain, snow, wind_speed, pressure, humidity)
i = i + 3
}
logInfo(ruleTitle,
"Forecast in {} days: temperature: {} - {}, rain: {}, snow: {}, wind speed: {}, pressure: {} - {}, humidity: {} - {}",
3 + forecastDayOffset,
temp_min_day_3, temp_max_day_3, rain_day_3, snow_day_3, wind_speed_max_day_3,
pressure_min_day_3, pressure_max_day_3, humidity_min_day_3, humidity_max_day_3)
if (forecastDayOffset == 0) {
Weather_OWM_Forecast_Rain_Day0.postUpdate(rain_day_0)
Weather_OWM_Forecast_Rain_Day1.postUpdate(rain_day_1)
Weather_OWM_Forecast_Rain_Day2.postUpdate(rain_day_2)
Weather_OWM_Forecast_Rain_Day3.postUpdate(rain_day_3)
Weather_OWM_Forecast_Snow_Day0.postUpdate(snow_day_0)
Weather_OWM_Forecast_Snow_Day1.postUpdate(snow_day_1)
Weather_OWM_Forecast_Snow_Day2.postUpdate(snow_day_2)
Weather_OWM_Forecast_Snow_Day3.postUpdate(snow_day_3)
Weather_OWM_Forecast_Wind_Speed_Max_Day0.postUpdate(wind_speed_max_day_0)
Weather_OWM_Forecast_Wind_Speed_Max_Day1.postUpdate(wind_speed_max_day_1)
Weather_OWM_Forecast_Wind_Speed_Max_Day2.postUpdate(wind_speed_max_day_2)
Weather_OWM_Forecast_Wind_Speed_Max_Day3.postUpdate(wind_speed_max_day_3)
Weather_OWM_Forecast_Temperature_Min_Day0.postUpdate(temp_min_day_0)
Weather_OWM_Forecast_Temperature_Min_Day1.postUpdate(temp_min_day_1)
Weather_OWM_Forecast_Temperature_Min_Day2.postUpdate(temp_min_day_2)
Weather_OWM_Forecast_Temperature_Min_Day3.postUpdate(temp_min_day_3)
Weather_OWM_Forecast_Temperature_Max_Day0.postUpdate(temp_max_day_0)
Weather_OWM_Forecast_Temperature_Max_Day1.postUpdate(temp_max_day_1)
Weather_OWM_Forecast_Temperature_Max_Day2.postUpdate(temp_max_day_2)
Weather_OWM_Forecast_Temperature_Max_Day3.postUpdate(temp_max_day_3)
Weather_OWM_Forecast_Pressure_Min_Day0.postUpdate(pressure_min_day_0)
Weather_OWM_Forecast_Pressure_Min_Day1.postUpdate(pressure_min_day_1)
Weather_OWM_Forecast_Pressure_Min_Day2.postUpdate(pressure_min_day_2)
Weather_OWM_Forecast_Pressure_Min_Day3.postUpdate(pressure_min_day_3)
Weather_OWM_Forecast_Pressure_Max_Day0.postUpdate(pressure_max_day_0)
Weather_OWM_Forecast_Pressure_Max_Day1.postUpdate(pressure_max_day_1)
Weather_OWM_Forecast_Pressure_Max_Day2.postUpdate(pressure_max_day_2)
Weather_OWM_Forecast_Pressure_Max_Day3.postUpdate(pressure_max_day_3)
Weather_OWM_Forecast_Humidity_Min_Day0.postUpdate(humidity_min_day_0)
Weather_OWM_Forecast_Humidity_Min_Day1.postUpdate(humidity_min_day_1)
Weather_OWM_Forecast_Humidity_Min_Day2.postUpdate(humidity_min_day_2)
Weather_OWM_Forecast_Humidity_Min_Day3.postUpdate(humidity_min_day_3)
Weather_OWM_Forecast_Humidity_Max_Day0.postUpdate(humidity_max_day_0)
Weather_OWM_Forecast_Humidity_Max_Day1.postUpdate(humidity_max_day_1)
Weather_OWM_Forecast_Humidity_Max_Day2.postUpdate(humidity_max_day_2)
Weather_OWM_Forecast_Humidity_Max_Day3.postUpdate(humidity_max_day_3)
} else {
Weather_OWM_Forecast_Rain_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Rain_Day1.postUpdate(rain_day_0)
Weather_OWM_Forecast_Rain_Day2.postUpdate(rain_day_1)
Weather_OWM_Forecast_Rain_Day3.postUpdate(rain_day_2)
Weather_OWM_Forecast_Snow_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Snow_Day1.postUpdate(snow_day_0)
Weather_OWM_Forecast_Snow_Day2.postUpdate(snow_day_1)
Weather_OWM_Forecast_Snow_Day3.postUpdate(snow_day_2)
Weather_OWM_Forecast_Wind_Speed_Max_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Wind_Speed_Max_Day1.postUpdate(wind_speed_max_day_0)
Weather_OWM_Forecast_Wind_Speed_Max_Day2.postUpdate(wind_speed_max_day_1)
Weather_OWM_Forecast_Wind_Speed_Max_Day3.postUpdate(wind_speed_max_day_2)
Weather_OWM_Forecast_Temperature_Min_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Temperature_Min_Day1.postUpdate(temp_min_day_0)
Weather_OWM_Forecast_Temperature_Min_Day2.postUpdate(temp_min_day_1)
Weather_OWM_Forecast_Temperature_Min_Day3.postUpdate(temp_min_day_2)
Weather_OWM_Forecast_Temperature_Max_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Temperature_Max_Day1.postUpdate(temp_max_day_0)
Weather_OWM_Forecast_Temperature_Max_Day2.postUpdate(temp_max_day_1)
Weather_OWM_Forecast_Temperature_Max_Day3.postUpdate(temp_max_day_2)
Weather_OWM_Forecast_Pressure_Min_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Pressure_Min_Day1.postUpdate(pressure_min_day_0)
Weather_OWM_Forecast_Pressure_Min_Day2.postUpdate(pressure_min_day_1)
Weather_OWM_Forecast_Pressure_Min_Day3.postUpdate(pressure_min_day_2)
Weather_OWM_Forecast_Pressure_Max_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Pressure_Max_Day1.postUpdate(pressure_max_day_0)
Weather_OWM_Forecast_Pressure_Max_Day2.postUpdate(pressure_max_day_1)
Weather_OWM_Forecast_Pressure_Max_Day3.postUpdate(pressure_max_day_2)
Weather_OWM_Forecast_Humidity_Min_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Humidity_Min_Day1.postUpdate(humidity_min_day_0)
Weather_OWM_Forecast_Humidity_Min_Day2.postUpdate(humidity_min_day_1)
Weather_OWM_Forecast_Humidity_Min_Day3.postUpdate(humidity_min_day_2)
Weather_OWM_Forecast_Humidity_Max_Day0.postUpdate(UNDEF)
Weather_OWM_Forecast_Humidity_Max_Day1.postUpdate(humidity_max_day_0)
Weather_OWM_Forecast_Humidity_Max_Day2.postUpdate(humidity_max_day_1)
Weather_OWM_Forecast_Humidity_Max_Day3.postUpdate(humidity_max_day_2)
}
end
My rule separately computes the values for a day at a time (hence the “_0
”, “_1
” etc. variable numbering in 4 quasi-similar code blocks). It takes care of the edge case where the first forecast value is no longer for today (then forecastDayOffset
is set to 1
). For this reason I can only compute the forecast values for up to 3 days in advance. The 4th day is not processed as it can only use a full forecast data set when the forecast starts at the 1st possible time slot of a day (so the 4th day uses the OWM forecast data from _75h
to _96h
).
Have fun!