[SOLVED] DateTime Items compare against fixed DateTimes

  • Platform information:
    • Hardware: _ Raspberry Pi 3 Model B Rev 1.2_
  • OS: Raspbian GNU/Linux 8 (jessie)
    • Java Runtime Environment: (Zulu Embedded 8.25.0.76-linux-aarch32hf) (build 1.8.0_152-b76)
    • openHAB version: OH 2.4.0.M6
      EDIT: * openHAB version: OH 2.4.0.M7
    • Bindings:Astro, AVM, EXEC, MQTT, Network, NTP, Samsung, Sonos, Weather (binding-weather1), OpenWeatherMap, MapDB-Persitence, http
    • Transformations: exec, Javascript, JSONPATH, Map, RegEx, Scale

Hi,
i have a little problem to compare several DateTime items against fixed dates in a rule.

items:

DateTime  localLastMeasurement             "Timestamp of last measurement [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"  <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#time-stamp" }
DateTime  localHourlyForecast3Timestamp    "Timestamp in 03 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#time-stamp" }
DateTime  localHourlyForecast6Timestamp    "Timestamp in 06 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#time-stamp" }
DateTime  localHourlyForecast9Timestamp    "Timestamp in 09 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#time-stamp" }
DateTime  localHourlyForecast12Timestamp   "Timestamp in 12 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#time-stamp" }
DateTime  localHourlyForecast15Timestamp   "Timestamp in 15 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#time-stamp" }
DateTime  localHourlyForecast18Timestamp   "Timestamp in 18 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours18#time-stamp" }
DateTime  localHourlyForecast21Timestamp   "Timestamp in 21 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours21#time-stamp" }
DateTime  localHourlyForecast24Timestamp   "Timestamp in 24 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours24#time-stamp" }
DateTime  localHourlyForecast27Timestamp   "Timestamp in 27 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours27#time-stamp" }
DateTime  localHourlyForecast30Timestamp   "Timestamp in 30 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"          <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours30#time-stamp" }
	

The first item DateTime localLastMeasurement is always today. The others can be today, tomorrow, etc. (future). What i want to know is to which Day the items belong to. So i need Year, Month and Day information. I think about fixed values (today, day1, day2,…) in a rule, to summarize other items, which corresponding to that DateTime items.

The torso of the rule looks like this:

import org.eclipse.smarthome.model.script.ScriptServiceUtil
  var dayindex = 0  // day index
  var dcountindex = 0 // items a day
  var sum_temp_curr =0
  var int sum_temp_day1 =0
	var avg_temp_day1 = 0
 
rule owmSummarize_test
  when
   Item Dummy3 received command ON
  then
   var itemindex = 3 //item index
   var itemstep  = 3 //item step
   var count_day1 = 0
   var current = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
   logInfo ("owm.owmSummarize", "Current-Time-Item: " + current)
  while (itemindex >=0 && itemindex <12)
  {
   var testItemTimestamp = ScriptServiceUtil.getItemRegistry.getItem("localHourlyForecast"+itemindex+"Timestamp")
   var testItemTemperature = ScriptServiceUtil.getItemRegistry.getItem("localHourlyForecast"+itemindex+"Temperature")
   logInfo ("owm.owmSummarize", "Timestamp-Item: " + testItemTimestamp + " :Temperature-Item: " + testItemTemperature)
   itemindex = itemindex + itemstep
   count_day1 = count_day1 + 1
   //sum_temp_day1 = sum_temp_day1 + testItemTemperature.state  //doesn't work at all
   logInfo ("owm.owmSummarize", " Count:  " + count_day1 + " Summe: " + sum_temp_day1 + " itemindex: " + itemindex)

  }
    //avg_temp_day1 = sum_temp_day1 / count_day1   //doesn't work at all
   //logInfo ("owm.owmSummarize", "Ende:  " + itemindex + " :Schrittweite:  " + itemstep + " Temp-AVG:  " + avg_temp_day1)
end

And the Logger shows me, that i’m on good way :wink: even if there are some problems with summarizing too :thinking:

