automation:
  - alias: Lighting · Kitchen · Motion on
    trigger:
      platform: state
      entity_id: binary_sensor.kitchen_motion_occupancy
      to: "on"
    condition:
      condition: state
      entity_id: binary_sensor.someone_home
      state: "on"
    action:
      - choose:
        # Turn on in Day Mode
        - conditions:
            - condition: state
              entity_id: sensor.house_mode
              state: 'day'
          sequence:
            - service: light.turn_on
              entity_id: light.browser_kitchen
              data:
                brightness_pct: 100
            - or:
                - or:
                  - condition: sun
                    after: sunset
                    after_offset: "-01:00:00"
                  - condition: sun
                    before: sunrise
                # - condition: numeric_state
                #   entity_id: sensor.dark_sky_cloud_coverage
                #   above: 80
            - service: light.turn_on
              entity_id: light.kitchen
              data:
                brightness_pct: 100
        # Turn on in Night Mode
        default:
          - service: light.turn_on
            entity_id:
              - light.hue_ambiance_6
              - light.hue_ambiance_1
            data:
              brightness_pct: 1
          - service: script.browser_kitchen_low

  - alias: Lighting · Kitchen · Night · Motion off
    trigger:
      platform: state
      entity_id: binary_sensor.kitchen_motion_occupancy
      to: "off"
      for:
        minutes: 5
    condition:
      condition: not
      conditions:
        - condition: state
          entity_id: sensor.house_mode
          state: 'day'
    action:
      # Turn off in Night Mode
      - service: light.turn_on
        entity_id:
          - light.hue_ambiance_6
          - light.hue_ambiance_1
        data:
          brightness_pct: 100
      - service: light.turn_off
        entity_id:
          - light.hue_ambiance_6
          - light.hue_ambiance_1
          - light.kitchen_main
          - light.kitchen_secondary
      - service: script.browser_kitchen_low

  - alias: Lighting · Kitchen · Day · Motion off
    trigger:
      platform: state
      entity_id: binary_sensor.kitchen_motion_occupancy
      to: "off"
      for:
        minutes: 15
    condition:
      condition: state
      entity_id: sensor.house_mode
      state: 'day'
    action:
      # Turn off in Day Mode
      - service: light.turn_off
        entity_id: light.kitchen
      - service: script.browser_kitchen_low
