I want to have a summary of my minimum, maximum temperature over the current day.
I have developed the following:
rule "Telegram commands"
when
Item Command changed
then
switch(Command.state) {
...
case "TEMP": {
sendTelegram("...","Temperature graph requested")
val java.text.DecimalFormat df = new java.text.DecimalFormat("#.##")
val Number round = Double.valueOf(df.format(TemperatureValue.state as DecimalType))
val Number round2 = Double.valueOf(df.format(TemperatureOutdoor.state as DecimalType))
val Number round3 = Double.valueOf(df.format(HumidityValue.state as DecimalType))
val Number round4 = Double.valueOf(df.format(HumidityOutdoor.state as DecimalType))
var String ts = now.withTimeAtStartOfDay.toString("dd/MM HH:mm:ss")
val max = TemperatureValue.maximumSince(now.withTimeAtStartOfDay)
val min = TemperatureValue.minimumSince(now.withTimeAtStartOfDay)
val maxS = Double.valueOf(df.format(max.state as DecimalType))
val minS = Double.valueOf(df.format(min.state as DecimalType))
val maxo = TemperatureOutdoor.maximumSince(now.withTimeAtStartOfDay)
val mino = TemperatureOutdoor.minimumSince(now.withTimeAtStartOfDay)
val maxSo = Double.valueOf(df.format(maxo.state as DecimalType))
val minSo = Double.valueOf(df.format(mino.state as DecimalType))
sendTelegram("...", "Inside: "+round+" ÂşC, Outside: "+round2+" ÂşC\n"+"Inside HR: "+round3+" %, Outside HR: "+round4+" %\nToday's InsideMin: "+minS+" ÂşC, Today's InsideMax: "+maxS+" ÂşC\nToday's OutsideMin: "+minSo+" ÂşC, Today's OutsideMax: "+maxSo+" ÂşC")
}
What I want is to know when the maximum and minimum temperature occurred, so I can say… “At XX:XX:XX was the maximum temperature”.
I don’t think so, at least not using persistence data of that item. Happy to see someone prove me wrong, though.
You could put up a rule to trigger on every temp change and track the time of day of the maximum in a DateTime variable.
rule "Max/Min Temp"
when
Item OutsideAirTemp changed
then
if (cWX_Temp_TodayMax.state == NULL) {
cWX_Temp_TodayMax.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMax_Time.postUpdate(new DateTimeType)
}
if (OutsideAirTemp.state as Number > cWX_Temp_TodayMax.state as Number) {
cWX_Temp_TodayMax.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMax_Time.postUpdate(new DateTimeType)
}
if (cWX_Temp_TodayMin.state == NULL) {
cWX_Temp_TodayMin.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMin_Time.postUpdate(new DateTimeType)
}
if (cWX_Temp_TodayMin.state as Number > OutsideAirTemp.state as Number) {
cWX_Temp_TodayMin.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMin_Time.postUpdate(new DateTimeType)
}
end
rule "6pm Min Temp Reset"
when
Time cron "0 0 18 * * ?" // 6 pm
then
cWX_Temp_TodayMin.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMin_Time.postUpdate(new DateTimeType)
sendTweet("Day time maximum temperature " + cWX_Temp_TodayMax.state.format("%.1f°C") + " at " + cWX_Temp_TodayMax_Time.state.format("%1$tH:%1$tM"))
end
rule "6am Max Temp Reset"
when
Time cron "0 0 6 * * ?" // 6 am
then
cWX_Temp_TodayMax.postUpdate(OutsideAirTemp.state.toString)
cWX_Temp_TodayMax_Time.postUpdate(new DateTimeType)
sendTweet("Overnight minimum temperature " + cWX_Temp_TodayMin.state.format("%.1f°C") + " at " + cWX_Temp_TodayMin_Time.state.format("%1$tH:%1$tM"))
end
Along with the item definitions:
Number cWX_Temp_TodayMax "Day Max Temp [%.1f °C]" <temperature> (gWeatherStation, gInfluxSlow)
DateTime cWX_Temp_TodayMax_Time "Max Temp Time [%1$tH:%1$tM]" <temperature> (gWeatherStation)
Number cWX_Temp_TodayMin "Night Min Temp [%.1f °C]" <temperature> (gWeatherStation, gInfluxSlow)
DateTime cWX_Temp_TodayMin_Time "Min Temp Time [%1$tH:%1$tM]" <temperature> (gWeatherStation)
I think you are right. If maximumSince et. al. returned a HistoricItem then there is a getTimestamp method that would work. But these methods return a State and there is no such method.
I suspect it wouldn’t be too big of a job to create a HistoricState type that the persistence methods could return and that could include this timestamp. But that would be a breaking change so it would need a lot of discussion.