2018-12-03 01:52:37.299 [INFO ] [rthome.model.script.owm.owmSummarize] - Current-Time-Item: 20181203
2018-12-03 01:52:37.317 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast3Timestamp (Type=DateTimeItem, State=2018-12-03T04:00:00.000+0100, Label=Timestamp in 03 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast3Temperature (Type=NumberItem, State=10.98 °C, Label=Temperature in 03 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.329 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  1 Summe: 0 itemindex: 6
2018-12-03 01:52:37.346 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast6Timestamp (Type=DateTimeItem, State=2018-12-03T07:00:00.000+0100, Label=Timestamp in 06 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast6Temperature (Type=NumberItem, State=10.43 °C, Label=Temperature in 06 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.358 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  2 Summe: 0 itemindex: 9
2018-12-03 01:52:37.375 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast9Timestamp (Type=DateTimeItem, State=2018-12-03T10:00:00.000+0100, Label=Timestamp in 09 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast9Temperature (Type=NumberItem, State=10.65 °C, Label=Temperature in 09 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.386 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  3 Summe: 0 itemindex: 122018-12-03 01:52:37.299 [INFO ] [rthome.model.script.owm.owmSummarize] - Current-Time-Item: 20181203
2018-12-03 01:52:37.317 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast3Timestamp (Type=DateTimeItem, State=2018-12-03T04:00:00.000+0100, Label=Timestamp in 03 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast3Temperature (Type=NumberItem, State=10.98 °C, Label=Temperature in 03 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.329 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  1 Summe: 0 itemindex: 6
2018-12-03 01:52:37.346 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast6Timestamp (Type=DateTimeItem, State=2018-12-03T07:00:00.000+0100, Label=Timestamp in 06 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast6Temperature (Type=NumberItem, State=10.43 °C, Label=Temperature in 06 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.358 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  2 Summe: 0 itemindex: 9
2018-12-03 01:52:37.375 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast9Timestamp (Type=DateTimeItem, State=2018-12-03T10:00:00.000+0100, Label=Timestamp in 09 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast9Temperature (Type=NumberItem, State=10.65 °C, Label=Temperature in 09 hours, Category=temperature, Groups=[gOWM])
2018-12-03 01:52:37.386 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  3 Summe: 0 itemindex: 12

Any hints/help for me ?

Could you go step by step, (Pseudo code), through exactly what you want your algorithm to achieve, please?
What is your end goal?

Hi @vzorglub, thx for reply.
I’m using the new OpenWeatherMap-Binding, which gives me information about current temperature, pressure, etc. and forecast-info for those values in 3-hour-steps up to 5 days.
I want to achieve to adress the several forecast-values to a fixed day (current, day1, day2…day5). The problem is that forecast-period slides every 3 hours. The current time comes from the item localLastMeasurement of my owm.items-file.
Eg. at 22:20/10:20 pm the 3-hour-forecast(01:00/01:am) belongs to “day1” and of course the next 7 forcasts too. But at 00:20 all those forcasts are belonging to the “current” day and the next 8 to “day1” etc.
In detai i want to achieve:

  1. declaring the variables current, day1, day2...day5 in the rule, beginning from localLastMeasurement which should be transformed in a value like “yymmdd” or “yy-mm-dd” or “a, yy-mm-dd” (a = day-name), and of course corresponding variable for summarizing temp, hum, etc for the corresponding day (eg. day1_temp_sum)
  2. defining the loops (while, if, etc). First i’m using a While-Loop where i get the several items from the virtual item corresponding with it, beginning with the TimeStamp, then Temperature, Humidity, etc. The Solution to do so, i found here from @5iver and also post from @rlkoshak.
    Next I will compare the Timestamp item (transormed in the same way as above) with the variable “day1…5” and then adding the virtual Temp-Item to variable “day1…5_temp_sum”.
  3. At the very end i want to calculate an average for daily temp, hum, etc., or min/max. The result can look like this (from my "normal weather-binding with yahoo-provider)

After the first post i made some changes in my items.File (no more UoM) and in th Test-Rule.

owm.items without UoM for localHourlyForecast3Temperature to localHourlyForecast12Temperature:

Group                gOWM
//String               localStationId                           "Orts-Nr. [%s]"                                                                             (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:station#id" }
String               localStationName                         "Ort [%s]"                                                                            (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:station#name" }
Location             localStationLocation                     "Koordinaten [%2$s°N %3$s°E]"                                           <location>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:station#location" }
                                                              
DateTime             localLastMeasurement                     "Timestamp of last measurement [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"   <time>       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#time-stamp" }

Image                localCurrentConditionIcon                "Icon"                                                                                (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#icon" }
Number:Temperature   localCurrentTemperature                  "Current temperature [%.1f %unit%]"                                     <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#temperature" }
String               localCurrentCondition                    "Current condition [%s]"                                                <sun_clouds>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#condition" }
Number:Pressure      localCurrentPressure                     "Current barometric pressure [%.1f %unit%]"                             <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#pressure" }
Number:Dimensionless localCurrentHumidity                     "Current atmospheric humidity [%d %unit%]"                              <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#humidity" }
Number:Speed         localCurrentWindSpeed                    "Current wind speed [%.1f km/h]"                                        <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#wind-speed" }
Number:Angle         localCurrentWindDirection                "Current wind direction [%d %unit%]"                                    <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#wind-direction" }
Number:Length        localCurrentRainVolume                   "Current rain volume [%.1f %unit%]"                                     <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#rain" }
Number:Length        localCurrentSnowVolume                   "Current snow volume [%.1f %unit%]"                                     <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#snow" }
Number:Length        localCurrentGustSpeed                    "Current Gust Speed Windböen[%.1f %unit%]"                              <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#wind-gust" }
Number:Dimensionless localCurrentCloudiness                   "Current cloudiness [%d %unit%]"                                        <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#cloudiness" }
String               localCurrentConditionID                  "Current condition ID[%s]"                                              <pic803>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:current#condition-id" }
String               localCurrentDummy                        "---------------------------------------"                               <clouds>      (gOWM)
DateTime             localHourlyForecast3Timestamp           "Timestamp in 03 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]" <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#time-stamp" }
Image                localHourlyForecast3ConditionIcon       "Icon"                                                                       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#icon" }
Number   localHourlyForecast3Temperature         "Temperature in 03 hours [%s °C]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#temperature" }
Number:Temperature   localHourlyForecast3Temperature_orig         "Temperature in 03 hours [%.1f %unit%]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#temperature" }

String               localHourlyForecast3Condition           "Condition in 03 hours [%s]"                                   <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#condition" }
Number:Pressure      localHourlyForecast3Pressure            "in 03 hours barometric pressure [%.1f %unit%]"                <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#pressure" }
Number:Dimensionless localHourlyForecast3Humidity            "in 03 hours atmospheric humidity [%d %unit%]"                 <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#humidity" }
Number:Speed         localHourlyForecast3WindSpeed           "in 03 hours wind speed [%.1f km/h]"                           <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#wind-speed" }
Number:Angle         localHourlyForecast3WindDirection       "in 03 hours wind direction [%d %unit%]"                       <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#wind-direction" }
Number:Length        localHourlyForecast3RainVolume          "in 03 hours rain volume [%.1f %unit%]"                        <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#rain" }
Number:Length        localHourlyForecast3SnowVolume          "in 03 hours snow volume [%.1f %unit%]"                        <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#snow" }
Number:Length        localHourlyForecast3GustSpeed           "in 03 hours Gust Speed Windböen[%.1f %unit%]"                 <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#wind-gust" }
Number:Dimensionless localHourlyForecast3Cloudiness          "in 03 hours cloudiness [%d %unit%]"                           <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#cloudiness" }
String               localHourlyForecast3ConditionId         "Condition ID [%s]"                                            <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours03#condition-id" }
String               localHourlyForecast3Dummy               "---------------------------------------"                      <clouds>      (gOWM)


DateTime             localHourlyForecast6Timestamp           "Timestamp in 06 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]" <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#time-stamp" }
Image                localHourlyForecast6ConditionIcon       "Icon"                                                                       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#icon" }
Number   localHourlyForecast6Temperature         "Temperature in 06 hours [%s °C]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#temperature" }
String               localHourlyForecast6Condition           "Condition in 06 hours [%s]"                                   <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#condition" }
Number:Pressure      localHourlyForecast6Pressure            "in 06 hours barometric pressure [%.1f %unit%]"                <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#pressure" }
Number:Dimensionless localHourlyForecast6Humidity            "in 06 hours atmospheric humidity [%d %unit%]"                 <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#humidity" }
Number:Speed         localHourlyForecast6WindSpeed           "in 06 hours wind speed [%.1f km/h]"                           <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#wind-speed" }
Number:Angle         localHourlyForecast6WindDirection       "in 06 hours wind direction [%d %unit%]"                       <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#wind-direction" }
Number:Length        localHourlyForecast6RainVolume          "in 06 hours rain volume [%.1f %unit%]"                        <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#rain" }
Number:Length        localHourlyForecast6SnowVolume          "in 06 hours snow volume [%.1f %unit%]"                        <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#snow" }
Number:Length        localHourlyForecast6GustSpeed           "in 06 hours Gust Speed Windböen[%.1f %unit%]"                 <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#wind-gust" }
Number:Dimensionless localHourlyForecast6Cloudiness          "in 06 hours cloudiness [%d %unit%]"                           <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#cloudiness" }
String               localHourlyForecast6ConditionId         "Condition ID [%s]"                                            <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours06#condition-id" }
String               localHourlyForecast6Dummy               "---------------------------------------"                      <clouds>      (gOWM)

DateTime             localHourlyForecast9Timestamp           "Timestamp in 09 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]" <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#time-stamp" }
Image                localHourlyForecast9ConditionIcon       "Icon"                                                                       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#icon" }
Number   localHourlyForecast9Temperature         "Temperature in 09 hours [%s °C]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#temperature" }
String               localHourlyForecast9Condition           "Condition in 09 hours [%s]"                                   <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#condition" }
Number:Pressure      localHourlyForecast9Pressure            "barometric pressure in 09 hours [%.1f %unit%]"                <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#pressure" }
Number:Dimensionless localHourlyForecast9Humidity            "atmospheric humidity in 09 hours [%d %unit%]"                 <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#humidity" }
Number:Speed         localHourlyForecast9WindSpeed           "wind speed in 09 hours [%.1f km/h]"                           <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#wind-speed" }
Number:Angle         localHourlyForecast9WindDirection       "wind direction in 09 hours [%d %unit%]"                       <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#wind-direction" }
Number:Length        localHourlyForecast9RainVolume          "rain volume in 09 hours [%.1f %unit%]"                        <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#rain" }
Number:Length        localHourlyForecast9SnowVolume          "snow volume in 09 hours [%.1f %unit%]"                        <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#snow" }
Number:Length        localHourlyForecast9GustSpeed           "Gust Speed Windböen in 09 hours [%.1f %unit%]"                <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#wind-gust" }
Number:Dimensionless localHourlyForecast9Cloudiness          "cloudiness in 09 hours [%d %unit%]"                           <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#cloudiness" }
String               localHourlyForecast9ConditionId         "Condition ID in 09 hours [%s]"                                <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours09#condition-id" }
String               localHourlyForecast9Dummy               "---------------------------------------"                      <clouds>      (gOWM)


DateTime             localHourlyForecast12Timestamp           "Timestamp in 12 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]" <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#time-stamp" }
Image                localHourlyForecast12ConditionIcon       "Icon"                                                                       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#icon" }
Number   localHourlyForecast12Temperature         "Temperature in 12 hours [%s °C]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#temperature" }
String               localHourlyForecast12Condition           "Condition in 12 hours [%s]"                                   <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#condition" }
Number:Pressure      localHourlyForecast12Pressure            "barometric pressure in 12 hours [%.1f %unit%]"                <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#pressure" }
Number:Dimensionless localHourlyForecast12Humidity            "atmospheric humidity in 12 hours [%d %unit%]"                 <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#humidity" }
Number:Speed         localHourlyForecast12WindSpeed           "wind speed in 12 hours [%.1f km/h]"                           <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#wind-speed" }
Number:Angle         localHourlyForecast12WindDirection       "wind direction in 12 hours [%d %unit%]"                       <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#wind-direction" }
Number:Length        localHourlyForecast12RainVolume          "rain volume in 12 hours [%.1f %unit%]"                        <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#rain" }
Number:Length        localHourlyForecast12SnowVolume          "snow volume in 12 hours [%.1f %unit%]"                        <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#snow" }
Number:Length        localHourlyForecast12GustSpeed           "Gust Speed Windböen in 12 hours [%.1f %unit%]"                <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#wind-gust" }
Number:Dimensionless localHourlyForecast12Cloudiness          "cloudiness in 12 hours [%d %unit%]"                           <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#cloudiness" }
String               localHourlyForecast12ConditionId         "Condition ID in 12 hours [%s]"                                <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours12#condition-id" }
String               localHourlyForecast12Dummy               "---------------------------------------"                      <clouds>      (gOWM)

DateTime             localHourlyForecast15Timestamp           "Timestamp in 15 hours [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]" <time>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#time-stamp" }
Image                localHourlyForecast15ConditionIcon       "Icon"                                                                       (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#icon" }
Number:Temperature   localHourlyForecast15Temperature         "Temperature in 15 hours [%.1f %unit%]"                        <temperature> (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#temperature" }
String               localHourlyForecast15Condition           "Condition in 15 hours [%s]"                                   <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#condition" }
Number:Pressure      localHourlyForecast15Pressure            "barometric pressure in 15 hours [%.1f %unit%]"                <pressure>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#pressure" }
Number:Dimensionless localHourlyForecast15Humidity            "atmospheric humidity in 15 hours [%d %unit%]"                 <humidity>    (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#humidity" }
Number:Speed         localHourlyForecast15WindSpeed           "wind speed in 15 hours [%.1f km/h]"                           <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#wind-speed" }
Number:Angle         localHourlyForecast15WindDirection       "wind direction in 15 hours [%d %unit%]"                       <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#wind-direction" }
Number:Length        localHourlyForecast15RainVolume          "rain volume in 15 hours [%.1f %unit%]"                        <rain>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#rain" }
Number:Length        localHourlyForecast15SnowVolume          "snow volume in 15 hours [%.1f %unit%]"                        <snow>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#snow" }
Number:Length        localHourlyForecast15GustSpeed           "Gust Speed Windböen in 15 hours [%.1f %unit%]"                <wind>        (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#wind-gust" }
Number:Dimensionless localHourlyForecast15Cloudiness          "cloudiness in 15 hours [%d %unit%]"                           <cloudiness>  (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#cloudiness" }
String               localHourlyForecast15ConditionId         "Condition ID in 15 hours [%s]"                                <pic600>      (gOWM)              { channel="openweathermap:weather-and-forecast:api:local:forecastHours15#condition-id" }
String               localHourlyForecast15Dummy               "---------------------------------------"                      <clouds>      (gOWM)

I made this change for summarazing the values in the rule. Now this works. Perhaps there’s a better solution.

And the Test-Rule-File is:

import org.eclipse.smarthome.model.script.ScriptServiceUtil
  var dayindex = 0  // day index
  var dcountindex = 0 // items a day
  var sum_temp_curr =0
 
rule owmSummarize_test
  when
   Item Dummy3 received command ON or
	 Item localLastMeasurement changed
  then
   var itemindex = 3 //item index
   var itemstep  = 3 //item step
   var count_day1 = 0
   var avg_temp_day1 = 0
   var Number sum_temp_day1 =0

   var current = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
   logInfo ("owm.owmSummarize", "Current-Time-Item: " + current)
  while (itemindex >=0 && itemindex <12)
  {
   var testItemTimestamp = ScriptServiceUtil.getItemRegistry.getItem("localHourlyForecast"+itemindex+"Timestamp")
   var testItemTemperature = ScriptServiceUtil.getItemRegistry.getItem("localHourlyForecast"+itemindex+"Temperature")
   logInfo ("owm.owmSummarize", "Timestamp-Item: " + testItemTimestamp + " :Temperature-Item: " + testItemTemperature)
   itemindex = itemindex + itemstep
   count_day1 = count_day1 + 1
   sum_temp_day1 = sum_temp_day1 + testItemTemperature.state  //doesn't work - without UoM in items-file it works
   logInfo ("owm.owmSummarize", " Count:  " + count_day1 + " Summe: " + sum_temp_day1 + " itemindex: " + itemindex)

  }
    avg_temp_day1 = sum_temp_day1 / count_day1   //doesn't work - works when not using UoM in items-file
   logInfo ("owm.owmSummarize", "Ende:  " + itemindex + " :Schrittweite:  " + itemstep + " Temp-AVG:  " + avg_temp_day1)
end

And the logger gives:

2018-12-03 11:52:55.687 [INFO ] [rthome.model.script.owm.owmSummarize] - Current-Time-Item: 20181203
2018-12-03 11:52:55.718 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast3Timestamp (Type=DateTimeItem, State=2018-12-03T13:00:00.000+0100, Label=Timestamp in 03 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast3Temperature (Type=NumberItem, State=12.34, Label=Temperature in 03 hours, Category=temperature, Groups=[gOWM])
2018-12-03 11:52:55.743 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  1 Summe: 12.34 itemindex: 6
2018-12-03 11:52:55.774 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast6Timestamp (Type=DateTimeItem, State=2018-12-03T16:00:00.000+0100, Label=Timestamp in 06 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast6Temperature (Type=NumberItem, State=11.16, Label=Temperature in 06 hours, Category=temperature, Groups=[gOWM])
2018-12-03 11:52:55.812 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  2 Summe: 23.50 itemindex: 9
2018-12-03 11:52:55.842 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast9Timestamp (Type=DateTimeItem, State=2018-12-03T19:00:00.000+0100, Label=Timestamp in 09 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast9Temperature (Type=NumberItem, State=10.71, Label=Temperature in 09 hours, Category=temperature, Groups=[gOWM])
2018-12-03 11:52:55.866 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  3 Summe: 34.21 itemindex: 12
2018-12-03 11:52:55.893 [INFO ] [rthome.model.script.owm.owmSummarize] - Ende:  12 :Schrittweite:  3 Temp-AVG:  11.40333333

2018-12-03 12:12:00.570 [INFO ] [.smarthome.model.script.sonoff.rules] - Tasmota Rel.Vers. set to Items:
 
2018-12-03 12:22:56.652 [INFO ] [rthome.model.script.owm.owmSummarize] - Current-Time-Item: 20181203
2018-12-03 12:22:56.678 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast3Timestamp (Type=DateTimeItem, State=2018-12-03T13:00:00.000+0100, Label=Timestamp in 03 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast3Temperature (Type=NumberItem, State=12.34, Label=Temperature in 03 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:22:56.697 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  1 Summe: 12.34 itemindex: 6
2018-12-03 12:22:56.720 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast6Timestamp (Type=DateTimeItem, State=2018-12-03T16:00:00.000+0100, Label=Timestamp in 06 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast6Temperature (Type=NumberItem, State=11.16, Label=Temperature in 06 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:22:56.737 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  2 Summe: 23.50 itemindex: 9
2018-12-03 12:22:56.757 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast9Timestamp (Type=DateTimeItem, State=2018-12-03T19:00:00.000+0100, Label=Timestamp in 09 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast9Temperature (Type=NumberItem, State=10.71, Label=Temperature in 09 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:22:56.772 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  3 Summe: 34.21 itemindex: 12
2018-12-03 12:22:56.790 [INFO ] [rthome.model.script.owm.owmSummarize] - Ende:  12 :Schrittweite:  3 Temp-AVG:  11.40333333

2018-12-03 12:24:36.871 [INFO ] [marthome.model.script.astro-rules_99] -  Moondistance updated every 5 Minutes by "astro.things " 2018-12-03T12:24:36.718+0100 / 1 Log only once an hour

2018-12-03 12:25:04.733 [INFO ] [smarthome.model.script.weather-rules] -  Forecast executed every 30 min. / 1 log only once an hour

2018-12-03 12:52:58.714 [INFO ] [rthome.model.script.owm.owmSummarize] - Current-Time-Item: 20181203
2018-12-03 12:52:58.737 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast3Timestamp (Type=DateTimeItem, State=2018-12-03T13:00:00.000+0100, Label=Timestamp in 03 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast3Temperature (Type=NumberItem, State=12.35, Label=Temperature in 03 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:52:58.755 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  1 Summe: 12.35 itemindex: 6
2018-12-03 12:52:58.780 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast6Timestamp (Type=DateTimeItem, State=2018-12-03T16:00:00.000+0100, Label=Timestamp in 06 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast6Temperature (Type=NumberItem, State=11.17, Label=Temperature in 06 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:52:58.799 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  2 Summe: 23.52 itemindex: 9
2018-12-03 12:52:58.821 [INFO ] [rthome.model.script.owm.owmSummarize] - Timestamp-Item: localHourlyForecast9Timestamp (Type=DateTimeItem, State=2018-12-03T19:00:00.000+0100, Label=Timestamp in 09 hours, Category=time, Groups=[gOWM]) :Temperature-Item: localHourlyForecast9Temperature (Type=NumberItem, State=10.72, Label=Temperature in 09 hours, Category=temperature, Groups=[gOWM])
2018-12-03 12:52:58.864 [INFO ] [rthome.model.script.owm.owmSummarize] -  Count:  3 Summe: 34.24 itemindex: 12
2018-12-03 12:52:58.895 [INFO ] [rthome.model.script.owm.owmSummarize] - Ende:  12 :Schrittweite:  3 Temp-AVG:  11.41333333

I get a sum and an average. So the Torso-Rule seems to work.

I hope you can understand what i have trying to explain in my simple, amateurishly words. Please be mercifully with me.

Thx

If it were me, I’d use groups for calculating the MIN, MAX and AVE for each day, then concatenate the values into StringItems.

Hi @5iver,
thx for reply, but itn’t that easy. As the items are not fixed to a specific date, groups have to change with, to get MIN,MAX and AVG for a day. But that’s something i would think about if all other is running.(Perhaps with Group.Member…).

At the Moment i do something like you with the normal weather-binding(with yahoo-provider) and concatenate Day, MIN and MAX in a StringItem (s.Picture above).

regards

The Items would need to be assigned to the groups programmatically. There’s still some rule coding to do, but the groups can take care of the other calculations.

1 Like

I agree with Scott. Use MyItem.addGroupName(“GroupName”) and MyItem.removeGroupName(“GroupName”) to dynamically add/remove the Items to the appropriate Group and then let the Group aggregation funciton calculate the MAX, MIN, AVG.

1 Like

Thx @rlkoshak and @5iver . I haven’t tested yet, but i think these are the two methods, i’m searching for, to group my items at runtime. I will look in your DP-tutoral too, to find a method to remove/clear all items of a group throughout.
Now i need a bit help in calculating a date. Beginning from localLastMeasurement

which is Item for the actual date, i want to get the values of the next five days and then format them to string-variables in the form “yymmdd”.

Sorry for this silly question but any hint would help.

var currentPlus1 = localMeasurement.state.plusDays(1).format("%1$tY%1$tm%1$td")
...
1 Like

thx for reply. I still have a little problem with it. when testing i got error messages.

   var day0 = localLastMeasurement.state.format("%1$tY%1$tm%1$td")                 // date today/current
   //var day5 = localLastMeasurement.state.plusDays(5).format("%1$tY%1$tm%1$td")    // date in five days   --- first test
   //var day5 = localLastMeasurement.plusDays(5).state.format("%1$tY%1$tm%1$td")    // date in five days   --- second test


2018-12-04 11:10:24.835 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'owmSummarize_test': 'plusDays' is not a member of 'org.eclipse.smarthome.core.types.State'; line 22, column 14, length 38
2018-12-04 11:12:18.186 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'owmSummarize_test': 'plusDays' is not a member of 'org.eclipse.smarthome.core.library.items.DateTimeItem'; line 23, column 14, length 32

:thinking:
Any idea ?

Try that:

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
val day1String = DateTimeType.valueOf(localLastMeasurement.state.toString).plusDays(1).format("%1$tY%1$tm%1$td")

Still an error


val day5 = DateTimeType.valueOf(localLastMeasurement.state.toString).plusDays(5).format("%1$tY%1$tm%1$td")

Message:

2018-12-04 11:29:29.533 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'owmSummarize_test': 'plusDays' is not a member of 'org.eclipse.smarthome.core.library.types.DateTimeType'; line 24, column 14, length 69

Sorry DateTimes are a bit of a pain when it comes to conversion:
See:


Then try:

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
val day0 = new DateTime.valueOf(localLastMeasurement.state.toString)
val day1String = day0.plusDays(1).toString("yyMMdd")
val day2String = day0.plusDays(2).toString("yyMMdd")
...
1 Like

Sorry to disturb you again. I made a new Rule to have no sideeffects in:

//import org.eclipse.smarthome.model.script.ScriptServiceUtil

rule test_date1_owm
  when
   Item Dummy3 received command ON 
  then

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
val day0 = new DateTime.valueOf(localLastMeasurement.state.toString)
val day1String = day0.plusDays(1).toString("yyMMdd")
val day2String = day0.plusDays(2).toString("yyMMdd")
	 
   logInfo ("owm.test_date1", " String-Item: " + day0String)
   logInfo ("owm.test_date1", "Current-Date-Item: " + day0 )
   logInfo ("owm.test_date1", "day 1 -Date-Item: " + day1String)
   logInfo ("owm.test_date1", "day 2 -Date-Item: " + day2String)
end

and got this error:

2018-12-04 12:49:06.967 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test_date1_owm': An error occurred during the script execution: null

That means that localLastMeasurement is null

:thinking: Mmmmh

When using the Rule in this way:


rule test_date1_owm
  when
   Item Dummy3 received command ON 
  then

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
//val day0 = new DateTime.valueOf(localLastMeasurement.state.toString)
//val day1String = day0String.plusDays(1).toString("yyMMdd")
//val day2String = day0.plusDays(2).toString("yyMMdd")
	 
   logInfo ("owm.test_date1", " String-Item: " + day0String)
//   logInfo ("owm.test_date1", "Current-Time-Item: " + day0 )
//   logInfo ("owm.test_date1", "day 1 -Time-Item: " + day1String)
//   logInfo ("owm.test_date1", "day 2 -Time-Item: " + day2String)
end

The logger shows me:

2018-12-04 13:16:15.177 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'test_date1.rules'
2018-12-04 13:23:16.749 [INFO ] [marthome.model.script.owm.test_date1] -  String-Item: 20181204

day0 is not a string. Try using this…

logInfo ("owm.test_date1", "Current-Date-Item: " + day0.toString)

… my preference is to use…

logInfo (“owm.test_date1”, "Current-Date-Item: {} ", day0)

val day1String = day0String.plusDays(1).toString("yyMMdd")

Should be:

val day1String = day0.plusDays(1).toString("yyMMdd")
1 Like

thx @5iver .

Test:
Rule:

rule test_date1_owm
  when
   Item Dummy3 received command ON 
  then

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
val day0 = new DateTime.valueOf(localLastMeasurement.state.toString)
//val day1String = day0String.plusDays(1).toString("yyMMdd")
//val day2String = day0.plusDays(2).toString("yyMMdd")
	 
   logInfo ("owm.test_date1", " String-Item: " + day0String)
//   logInfo ("owm.test_date1", "Current-Time-Item: " + day0 )
   logInfo ("owm.test_date1", "Current-Date-Item: " + day0.toString)
//   logInfo ("owm.test_date1", "day 1 -Time-Item: " + day1String)
//   logInfo ("owm.test_date1", "day 2 -Time-Item: " + day2String)
end

Logger:

2018-12-04 13:31:24.252 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'test_date1_owm': An error occurred during the script execution: null

Same error.:thinking:

Try this…

var day0String = localLastMeasurement.state.format("%1$tY%1$tm%1$td")
logInfo ("owm.test_date1", "String-Item: {}", day0String)
val day0 = new DateTime(localLastMeasurement.state.toString)
logInfo ("owm.test_date1", "Current-Time-Item: {}", day0)
val day1String = day0.plusDays(1).toString("yyMMdd")
logInfo ("owm.test_date1", "day 1 -Time-Item: {}", day1String)
val day2String = day0.plusDays(2).toString("yyMMdd")
logInfo ("owm.test_date1", "day 2 -Time-Item: {}", day2String)

By logging after each line, you can figure out where your errors occur. day0 was not defined properly.