Reversibly photo-switchable proteins are essential for many super-resolution fluorescence microscopic and optoacoustic imaging methods. However, they have yet to be used as sensors that measure the distribution of specific analytes at the nanoscale or in the tissues of live animals. Here we constructed the prototype of a photo-switchable Ca2+ sensor based on GCaMP5G that can be switched with 405/488-nm light and describe its molecular mechanisms at the structural level, including the importance of the interaction of the core barrel structure of the fluorescent protein with the Ca2+ receptor moiety. We demonstrate super-resolution imaging of Ca2+ concentration in cultured cells and optoacoustic Ca2+ imaging in implanted tumor cells in mice under controlled Ca2+ conditions. Finally, we show the generalizability of the concept by constructing examples of photo-switching maltose and dopamine sensors based on periplasmatic binding protein and G-protein-coupled receptor-based sensors.Calcium and other analytes can be imaged at super-resolution and in vivo with photo-switchable sensors.