[SOLVED] Temperature: minimum, maximum and when happened

Hi,

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”.

Is it possible to do it?

Thanks

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.

I use a rule like so:

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

Then you’ll need a rule that clears values once per day, right?

Oh, yes of course. Here they are:

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)
1 Like

That’s a pity. There are methods such as minimumSince maximumSince but not with the datetime values associated!

Maybe I’m wrong…?

They might exist, but I couldn’t find any documentation of them

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.

1 Like