UoM: Number:Temperature minimumSince

for my blindcontrols I would like to know the lowest temperature of the last night.
my Item is a UoM formatted item and I can´t figure out the correct syntax combined with minimumSince:

Number:Temperature Temperature_outside “Aussentemperatur [%.1f °C]” (Temp_stat, Weather_stat, gTemp_EG) { channel="…"}

logInfo(“test”, "minimum Temp: ", Temperature_outside.minimumSince(now.minusHours(24) as QuantityType).intValue)

Validation issues found in configuration model 'testrule.rules', using it anyway: 
Cannot cast from DateTime to QuantityType<Temperature>

yes, a possible workaround would be to create a second Item without UoM and do Temperature_outside.minimumSince(now.minusHours(24))

Look closely at the used brackets, you are asking for the minimumsince for a datetime, because one closing bracket is misplaced.

tried to move the bracket to:
logInfo("test", "minumum Temp: ", Temperature_outside.minimumSince(now.minusHours(24)) as QuantityType<Temperature>.intValue)

Rule ’ test’: Could not cast org.openhab.core.persistence.internal.QueryablePersistenceServiceDelegate$1@17fc1c9 to void; line 9, column 51, length 77

See the docs, this returns an historicState object, you should at least convert to string for printing
Temperature_outside.minimumSince(now.minusHours(24)).toString

It’s going to give you a simple number in the .state part, persistence service does not (yet) handle UoM

Ok, from the docs I couldn’t see that persistence is not available for UoM.
minimumSince and averageSince do need different syntaxes:

logInfo("test", "minimum Temp: " + Temperature_outside1.minimumSince(now.minusHours(24)).state )
logInfo("test", "average Temp: " + Temperature_outside1.averageSince(now.minusHours(24)))

minimumSince requires .state
averageSince fails with .state

So, a persistence extension that returns a historicItem needs the .state syntax. a persistence extension that returns something else (eg a calculation like average or delta) does not need .state

ok, the docs tell which extensions do return a historicItem and also note that:

The most useful methods of the HistoricItem object returned by some queries, are .state and .getTimestamp

btw. Temperature_outside1.minimumSince(now.minusHours(24)).toString fails too, it has to be .state.toString :wink:

1 Like