As smart home environment gets more and more diverse with newly evolved devices and applications, instead of programming each household, there is a need for a knowledge-based framework to facilitate the automatic composition of appropriate services. The framework should address the issues of finding suitable devices automatically, composing feasible plans, and making the composed plans executable. In this paper, we propose a way to compose the executable plans for the smart home devices based on ontology-base process models. A code generator and an execution environment are then discussed. The generated code can be deployed and scheduled in the execution environment. It can also query the ontology and dynamically find any possible replacements from registered devices at runtime. To demonstrate the framework, an experiment with a simple application is included in the paper.