Condition: time never works without weekday

I just discovered after debugging an automation, that this yaml doesn’t work. When you specify a before or after time you must also specify weekdays. This is contrary to logical expectations. If before isn’t specified, it isn’t applicable, if after isn’t specified it isn’t applicate, weekdays should work the same, if not specified then it should not be applicable. This is a bug or a feature request. Weekday restriction should not apply if no weekdays are specified. I’d file a bug report, but I don’t know if this is in Core, OS, FE or where.

  • condition: time
    after: ‘12:00:00’

I used the Automation Editor to create the following automation:

alias: "Time Condition Test "
description: ""
  - platform: state
      - input_boolean.test
    to: "on"
  - condition: time
    after: "09:00:00"
  - service: notify.persistent_notification
      message: Hello World!
mode: single

It contains a Time Condition without specifying any days.

At 9:38, I turned on the input_boolean and it produced a notification.

In other words, I wasn’t able to reproduce the problem you reported.


Like @123, I cannot reproduce this behavior…

Home Assistant 2023.2.4
Supervisor 2023.01.1
Operating System 9.5

Hmmm, maybe it doesn’t happen in every context. I’ll try to reproduce the problem and I’ll post the entire automation.

Well, now I can’t reproduce the problem either. It seems to work fine. I had a trace where none of the Choose options were chosen but testing the conditions one of them should have been true. But apparently I was mistaken somewhere along the way in debugging the trace.

You could get this kind of problem with an empty weekday, which you can get out of the UI sometimes:

- condition: time
  before: "02:00:00"

That’ll never match, because the weekday is never blank.

1 Like

Perhaps that is what happened. I’ll have to grab automations.yaml from yesterday’s backup and see if that’s what was in there.

Yup, that was it. This is what was in automations.yaml from yesterday’s backup.
An empty weekday: list. Sounds like a UI bug to me :slight_smile:

  - choose:
    - conditions:
      - condition: state
        entity_id: alarm_control_panel.home_alarm
        state: disarmed
      - condition: or
        - condition: time
          after: '21:45:00'
          weekday: []
        - condition: time
          before: 06:30:00
          weekday: []
      - condition: or
        - condition: trigger
          id: No_hall_motion_for_half_hour
        - condition: trigger
          id: Late_Evening_Time
1 Like

How did you get an empty weekday option?

I’ve had this problem but I’m not sure how to reproduce it.

In the visual editor, if you check one (or more?) of the weekday boxes (ie: saturday), then uncheck them all, the yaml will be:

  weekday: []

It looks fine in the visual editor, but it no longer works. You can’t detect the difference from the visual editor, you have to look at the resulting yaml.

Note: this is already a known bug and was fixed two weeks ago. I’m just a couple updates behind so I don’t have the fix installed yet.