In this work, the process of developing a flexible and semantic middleware (SeMiWa) for cyber-physical systems is presented. The proposed system focus the challenge of controllability in a heterogeneous wireless infrastructure of a smart home environment. With the semantic and model-based approach, it is possible to react on this rapidly changing environment and therefore, assist the user seamless integrate its devices, e.g. new sensors. To solve the problem of interoperability, we use semantic annotated XMPP messages as transmission format, a semantic annotator for unifying all heterogeneous sensor data and a semantic query language for handling later registered or removed devices without changing ongoing processes. We evaluate our solution with a test installation by using the requirements for middleware-based cyber-physical systems.