Automation with time comparison behaving differently than expected

Hi,

I have one automation that behaves very strangely in my opinion and I cannot really understand why.

In the first step I want to compare the current time against a input_datetime. It should trig if the current time is before the input_datetime. However, it seem to not follow the pattern I expect. When the automation runs, the input_datetime is approx 13 h before the current time, but the automation any way consider the opposite. What am I doing wrong?

The time condition passed. What are the other conditions (in the choose action) after that?

It looks like no choose option was matched and there is no default action.

Hi,

Yes, the time condition passed, but I would expect it to not pass? Or am I thinking incorrectly here?

My thought is that the condition is “if time is before X”. That is time < X. Meaning now (2024-11-09 09:11:00) < 2024-11-08 19:43:52. In my opinion the current datetime should be larger than (not smaller than) the previous? Or is the “time before” actually only comparing the time component, not datetime?

Your condition passes if the time now (9am) is before the input_datetime (7:45pm) which it was.

Thank you for the answer. This explains it fully - I made a too strong assumption that it compares both time+date and not just time. I couldn’t find any premade function similar to the time trigger but with datetime consideration instead of just time. I handled it now in a template within the automation, but it decreases the readibility.

I have another issue in the same automation. I have few conditions similar to the following:

  • conditions:
    - condition: template
    value_template: >-
    {{
    states(‘input_number.utebelysningsscen_forcering’)|int(default=99)
    == 4 }}

At some points, but not always, when I have edited the automation and save it, it changes |int(default=99) to |int(default(99)). Afterwards, the automation fails due to incorrect syntax. What could cause that?

That is not an incorrect assumption for time triggers

https://www.home-assistant.io/docs/automation/trigger/#input-datetime

However for time conditions it is just the time,
https://www.home-assistant.io/docs/scripts/conditions/#time-condition

Try just |int(99) it means the same thing.