[SOLVED] Rule DSL DateTimeType add minutes

Hi all I want to do what I thought would be simple but really struggling.

I want a ruleDSL script to show a time plus 5 minutes no matter what I try i get errors - the script below shows the current time and works

all I want is that plus 5 minutes

Any help appreciated

var thetime = new DateTimeType
logInfo("testing",thetime.toString)
BackIn.postUpdate(thetime.format("%1$tI:%1$tM").toString) 

Show it where?

Nowhere are you actually adding five minutes in that code.

A DateTime Item, when sent a String date time, requires that String to conform to ISO8601. You’ve formatted it to not conform to that specification.

Have you seen DateTime Conversion (openHAB 3.x)?

var theTime = now
logInfo("testing", theTime.toString)
var plusFiveMin = now.plusMinutes(5)
logInfo("testing", plusFiveMin.toString()
BackIn.postUpdate(plusFiveMin)

Hi @rlkoshak thanks for the reply - my question may have been worded unclearly - the script was to show what I got to only show the now time.
Thanks this got me going, I look at that link and my eyes start to go crosseyed and get very lost very quickly with all the information so thanks for dumbing it down to something I can understand. I did find something in the comments of that link which hepled me format the string as well so Ive included here for anyone in the same boat. Couldnt work out where to find a comprehensive list of pattern options - wanted AM or PM but “hh:mm aa” was all I could find which doesnt work but no biggie.

val formatter = java.time.format.DateTimeFormatter.ofPattern("hh:mm")
var theTime = now
var plusFiveMin = now.plusMinutes(5).format(formatter) 
BackIn.postUpdate(plusFiveMin)

That’s pointless, you don’t use the variable theTime that you create anywhere else.

It’s using Java formatter
https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html

“hh:mm p”

1 Like