How to use physical buttons to control the fan's oscillation?

I modified an old fan.
It is still missing a vibration button.
Can anyone help me solve this problem?


binary_sensor:
  - platform: gpio
    pin:
      number: GPIO5
    name: "osc"
    filters:
      - delayed_on: 150ms
      - delayed_off: 150ms
    on_press:


fan:
  - platform: speed
    id: threespeedfan
    output: threespeedfan_1
    oscillation_output: relay4
    name: "Three Speed Fan"
    speed_count: 3