OH2 to OH3 rule Timestamp not working

I am trying to get an OH2 rule to work with OH3

Rule that works with OH2 and creates a timestamped .jpg file:

var FrontDoorCamA = "FrontDoorA"+ now.toString ("MM-dd-yyyy_HH-mm-ss") +".jpg"
executeCommandLine("wget http://user:pass@192.168.xx.xx:port/Streaming/Channels/1/picture -O /usr/share/openhab2/pictures/" +FrontDoorCamA)

I have made these changes, but it seems like I am missing something:

var FrontDoorCamA = "FrontDoorA"+ ("MM-dd-yyyy_HH-mm-ss") +".jpg"
executeCommandLine("wget", "http://user:pass@192.168.xx.xx:port/Streaming/Channels/1/picture", "-O", "/usr/share/openhab/pictures/" +FrontDoorCamA)

This only creates a file called: FrontDoorAMM-dd-yyyy_HH-mm-ss.jpg

I have also tried the following but noting that works:

var FrontDoorCamA = "FrontDoorA"+ ZonedDateTime.now() +".jpg"           // no errors, no file created
var FrontDoorCamA = "FrontDoorA"+ (ZonedDateTime now()) +".jpg"         // no errors, no file created
var FrontDoorCamA = "FrontDoorA"+ ("ZonedDateTime now()") +".jpg"         //no errors, FrontDoorAZonedDateTime.now().jpg
var FrontDoorCamA = "FrontDoorA"+ "ZonedDateTime now()" +".jpg"            //no errors, FrontDoorAZonedDateTime.now().jpg
var FrontDoorCamA = "FrontDoorA"+ ZonedDateTime now +".jpg"           // no errors, no file created
var FrontDoorCamA = "FrontDoorA"+ (ZonedDateTime now) +".jpg"        // no errors, no file created
var FrontDoorCamA = "FrontDoorA"+ ("ZonedDateTime now") +".jpg"     //no errors, FrontDoorAZonedDateTime.now.jpg
var FrontDoorCamA = "FrontDoorA"+ "ZonedDateTime now" +".jpg"       //no errors, FrontDoorAZonedDateTime.now.jpg
var FrontDoorCamA = "FrontDoorA"+ ZonedDateTime +".jpg"                 //no errors, FrontDoorAclass java.time.ZonedDateTime.jpg
var FrontDoorCamA = "FrontDoorA"+ (ZonedDateTime) +".jpg"               //no errors, FrontDoorAclass java.time.ZonedDateTime.jpg
var FrontDoorCamA = "FrontDoorA"+ ("ZonedDateTime") +".jpg"             //no errors ,  FrontDoorAZonedDateTime.jpg
var FrontDoorCamA = "FrontDoorA"+ "ZonedDateTime" +".jpg"               //no errors, FrontDoorAZonedDateTime.jpg
var FrontDoorCamA = "FrontDoorA"+ ZonedDateTime() +".jpg"                // failed: The name 'ZonedDateTime' cannot be resolved to an item or type
var FrontDoorCamA = "FrontDoorA"+ (ZonedDateTime()) +".jpg"             // failed: The name 'ZonedDateTime' cannot be resolved to an item or type
var FrontDoorCamA = "FrontDoorA"+ ("ZonedDateTime()") +".jpg"          // no errors, FrontDoorAZonedDateTime().jpg
var FrontDoorCamA = "FrontDoorA"+ "ZonedDateTime()" +".jpg"            //no errors, FrontDoorAZonedDateTime().jpg

Have a look here:

Yeah, I have that page bookmarked.
I’m still stumped.

Why? No. 11 or 11 should be your solution


Or with formatting.

Maybe you bookmarked 2.5 tutorial?

Working with Date only. No time.

var FrontDoorCamA = "FrontDoorA"+ now.toLocalDate().toString() +".jpg"      //creates FrontDoorA2023-02-05.jpg
var FrontDoorCamA = "FrontDoorA"+ now.toLocalDateTime().toString() +".jpg"  // creates random file:  F0BZEN~9.JPG
var FrontDoorCamA = "FrontDoorA"+ LocalDate.now() +".jpg"                   //creates FrontDoorA2023-02-05.jpg
var FrontDoorCamA = "FrontDoorA"+ LocalDateTime.now() +".jpg"              //creates random file:   FSGC3M~X.JPG
var FrontDoorCamA = "FrontDoorA"+ LocalTime.now() +".jpg"                  //creates random file:    F73IYN~M.JPG

Make it without now, because thats a java time.

var FrontDoorCamA = "FrontDoorA_"+ (new DateTimeType()).format("%1$tY-%1$tm-%1$td_%1$tH_%1$tM_%1$tS")+".jpg"   

LocalDateTime.now().toString() works too, you missed the toString() after now().

this works too on my system. Interesting you got a random filename

logInfo("Test", "Wert: "+(new DateTimeType()).format("%1$tY.%1$tm.%1$td_%1$tH_%1$tM_%1$tS"))
logInfo("Test2", "Wert: "+now.toString)
logInfo("Test3", "Wert: "+now.toString())
logInfo("Test4", "Wert: "+LocalDateTime.now().toString())
logInfo("Test5", "Wert: "+now.toLocalDateTime().toString())


2023-02-05 20:49:00.338 [INFO ] [org.openhab.core.model.script.Test  ] - Wert: 2023.02.05_20_49_00
2023-02-05 20:49:00.338 [INFO ] [org.openhab.core.model.script.Test2 ] - Wert: 2023-02-05T20:49:00.338854+01:00[Europe/Berlin]
2023-02-05 20:49:00.339 [INFO ] [org.openhab.core.model.script.Test3 ] - Wert: 2023-02-05T20:49:00.339117+01:00[Europe/Berlin]
2023-02-05 20:49:00.339 [INFO ] [org.openhab.core.model.script.Test4 ] - Wert: 2023-02-05T20:49:00.339464
2023-02-05 20:49:00.340 [INFO ] [org.openhab.core.model.script.Test5 ] - Wert: 2023-02-05T20:49:00.339844

This is working

var FrontDoorCamA = "FrontDoorA_"+ (new DateTimeType()).format("%1$tY-%1$tm-%1$td_%1$tH_%1$tM_%1$tS")+".jpg"      //creates good file:  FrontDoorA_2023-02-05_16_36_32.jpg

this one dosen’t work:

var FrontDoorCamA = "FrontDoorA"+ LocalDateTime.now().toString() +".jpg"        //creates random: FEHNRP~W.JPG

Thank you so much for all your help!

Did you updated to actual Java? OpenHAB uses Java 11 if I remember right

oh3:~$ java -version
openjdk version “11.0.17” 2022-10-18
OpenJDK Runtime Environment (build 11.0.17+8-post-Ubuntu-1ubuntu222.04)
OpenJDK 64-Bit Server VM (build 11.0.17+8-post-Ubuntu-1ubuntu222.04, mixed mode, sharing)

Very interesting the second works here with same Java version but not for you …

Maybe because you didn’t define

var string ‚variable‘ =….

But equal, your problem is solved :slight_smile: