Motion sensor light automation

I am new to HA!

I have 2 automation setup for my Office Light with Motion sensor.

  1. When Motion is triggered between Sunset and Sunrise the office light with turn ON
  2. When there is no motion detected for 2 mins the office light turn off.

The 1st automation works fine, But the 2nd once work for few times and then it stops working.

Below is my YAML.

- id: '1640540681367'
  alias: Turn On Office Light When motion is detected
  description: Turn On Office Light When motion is detected
  trigger:
  - type: motion
    platform: device
    device_id: 49f4538e5e5a72d12b1aea8666e80c19
    entity_id: binary_sensor.office_pir_sensor
    domain: binary_sensor
  condition:
  - condition: sun
    before: sunrise
    after_offset: 00:30:00
    before_offset: 00:30:00
    after: sunset
  - condition: device
    type: is_on
    device_id: d167066c832382fce1e24a82559140e7
    entity_id: light.office_light
    domain: light
  action:
  - type: turn_on
    device_id: d167066c832382fce1e24a82559140e7
    entity_id: light.office_light
    domain: light
    brightness_pct: 100
  mode: single
- id: '1641060316552'
  alias: Turn off office light when motion is not detected
  description: Turn off office light when motion is not detected
  trigger:
  - type: no_motion
    platform: device
    device_id: 49f4538e5e5a72d12b1aea8666e80c19
    entity_id: binary_sensor.office_pir_sensor
    domain: binary_sensor
    for:
      hours: 0
      minutes: 2
      seconds: 0
  condition: []
  action:
  - type: turn_off
    device_id: d167066c832382fce1e24a82559140e7
    entity_id: light.office_light
    domain: light
  mode: single

Appreciate if you guys can help me to figure what is wrong.

Thank You

The condition is to not have the light turn off when the vacuum is running. I tend to use state and service the most as it makes the most sense to me. It is also cleaner.

  alias: Study Lights Off via Motion
  description: Control Study Lights with Shelly Motion Detection
  trigger:
  - platform: state
    entity_id: binary_sensor.shellymotionsensor_motion
    to: 'off'
    for:
      hours: 0
      minutes: 3
      seconds: 0
      milliseconds: 0
  condition:
  - condition: state
    entity_id: input_boolean.vacuum
    state: 'off'
  action:
  - service: light.turn_off
    target:
      entity_id: light.study_cans_current_value
  mode: single