Channel -> Item time conversion

Sun Thing from Astro Binding provides surise/sunset times as DateTime. I can’t imagine the situation when date part is needed for such Channels, and weather widget of course prints the whole DateTime which is quite ugly. I tried to add regex profile with \d±\d±\d+\s(\d+:\d+) regex but it still prints the date. I tried different regex patterns with no success. How can I eventually strip the date part?

The same with day duration that is returned in seconds. I created fake Item bound by Blockly Rule that transform seconds into HH:MM. This is way too complicated for such a trivial transformation and I can’t understand why Channel does not return value in immediately usable form. Or did I do something wrong again?

@kanyck I’m using the Type start and Type end channels in my textual configurations, and then can just assign these to DateTime Items with the following value format as an example

"Evenings [%1$tH:%1$tM]"

easily giving me

Screenshot 2026-03-10 at 19.45.23

without much fuss, with such value formatting working on all DateTime types.

With day duration or any other durations in seconds or minutes I use some javaScripts

  1. the channel delivers a data type and if it’s DateTime it simply delivers it. Same with your seconds exmaple. So data type is fully correct, machine readable but I agree - per default ugly to read
  2. Binding developers can define a default state description which converts e.g. x seconds into a UI readable 9h 21m 23s
  3. You as a user can override this state description. Perhaps you want it in german with 9 Std 21 Min 23 Sek

So in UI search your item and open it. Click on Add Metadata and select State Description.
In the pattern add the wanted conversion.
Like in the picture below Unit is seconds and is converted into hour and minutes with

%1$tHh %1$tMmin

Or DateTime into time only HH:MM

%1$tH:%1$tM

For more see openhab docs

Thanks a lot! It worked and seems nearly as simple as it’s expected to be!

However I still can not comprehend the info under the link you provided – it describes textual .item so I can’t map it to MainUI manipulations. Thus it seems irrelevant :slight_smile:

What I also can’t understand is “Evenings [%1$tH:%1$tM]” notion @Hans_Lree mentioned. Is it of any use in my case (building stuff with MainUI). Hans also provided a link, but it says HH:mm[:ss[.SSS]]not %1$tH:%1$tM. I’m completely lost in what should I use and trying to RTFM only adds up to the confusion.

I have a serious issue with the OH docs: it’s still so much oriented on textual configuration that I can’t really map it to MainUI usage. So trying to RTFM only adds up to the confusion… which means that there will be more my posts asking stupid questions. Please be patient… and thanks again!

My main reason for the link was in its first sentence

DateTimeType objects are parsed using Java’s DateTimeFormatter

which can be looked up. And yes, I do use it with purely textual definitions, but the formatting is the same, as you saw, be it for Items for sitemaps or MainUI, hence

@Hans_Lree mentioned. Is it of any use in my case (building stuff with MainUI)

of course it is :wink:

Search for Java DateTimeFormatter and now that you know the syntax, with all the different letters’ meaning you can format any DateTime Items exactly as you want, for BasicUI Sitemaps or MainUI alike.

1 Like

Just my thoughts how I personally see this.

History
openHAB has the legacy build upon text files. I really don’t like them!
My unfortunately not so small system was a mess of textual plus UI configured items, things, persistence, .... Hard to maintain!
End of last year I decided to build it up from scratch. Besides rules and some custom transformations I’ve no text config anymore.

Is it irrelevant?
My personal answer: No!
The description and content is correct. But I can understand as beginner it’s hard to translate the textual config stuff into UI config as you said.

The Evenings [%1$tH:%1$tM] contains already the pattern %1$tH:%1$tM which I posted too.
And HH:mm[:ss[.SSS]] is the standard display you mentioned if no state description is added. You described as ugly, I agree :slight_smile:

I understand. I just can explain what’s mentioned but sure I don’t see it from beginners perspective.

My advise: use AI search
If you know the bingo word which is here state description you’ll get a comprehensive answer combined from openhab docs and community posts. Also the UI config is mentioned!

1 Like

Thank you guys for your kind help!

I think I shall put it on my wall. Yet I’m afraid I don’t have enough wall surface for everything I’ll need to have in sight :roll_eyes:

It’s definitely a part of the problem. MainUI is poorly documented.

Here I used icorrect phrasing. Of course it is but is not seem so from my perspective. That’s what I was trying to say.

That’s another part of the problem. The devs and people who have been using OH for a long time have grown with it gradually and just don’t see the gaps that scares the beginners. For instance, I could not find definitions (or, better, explanations) on lots of notions used in the docs.

I have already. The only issue is that it lies now and then. But it definitely helps nevertheless, thank you!

A simple text file on your PC should probably suffice :wink:

**********************

All letters ‘A’ to ‘Z’ and ‘a’ to ‘z’ are reserved as pattern letters. The following pattern letters are defined:

Pattern Letters and Symbols

Symbol Meaning Presentation Examples
G era text AD; Anno Domini; A
u year year 2004; 04
y year-of-era year 2004; 04
D day-of-year number 189
M/L month-of-year number/text 7; 07; Jul; July; J
d day-of-month number 10
g modified-julian-day number 2451334
Q/q quarter-of-year number/text 3; 03; Q3; 3rd quarter
Y week-based-year year 1996; 96
w week-of-week-based-year number 27
W week-of-month number 4
E day-of-week text Tue; Tuesday; T
e/c localized day-of-week number/text 2; 02; Tue; Tuesday; T
F day-of-week-in-month number 3
a am-pm-of-day text PM
h clock-hour-of-am-pm (1-12) number 12
K hour-of-am-pm (0-11) number 0
k clock-hour-of-day (1-24) number 24
H hour-of-day (0-23) number 0
m minute-of-hour number 30
s second-of-minute number 55
S fraction-of-second fraction 978
A milli-of-day number 1234
n nano-of-second number 987654321
N nano-of-day number 1234000000
V time-zone ID zone-id America/Los_Angeles; Z; -08:30
v generic time-zone name zone-name Pacific Time; PT
z time-zone name zone-name Pacific Standard Time; PST
O localized zone-offset offset-O GMT+8; GMT+08:00; UTC-08:00
X zone-offset ‘Z’ for zero offset-X Z; -08; -0830; -08:30; -083015; -08:30:15
x zone-offset offset-x +0000; -08; -0830; -08:30; -083015; -08:30:15
Z zone-offset offset-Z +0000; -0800; -08:00
p pad next pad modifier 1
escape for text delimiter
‘’ single quote literal
[ optional section start
] optional section end
# reserved for future use
{ reserved for future use
} reserved for future use
1 Like