openhab-core
openhab-core copied to clipboard
Using 1970-01-01 in Date Item overwrites the Time-only flag of DateTime Triggers
Expected Behavior
When creating a DateTime Trigger for a rule whith time-only set to false, the rule should not trigger, if the DateTime Items contains a date in the past.
Current Behavior
If the rule contains "1970-01-01 00:00:00", the rule will trigger every 1am in the morning.
Possible Solution
I think, the problem is related to this line of code: https://github.com/openhab/openhab-core/blob/12f2314a2d1cbd3157bead4b6de9159bea37275d/bundles/org.openhab.core.automation/src/main/java/org/openhab/core/automation/internal/module/handler/DateTimeTriggerHandler.java#L180C21-L180C35
It assumes that the date 1970-01-01 means that the rule is time-only. In the edge-case of a user actually sending this date, this is unexpected behavior.
Steps to Reproduce (for Bugs)
A minimal rule to reproduce this looks like the following:
configuration: {}
triggers:
- id: "1"
configuration:
timeOnly: false
itemName: Alarmclock_Next_Schedule
offset: 60
type: timer.DateTimeTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: 'console.log("Debugging: Timestamp Rue has been triggered")'
type: script.ScriptAction
Check your logs and you will see that the rule triggered at 1am in the morning.
Context
When trying to implement an alarmclock-rule that is triggered by a datetime trigger, I stumbled over a behavior, where the time-only flag is not working as expected when using a DateTime trigger. As I could not find a way to reset DateTime-Items to UNDEF, I use 1970-01-01 to express, that no date is selected.
Your Environment
- Version used: 4.3
- Environment name and version (e.g. Chrome 111, Java 17, Node.js 18.15, ...): Docker Image
- Operating System and version (desktop or mobile, Windows 11, Raspbian Bullseye, ...): Debian
This was kind of by design. It's related to DateTimeType parsing a time-only string, the date part is set to 1970-01-01, and giving that to the datetime trigger means that you want a timeonly trigger. Perhaps it was done this way prior to the addition of timeOnly option, I haven't dug into that.
Need to think about whether there'd be any impact if we remove this. It would probably break some existing rules that relied on this specific behaviour.