User requirements are the fundamental driving force of smart services in Internet of Things (IoT). Today, many IoT frameworks such as IFTTT allow end users to use simple Trigger-Action Programming (TAP) rules for programming. However, these rules describe device scheduling instructions instead of user service requirements. Some IoT systems propose goal-oriented requirement approaches to support service goal decomposition. Nevertheless, it is difficult to ensure the consistency of different services and completeness of service deployment. To achieve correct "user programming" in IoT systems and ensure the consistency and completeness of user service requirements, this study proposes an environment modeling-based approach to automatically generate TAP rules. On the basis of the service requirements provided by users, required system behaviors are automatically extracted according to the environment model. After their consistency and completeness are checked, TAP rules are generated, which realizes automatic generation from user service requirements to device scheduling instructions. The environment ontology of IoT application scenarios is constructed for environment modeling, and the description method of service requirements based on the environment ontology is also defined. Finally, the accuracy, efficiency, performance of the approach, and the time cost for building the environment ontology are evaluated with a smart home scenario. The results show that the accuracy, efficiency, and performance of this approach exceed the available threshold, and the time cost in building the environment ontology can be ignored when the number of requirements reaches a certain level.