zizebra
(Zizebra)
November 5, 2023, 9:49pm
1
Hi All
I would like to format the value for string item. The string is holding a date. I have defined statedescription pattern and it shows up as undefined
The yaml code for the widget is below
component: oh-label-cell
config:
expandable: false
item: loadshedding_counter
stateAsHeader: true
title: Loadshedding Time
footer: '= "StartTime: " + items.ld_StartTime_item.displayState'
the statedescription pattern is below
value: " "
config:
pattern: "%1$tY.%1$tm.%1$td %1$tH:%1$tM:%1$tS"
did you try
footer: '= "StartTime: " + items.ld_StartTime_item.state'
?
What does your item show in openHAB MainUI Items menu?
zizebra
(Zizebra)
November 6, 2023, 6:32am
3
Thank you Sebastian, yes that works but i would like to display the date differently hence i attempted using pattern
uk59821
(Ulf Kräling)
November 6, 2023, 7:32am
4
In an Label component I’m using this
text: ="Herausgegeben:\ " + @props.itemIssued
with this item pattern:
%1$td.%1$tm.%1$tY %1$tH:%1$tM
and it works.
zizebra
(Zizebra)
November 6, 2023, 8:10am
5
I assume your item is of type datetime. That would work. In my case, my item is of type string hence my challenge. The above works on my items which are datetime. Iam needing to format an item which is a string type.
uk59821
(Ulf Kräling)
November 6, 2023, 9:29am
6
oh, my fault I should better read the question
This should work:
footer: '= "StartTime:\ " + dayjs("2023-11-08T04:00:00+02:00").format("YYYY.MM.DD HH:mm:ss ")'
footer: '= "StartTime:\ " + dayjs(items.ld_StartTime_item.state).format("YYYY.MM.DD HH:mm:ss ")'
The description of dayjs().format you can find here
I hope it helps better
zizebra
(Zizebra)
November 6, 2023, 9:53am
7
Brilliant that is it. Just wwhat i wanted.