Calculation of a DateTime Item in Openhab

Hello,

I use the NTP Binding in Openhab 4.0.4 to get the current DateTime in this variable.

DateTime    Datum           "[%1$td.%1$tm.%1$tY]"    {channel="ntp:ntp:ce4bc9acd6:dateTime"}

The value is like this:

2023-12-13T10:37:45.153+0100

Now I want to increase this value +1 day to get the date of tomorrow.

The variable has to be the same DateTime Typ like:

DateTime    Datum2          "[%1$td.%1$tm.%1$tY]"

Are there any hints for a simple solution?

Thanks in advance.

Have a look into timestamp-offset profile

This Profile can be specified via the parameter offset (in seconds) which has to be a DecimalType. The specified offset will be applied to the date time before it is passed to the Item. Additionally it allows to modify the timezone by setting the parameter of the same name (e.g. “Europe / Berlin”).

Terminology is important and using the wrong terms can be an indication of confusion.

In this case Datum is an Item, not a variable. Items, among other things, carry a State and in this case the State is a DateTimeType. Items are often linked to Channels where the Item gets it’s State (in this case the NTP binding).

The term “variable” implies you are working inside a rule.

So for what purpose are you using Datum and Datum2? If it’s just for display on your sitemap/MainUI then @Matze0211’s approach will work just fine.

If you are looking to use these in a rule somehow, you don’t even need the Items. Assuming Rules DSL, the current time is in the implicit variabel now and tomorrow can be calculated using now.plusDays(1).

Thanks for your answers.

In my use case, I get an appointment back from my Google calendar via the Ical Binding. I would like to compare this date with the date today (which I get via the NTP binding “Datum”) and a comparison with the date of tomorrow (Datum2).

Visually? In a rule? If a rule what language? What sort of comparison? What do you want to happen when the comparison is true? When false?

If in a rule, like I said, you don’t need an Item nor the NTP binding. If using Rules DSL now will be this exact moment in time. Blockly has a now block. JS Scripting has time.toZDT(). In all the cases to compare to get a date time for tomorrow you just add a day (e.g. now.plusDays(1)).

Let’s say you are using Blockly and your iCal Item is MyItem:

Notice, the only Item involved here is the iCal Item.

I want to use it in this scenario: Garbage Collection - Add-on Marketplace / UI Widgets - openHAB Community

I want to make the same thing on my own system. In my case it is enough to display “Today” and the “Tomorrow” UseCase. Everything works (Today) but the comparison of the dates don’t work (Tomorrow) because I can’t calculate it. To my Idea was to make a rule for once a day to make the calculation.

I do not use Blocky. I like to have real source code.

OK, but in that scenario the DateTimes are coming from a calendar through the iCal binding. Neither now, tomorrow, nor the NTP binding has anything to do with that widget. You just need a series of DateTime Items with the date of the next collection and the widget handles the rest.

That’s reasonable.

Then it should be relatively simple for you to translate the above Blockly to the language of your choice. All the reference docs for all of the supported languages cover how to add/subtract time to now.

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.