###### Abstract  
The research described in this article aims to propose the creation of a framework that would enable the self-optimization of IoT device networks. The work is based on two foundations: distributed graph transformations and a flexible IoT network supported by the several standards and definitions proposed by The Open Group, such as the definition of microservices architecture (MSA) as well as IoT and semantic interoperability standards, providing a broader context for the research. It introduces the concept of capabilities, both at the individual device and network levels, which are used to describe the desired functions that will be performed by the given system. The network of distributed IoT devices is visualized as a graph, and graph transformations are used to specify and optimize the network in response to events like degraded performance, failures, or configuration changes. These actions are automatically performed in order to restore the original set of capabilities defined for the system. Validation of these capabilities is used to assess the success rate of the performed actions. The document describes a practical implementation of an IoT network for managing and monitoring an indoor greenhouse. Thanks to the introduction of formal representation of capabilities, the programming effort required to build the system was significantly reduced. Furthermore, automation related to the validation of capabilities and the performance of automated actions reduces the effort by a factor of a hundred compared with a manual action. IoT; graph transformations; sensors; smart agriculture 202313 132718 13271  
of the key aspects of such a distributed system is determining its intended functionality and verifying its fulfillment, especially when such systems are usually expanding dynamically. In Section 2.3, we propose an introduction to the concepts of local and global capabilities (i.e., the features that a managed distributed system must meet). Even if we implemented the concept of capabilities as sets of predicates built into the software source code, defined as logical conditions, the solution would prolong the system implementation process. Adding additional conditions and actions related to the reconfiguration of a distributed system in the application's code will further complicate the system and may make its architecture complex. Manual system configuration and verification of its correctness by a programmer also does not seem to be an effective solution. Fortunately, the network of IoT devices can be visualized as a graph, adhering to specific grammar and enabling features associated with graphs. In this paper, we demonstrate that microservice capabilities can be formalized through predicates associated with the subgraph structure (refer to Section 3). Therefore, instead of manually implementing capability verification and self-configuration actions, we can employ a system of graph transformation mechanisms for the entire system. This significantly enhances code readiness and reduces the effort required by programmers, particularly during the system maintenance phase. Graph transformations facilitates both the specification of current problems (as a graph of IoT devices) and, more importantly, the optimized approach to modifying such a network in response to various events, such as degraded performance of the connected devices. It is noteworthy that certain types of graph transformations, such as complementary graphs [1], can be practically implemented in distributed environments, providing formal mechanisms to transform between different states of graphs representing sets of complementary capabilities. The other applicable methods are the parallel graph transformations [2; 3], similarity and conformity graphs [4] or a framework for computational design synthesis based on the graph grammars [5] and hyper-graph models [6]. The main benefit of the introduced approach is that it costs less in terms of the programming effort regarding the maintenance of the system.