  2D materials with broken inversion symmetry posses an extra degree of
freedom, the valley pseudospin, that labels in which of the two
energy-degenerate crystal momenta, K or K', the conducting carriers are
located. It has been shown that shining circularly-polarized light allows to
achieve close to $100\%$ of valley polarization, opening the way to
valley-based transistors. Yet, switching of the valley polarization is still a
key challenge for the practical implementation of such devices due to the short
coherence lifetimes. Recent progress in ultrashort laser technology now allows
to produce trains of attosecond pulses with controlled phase and polarization
between the pulses. Taking advantage of such technology, we introduce a
coherent control protocol to turn on, off and switch the valley polarization at
faster timescales than electronic and valley decoherence, that is, an ultrafast
optical valley switch. We theoretically demonstrate the protocol for hBN and
MoS$_2$ monolayers calculated from first principles. Additionally, using two
time-delayed linearly-polarized pulses with perpendicular polarization, we show
that we can extract the electronic dephasing time $T_2$ from the valley Hall
conductivity.
