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