[SOLVED] Display of time of a DateTime type

Hi,

I am querying a time from an item and want to display it on a GUI (Habpanel).

I have set up the binding and a corresponding item. The DateTime type returns simply one string consisting of date and time, e.g.

2019-10-28T17:13:40.000+0100

To only see hour and minute I have set up the item formatting rule like this:

DateTime I_Sunset_Time “Sunset [%1$tH:%1$tM]” {channel=“astro:sun:home:set#start”}

This, however, still prints the full string into the variable, not only hour and minute. How can I actually show the correct value instead?

Thanks a lot,
Torsten

I use [%1$tr]in my label. I think that includes the seconds too, though. That will not change the variable, AFAIK.

EDIT: I see you wanted a 24 hour clock time I think that would be [%1$tR]

Do you mean that you are changing the item definition to this?

DateTime I_Sunrise_Time "Sunrise [%1$tR]" {channel="astro:sun:home:rise#end"}

That does not change anything, though. Still, the full format string consisting of date and time is displayed.

try the following - works for me:

DateTime Sunrise_Time  	
    "Sunrise [%1$tH:%1$tM]"  	
    <sunrise>		
    { channel="astro:sun:home:rise#start" }	

What UI are you using?
I believe that should be correct based in looking remotely at my REST API. I will verify my text Item after I get home.

But this is the same format string that I used in my query already. The item value as way as the display on Habpanel is the full string consisting of date and time in that case.

I am using Habpanel.

OK, I have not yet used Habpanel. Just Basic UI currently.

You are right - it’s the same :thinking:
At least under BasicUI it shows the correct behavior - the relevant part of my sitemap looks like this:

Text item=Sunrise_Time

As I’m not using HabPanel I have no idea how you have to configure it for HabPanel - but your Item definition should be fine :thinking:

I am not even clear about what is the intended way:

a) Do I need to format the value of the Item already with that format string, such that I can also already see a properly formated item value in the log?

b) or do I change only the display via a format string within HabPanel?

My understanding is that the format string in the Item definition does a). Is that correct? If not, what affect would the format string in the item definition have?

I wouldn’t say you ‘need’ to format the label in the item definition - but you can. I prefer to format the label in the item definition - to have a clearly readable label where ever I access the item (rules, log, sitemap).
But you could skip the label part of the item definition and just define a label in your sitemap file (still no idea about HabPanel).
But be aware that if you set a label in the sitemap definition you will override your label from the item definition.

Ok, but in that case it is totally irrelevant whether I am using HabPanel or BasicUI because the format definition does not work in the first place. I am seeing the following in the log when the date is set by the binding even though the format string is used in the item definiton:

Sunset_Time changed from NULL to 2019-10-28T17:13:40.000+0100

That log entry format is determined by the binding or Item definitions to be generic but accurate. Here is one of mine.

sunset_time changed from 2019-10-27T18:24:00.000-0400 to 2019-10-28T18:23:00.000-0400

Sorry if my answer wasn’t clear on that: you have to make a diffrence between the items value - and the items label.
With the part

in the item definition you are setting the label of the item - not the value.
The label is what you are displaying in BasicUI (and probably also HabPanel?) - the item value is not changed by the format of the label!
One way to check that: if you are writing in a rule Sunrise_Time.state.toString would deliver what you see in your log (2019-10-28T06:36:40.000+0100) while Sunrise_Time.label would deliver something like “Sunrise 06:36” for my item definition above.

EDIT:
If you want to see the effect live whenever your item is changing than use the following rule (replace Sunrise_Time with your own item name):

rule "Test Label"
when
  Item Sunrise_Time changed
then
  logInfo("Test Label", "Item value changed to: " + Sunrise_Time.state.toString)
  logInfo("Test Label", "Item label is: " + Sunrise_Time.label)
end
1 Like

This will be a bit of a summary of what has already been said with one new piece of information.

The "Sunset [%1$tH:%1$tM]” does not change the actual value stored. It only changes how the value appears when displayed on the sitemap or HABPanel.

A DateTime Item is a single instant in time. There is no such thing as a date time of 17:13:30. That’s just the time, there is no date.

Now for the key bit of info. When you put the DateTime on your HABPanel, as for example a Dummy widget, there is a checkbox that causes HABPanel to use the format defined on the Item.

If you don’t check that, you need to define the format (I think it uses the same syntax) in the field above the checkbox.

3 Likes

Unfortunately it is not working this way.

When I check the box in Habpanel to use the server provided format it will not display anything - the display box remains empty.

I have tried using simply the term “HH:MM” as defined format instead, but while this seems to be working at first sight it actually displays wrong information because it mistakes a wrong piece of the string for the minutes.

E.g. for the DateTime string: 2019-10-29T16:48:00.000+0100 it displays “16:10” on the UI, because probably it takes the 10 of October as minutes instead.

Using the string from the format definition is not accepted either. The formating text itself is displayed on the UI in that case.

MM is often months. Try mm which usually means minutes.

2 Likes

This is actually working! :slight_smile:

Thank you!

Can this be done to the info displayed in the “control” tab of PaperUI?

PaperUI is just an administrator’s toolbox, and does not offer any real display formatting.

The user-facing UIs do, of course.

1 Like