Advertisement
__Dave__

OpenHAB - Sekunden als Zeit formatieren

Oct 29th, 2020 (edited)
2,146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.10 KB | None | 0 0
  1. ITEMS:
  2.  
  3. Number OctoprintPrintTimeLeft "Verbleibende Zeit [%.0f s]" <time> (gOctoprint) {mqtt="<[broker:octoprint/progress/printing:state:JSONPATH($.printer_data.progress.printTimeLeft)]"}
  4. String OctoprintPrintTimeLeftString "Verbleibende Zeit[%s]" <time> (gOctoprint)
  5. DateTime OctoprintPrintETADateTime "ETA [%1$tA, %1$td.%1$tm.%1$tY %1$tH:%1$tM]" <time> (gOctoprint)
  6.  
  7.  
  8. RULE:
  9.  
  10. rule "Time Left String"
  11. when
  12.     Item OctoprintPrintTimeLeft changed
  13. then
  14.     val seconds = (OctoprintPrintTimeLeft.state as DecimalType).intValue
  15.     val int totalMinutes = seconds/60
  16.     val int remainderSecs = seconds%60
  17.     val int totalHours = totalMinutes/60
  18.     val int remainderMins = totalMinutes%60
  19.     val formattedTime = String::format("%02d", totalHours) + ":" + String::format("%02d", remainderMins) + ":" + String::format("%02d", remainderSecs)
  20.     OctoprintPrintTimeLeftString.postUpdate(formattedTime)
  21.  
  22.     val DateTime OctoprintETA = now.plusSeconds(seconds)
  23.     OctoprintPrintETAString.postUpdate(OctoprintETA.toString)
  24.     OctoprintPrintETADateTime.postUpdate(new DateTimeType(OctoprintETA.toString))
  25.  
  26. end
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement