Electrical stimulation is currently the gold standard treatment for heart rhythm disorders. However, electrical pacing is associated with technical limitations and unavoidable potential complications. Recent developments now enable the stimulation of mammalian cells with light using a novel technology known as optogenetics. The optical stimulation of genetically engineered cells has significantly changed our understanding of electrically excitable tissues, paving the way towards controlling heart rhythm disorders by means of photostimulation. Controlling these disorders, in turn, restores coordinated force generation to avoid sudden cardiac death. Here, we report a novel continuum framework for the photoelectrochemistry of living systems that allows us to decipher the mechanisms by which this technology regulates the electrical and mechanical function of the heart. Using a modular multiscale approach, we introduce a non-selective cation channel, channelrhodopsin-2, into a conventional cardiac muscle cell model via an additional photocurrent governed by a light-sensitive gating variable. Upon optical stimulation, this channel opens and allows sodium ions to enter the cell, inducing electrical activation. In side-by-side comparisons with conventional heart muscle cells, we show that photostimulation directly increases the sodium concentration, which indirectly decreases the potassium concentration in the cell, while all other characteristics of the cell remain virtually unchanged. We integrate our model cells into a continuum model for excitable tissue using a nonlinear parabolic second order partial differential equation, which we discretize in time using finite differences and in space using finite elements. To illustrate the potential of this computational model, we virtually inject our photosensitive cells into different locations of a human heart, and explore its activation sequences upon photostimulation. Our computational optogenetics tool box allows us to virtually probe landscapes of process parameters, and to identify optimal photostimulation sequences with the goal to pace human hearts with light and, ultimately, to restore mechanical function.