[SOLVED] Is there a way to get the current time to an item?

Hi, is there a way to get the current time to an item?

I have the following item:

DateTime Temp_update    <time>      { channel = "mqtt:topic:fceb####:Temp_update"}

Now I need a rule that puts the current time in this item.
Something like this:

when something changed 

Item Temp_update = currentTime

Is that possible?

Thanks for your help!

have you tried postUpdate?


1 Like

Hey, I tried that, but when I go in the habpanel the dummy were I linked the “Temp_update” says “UNDEF” and it says the following in the logviewer

Rule 'Temperature': The name 'currentTime' cannot be resolved to an item or type; line 38, column 28, length 11

try this

Temp_update.postUpdate(new DateTimeType())

But what’s about your linked channel ? You should leave it away, or ?

1 Like

Hi thanks for your fast reply!
What do you mean with leave it away?

This one worked :slight_smile: but is shows very much information: 2019-04-17T10:26:01.038+0200
Is it possible just to show the time? (10:26:01)

As you will overwrite the channel-info, you don’t need it from the binding. I think this can end in an invite loop. (Not really :wink:, as you’re using "postUpdate). But if you want to have the channel-information too, better use a Dummy-Item.

To show specific information you have to use Formatting in the Label. Either in your .items.file or in your SiteMap/HABPanel.

Here an example out of my Item-Set:

DateTime             localLastMeasurement                    "Datum letzte Messung [%1$ta, %1$ty-%1$tm-%1$td %1$tH:%1$tM]"     <time>         (gOWM,gOWMOutlook)  { channel="openweathermap:weather-and-forecast:api:local:current#time-stamp" }



Hey, the following question might sound “stupid” but
how can I create a item without adding it to a thing?
For now I added my Temp_update item to the Temp. sensor, but I can’t configure the item as I want to…
You must have in mind that I’m very new to all this.

What is this line doing?
Thanks in advance!

Just create a new item like this:

DateTime  lastRuleRefresh   "Regel ausgeführt um [%1$tH:%1$tM:%1$tS]"      <time>    // Value calculated via Rule 

As you see the first formatter looks a bit different from this one.

The results can look like:

1 Like

Hi, you really helped me a lot today and it is finally working!
Thank you!! :smile:

Fine to hear. If everything’s ok now, pls. mark your post as solved at the post which helps you.

EDIT: here and here you can read something about Formatters

1 Like