Automation not checking state of input_boolean

I have a light switch in my office that I’m using as a “master switch” to control a few desk lamps. When the master switch turns on, the desk lamps turn on… same for off. I do this with an automation that checks the state of the master switch, and when the state changes from off to on, a scene is activated that sets the desk lamps to the proper levels.

However, sometimes at night I like to dim the lights in the office. I have a scene that sets the main lights to 50%, and the desk lights to 50%. However the above automation detects the master switch state change from off to on, and triggers the lights at full brightness. Only if I execute the scene a second time (with the master switch already “on”) do the brightness levels get set correctly as it bypasses the automation.

To get around this, I was thinking of creating an input_boolean variable that temporarily deactivates the automation. So for example, the automation only runs if the input_boolean.protected_office is set to off. When I trigger the dimming scene, I have a script that sets protected_office to ON and then sets it to off after the script is finished. My thinking was this could disable the automation.

automations.yaml

 - alias: Office Lights On
  trigger:
    platform: state
    entity_id: light.office_main_lights
    from: 'off'
    to: 'on'
  condition:
    condition: and
    conditions:        
      - condition: state
        entity_id: input_boolean.protected_office
        state: 'off'
      - condition: time 
        after: '06:00:00'
        before: '19:00:00'
  action:
    service: scene.turn_on
    entity_id: scene.office_work

scripts.yaml

office_relaxation:
  alias: "Office Relaxation"
  sequence:
    - service: input_boolean.turn_on
      data:
        entity_id: input_boolean.protected_office
    - service: scene.turn_on
      entity_id: scene.office_relaxation
    - service: input_boolean.turn_off
      data:
        entity_id: input_boolean.protected_office

scenes.yaml

- name: Office Relaxation
  entities:
    light.office_main_lights:
      state: true
      brightness_pct: 40
      transition: 60
    light.office_desk_adam:
      state: true
      transition: 5
      brightness_pct: 40
    light.office_desk_daniela:
      state: true
      transition: 5
      brightness_pct: 40

- name: Office Work
  entities:
    light.office_main_lights:
      state: true
      brightness_pct: 100
    light.office_desk_adam:
      state: true
      brightness_pct: 100
    light.office_desk_daniela:
      state: true
      brightness_pct: 100

However this doesn’t work. The input_boolean variable is ignored by the automation. Any idea what could be going on?

Thanks in advance.

Try it like this (conditions are AND by default):

  condition:
    - condition: state
      entity_id: input_boolean.protected_office
      state: 'off'
    - condition: time 
      after: '06:00:00'

I had this originally, it’s the same thing. It’s as if the automation is checking the state of protected_office before the script is turning it on.

Try:

office_relaxation:
  alias: "Office Relaxation"
  sequence:
    - service: input_boolean.turn_on
      entity_id: input_boolean.protected_office
    - service: scene.turn_on
      entity_id: scene.office_relaxation  # HA does not wait for this scene to finish setting up before preceding
    - delay: '00:00:05'   # so wait a bit before turning off the input boolean.
    - service: input_boolean.turn_off
      entity_id: input_boolean.protected_office

That works perfectly. Thanks @tom_l