With the development of smart devices and information technology, it is possible for users to optimize their usage of electrical equipment through the home energy management system (HEMS). To solve the problems of daily optimal scheduling and emergency demand response (DR) in an uncertain environment, this paper provides an opportunity constraint programming model for the random variables contained in the constraint conditions. Considering the probability distribution of the random variables, a home energy management method for DR based on chance-constrained programming is proposed. Different confidence levels are set to reflect the influence mechanism of random variables on constraint conditions. An improved particle swarm optimization algorithm is used to solve the problem. Finally, the demand response characteristics in daily and emergency situations are analyzed by simulation examples, and the effectiveness of the method is verified.