Hello, under OH 3.1 I try to find the value of an Item 24 hours ago with “historicState” and its persistence “influxdb”.
To do so, I created a “ZonedDateTime”.
That I converted to “DateTime”.
Then I remove 24h from my “DateTime”.
Its working, but isn’t there a cleaner way to remove a “ZonedDateTime” from 24h? or remove 2 days? like we did under OH2?
here my code:
rule "Test"
when
Item ProdSolaire received update
then
// ZonedDateTime
val ZonedDateTime Maintenant = ZonedDateTime.now().with(LocalTime.now)
logInfo("Maintenant", Maintenant.toString)
// ZonedDateTime to DateTimeType
val DateTimeType MaintenantToDateTimeType = new DateTimeType(Maintenant)
logInfo("Maintenant_DateTime", MaintenantToDateTimeType.format("%1$td du %1$tm à %1$tHh%1$tM"))
// Usage de ZonedDateTime dans la recherche dans l'historique il y as 24 h
val conso1 = (ZWaveNode019ZW095EnergyConsToday.historicState(Maintenant.minusHours(24),"influxdb").state as Number ) //Production hier
logInfo("conso24", "conso hier=" + conso1)
end
thanks and for formating ZoneDateTime to string can you tell me how whe can log ? whithout convert to DateTime and use “.format” ? or a link where i can learn ?
For exemple how i can format for log these string with ZoneDateTime :
val ZonedDateTime Maintenant = ZonedDateTime.now().with(LocalTime.now)
logInfo("Maintenant",Maintenant.toString)
// like :
logInfo("Maintenant",Maintenant.format("%1$td du %1$tm à %1$tHh%1$tM"))
thanks in advance for your time spend to help me :-
With your great links I was able to format a “ZoneDateTime” less 1 day and formatting as “String”
val ZonedDateTime Maintenant = ZonedDateTime.now().with(LocalTime.now)
logInfo("Maintenant",String.format("%1$td du %1$tm à %1$tHh%1$tM", Maintenant.minusDays(1)))
//return : "01 du 07 à 16h59"
also I was able to use “historicState” less than 24 hours directly on a “ZoneDateTime”.
val conso1 = (ZWaveNode019ZW095EnergyConsToday.historicState(Maintenant.minusHours(24),"influxdb").state as Number ) //Production 1 jours
logInfo("conso24", "conso hier=" + conso1)
//return : the good one