Question about trigger Time is <DateTimeType item>

Hi:
Not sure if it’s a bug or I misunderstood how the “Time is” trigger supposed to work.
I noticed the charging schedule was executed last night at 1AM despite that I have reset the DateTime item to 1970-01-01T01:00:00.000+0100 (I’m in the timezone +0100).

Item 'Charging_start_time' changed from 2025-02-12T03:00:00.000+0100 to 1970-01-01T01:00:00.000+0100

My question: is "Time is " triggered only by time (and ignore the date)?
I have read through the documentation (Textual Rules | openHAB) but couldn’t find any description there.

And if it is the case, my next question: how to make sure it is triggered “now” on today’s date?

Many thanks in advance!

Hi, if you are using rulesDSL for your rule you have 2 kinds of time triggers…

Time is <DateTimeTypeItem> 

is executed at the exact time and date.

Time is <DateTimeTypeItem> timeOnly 

is executed every day at the time only :wink:

Greets

1 Like

Even when your trigger is this (without timeOnly), but if your DateTimeItem contains 1970-01-01 as its date, it will be treated as timeonly, hence it will trigger every day.

I think this was initially committed by @J-N-K? I presume there’s a reason for this behaviour, but I can’t figure it out. Perhaps it was done before we had the timeOnly option?

Ok, can I ask why is that? My trigger is defined as below without “timeOnly”:

when Time is Charging_start_time

In the past I reset to UNDEF so it’s my first time to see this problem. As resetting to UNDEF gives a problem when OH restarts, it loads the previous value from persistency service (UNDEF is ignored). Hence now I change all rules to reset to 1970-01-01T01:00:00.000+0100

That’s what I was asking too.

Have you tried to set it to null? Or simply don’t persist it?

Or set it to yesterday

Can’t set it to null as I have a rule to check all items have value (instead of null).
And also need to persist it, as otherwise schedule will not run if OH get restarted.
So my current solution is to check in my rules if now - DateTimeItem < 1minute. It’s not ideal and I think it should be fixed in OH for consistency.

Before we added the timeOnly option (which happened sometime after adding the Time is Item trigger) I think that’s how timeOnly was handled.

What about changing the date to some time far into the future instead of a time in the past?

Hi @jimtng and @rlkoshak :

Do you know is it only the date 1970-01-01 gives the issue and cause the trigger ignoring the date? I don’t recall if I experience the rule triggered on past date/time before. What if I reset always to 2000-01-01T00:00:00 do you know if it will work?

Best regards

As far as I remember yes. However, I think when you reload a rule, if the Item’s state is in the past it might trigger immediately too. That would be consistent with how system runlevel triggers work. But I don’t use this trigger much and don’t use .rules files at all so I can’t be sure without explicitly testing it.

There is one guaranteed way to find out.

I do know if you set it to 3000-01-01T00:00:00 it will work in all the cases you’ve outlined so far.

1 Like

Makes sense I will try this approach then.

Setting it to the past e.g year 2000 works too. Anything as long as it’s not 1970-01-01

2 Likes

I suspect it has something to do with Java Date/Calendar types - as far as I know the Time object is same as Date with 1970-01-01 (as it always counts from that particular date). So somewhere in OH code it treats Date/Calendar with 1970-01-01 as Time even though it has the date part.

There’s no “suspect” or “guessing”. It’s in the source code and we know exactly what it does, and it’s there as explained above, because it’s how it was done to have “Time only” trigger, prior to the addition of timeOnly parameter. It is now still there for compatibility reasons.

https://github.com/openhab/openhab-core/blob/fd53c4cb1d772c8086e7f4651f19db20bfcadfe6/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/DateTimeTriggerHandler.java#L180

The discussion is whether this should be removed now that we have timeOnly and perhaps it should be, but that is definitely up for discussion, because openHAB in general values stability and tries to avoid breaking changes unless necessary.

Maybe OH5 is when this should go.

1 Like

Hi @jimtng :

I see, sorry I wasn’t aware that date is hard-coded there, thanks a lot for showing the code.
My other question is: when OH is restarted does it only trigger for future timestamps? For example is OH is restarted on 2025-02-20T12:00:00, will the rules engine trigger a rule based on timestamp 2025-02-20T11:59:59? I ask because what @rlkoshak previously wrote possibly past timestamp may cause the rule to be triggered.

It won’t trigger on past timestamps - with the exception of 1970-01-01 of course.

1 Like

Thanks !