Public sentiments affecting health outcomes are increasingly modulated by social media. Existing literature mainly focus on investigating how network structure affects the contagion of health sentiments. However, most of these studies neglect that the interaction topology change in time. In fact, the change of inter-individual connections over time is associated with individual attributes. The mechanism through which individual attributes reshapes the connection topology is mainly governed by the competition between two principles, i.e., homophily (establishing or reinforcing social connections) and homeostasis (preserving the total strength of social connections to each individual). No existing approaches are yet able to accommodate these two competing effects at the same time. We thus propose a new statistical model (H2 model, Homophily and Homestasis model) to depict the evolution of temporal network, which is governed by the competition of homophily and homeostasis. In addition, we consider the mediation effect of external shock events, which enables us to separate exogenous confounding factors. Evaluation on Twitter data suggests that H2 model can capture long-range sentiment dynamics and external shock events. In sentiment prediction, H2 consistently outperforms existing methods in terms of error rate. Through the model's shock tensor, we successfully detect several typical events, and reveal that users in negative emotions are more influenced by external shock events than those with positive emotions. Our findings have practical significance for those who supervise and guide health sentiments in online communities.