Automation for auto-switch off lights when turned on accidentally

Hi,
I wanted to create an automation to turn off light when it is turned on accidentally.

Let me explain better. I have a motion sensor in the bathroom. Sometimes I can turn on the bathroom light using the switch but I don’t enter on the bathroom.

I have an automation to turn on and off the lights using the motion sensor.
If motion is detected → turn on.
If no motion detected for 10minutes (it’s a bathroom, I have set a long time because it is a motion sensor). → turn off.

In the case of turning on the light and I don’t enter on the bathroom no state change of the motion sensor and the light don’t turn off.

I have try to do it in this way. It works but sometimes the light is turned off when i’m in…
I have used the shelly Input to launch when swith is pressed. Then I check if the swith turned on the light (it can be turned off with the swith) and then wait for motion sensor state. But … I think that platform: state is for use when state change. If I don’t enter on the bathroom the statw won’t change.

alias: Luz - Auto Off
trigger:
  - platform: state
    entity_id:
      - event.shelly_dimmerpro_input_3
condition: []
action:
  - wait_for_trigger:
      - platform: state
        entity_id:
          - light.group_bathroom
        to: "on"
    timeout:
      hours: 0
      minutes: 0
      seconds: 2
      milliseconds: 0
    continue_on_timeout: false
  - wait_for_trigger:
      - platform: state
        entity_id:
          - binary_sensor.aqarasensor_bathroom_mov_occupancy
        for:
          hours: 0
          minutes: 2
          seconds: 0
    timeout:
      hours: 0
      minutes: 2
      seconds: 30
      milliseconds: 0
    continue_on_timeout: false
  - service: light.turn_off
    metadata: {}
    data: {}
    target:
      entity_id: light.group_bathroom
mode: restart

With regards,