I calculate a time difference with these rules and would like to display the elapsed time in the sitemap.
My problem: The elapsed time is simply displayed in the local time. In the script, I simply subtract one hour, which works in wintertime, but in the summertime, I have to adjust the script again.
val long DateStart = (Gmc_brenndauer_start.state as DateTimeType).zonedDateTime.toInstant.toEpochMilli
val long Datenow = now().toInstant.toEpochMilli
val Java_Brenndauer = Instant.ofEpochMilli((Datenow - DateStart)).atZone(ZoneId.of("UTC")) // #6 convert epoch to JavaTime
val Brenndauer = new DateTimeType(Java_Brenndauer.minusHours(1)) // #3 convert JavaTime to DateTimeType
If you use a Datetime Item, it’s going to display as a date time, naturally enough. An un-advertised property of the UIs is that they will silently convert datetime to display in the system local time, too. I don’t know how to stop that.
Avoidance - don’t use a Datetime Item for an elapsed time.
Format out your result into a String Item. (but beware of it all going wrong for >24hrs, first “day” is 1 not 0)
Or use a Number:Time type Item, openHAB’s duration type.
That’s a date time format, it’s not going to work with a Number. It’s just a simple Quantity, like a Number:Temperature, a numeric with units.
There’s an idea for fancier formatting here
It’s no good commanding a Number with a datetime.
You need to send it a Quantity, a single numeric with a unit.
If you want to just update the Item, update it, don’t send a command.
You’re working with milliseconds already, so something like - Gmc_brenndauer.postUpdate(myResultInMilliseconds.toString + " mS")