Setting condition for on-time

I want several on_time actions to run, but only if conditions are met. This is the code without conditions:

time:
  - platform: ds1307
  - platform: homeassistant
    on_time_sync:
      then:
        ds1307.write_time
    on_time:
    # every morning at 0400
    - seconds: 0
      minutes: 0
      hours: 4
      days_of_week: MON-SUN
      then:
        - climate.control:
            id: this_thermostat
            custom_preset: Day
    # every evening at 2100
    - seconds: 0
      minutes: 0
      hours: 21
      days_of_week: MON-SUN
      then:
        - climate.control:
            id: this_thermostat
            custom_preset: Night

The actions switch a thermostat between custom presets Day and Night. There’s a text sensor that returns the current preset:

text_sensor:
  - platform: template
    id: preset_sensor
    lambda: "return id(this_thermostat).custom_preset;"

I want the on_time jobs to run only if this sensor returns Day or Night. I tried this:

time:
  - platform: ds1307
  - platform: homeassistant
    on_time_sync:
      then:
        ds1307.write_time
    on_time:
      - if:
        condition:
          or:
            - lambda |-
                return id(preset_sensor) == "Night"
            - lambda |-
                return id(preset_sensor) == "Day"
        then:
            # every morning at 0400
            - seconds: 0
              minutes: 0
              hours: 4
              days_of_week: MON-SUN
              then:
                - climate.control:
                    id: this_thermostat
                    custom_preset: Day
            # every evening at 2100
            - seconds: 0
              minutes: 0
              hours: 21
              days_of_week: MON-SUN
              then:
                - climate.control:
                    id: this_thermostat
                    custom_preset: Night

but it won’t compile and I’m not sure the lambda format is correct. How should I place a condition within an on_time action? Thanks.