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?
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 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
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
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.
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.