Finite-state machines, also known as state machines, or state diagrams, define the invariable states of a system. Documentation can be done in tabular or graphical format. Since the number of table rows increases significantly with the number of states, it is more concise to use the graphical approach. This article will demonstrate how state machines can be modeled.
Introduction

A state diagram always represents the states and their state transitions (see Figure 1). The graphical representation allows for immediate identification of deadlocks and isolated states. Deadlock occurs when a state can be entered but not exited. Isolated states cannot be reached at all. States are often represented by circles, and transitions by directed arrows. It is important to note that only one state can be active at a time. Furthermore, an initial state is always defined, which is assumed upon a reset.
State machines in UML / SysML
However, the state machines in UML and SysML are somewhat more complex than just described. Here, the semantics of the state machine are specified in such detail that the machines can be executed and used for automatic code generation. The concept of state machines in UML goes back to the computer scientist David Harel, who, among other things, combined the properties of the Mealy and Moore machines. Every system has states. Depending on the state, events trigger internal reactions and possibly state changes. Events can also be discarded if the state cannot interpret them. In UML and SysML, states are represented by rounded rectangles. The state name is inside the rectangle. UML also has three defined behaviors to further specialize a state. For example, the entry behavior (entry), the state behavior (do), and the exit behavior (exit) can be defined for each state. These behaviors are also stored within the rectangle. State transitions are also called transitions in modeling languages. A transition is a directed arrow between two states and defines the trigger, the condition for the transition, and a possible behavior. The notation is as follows:
Notation: TriggerA, TriggerB, ... [Condition] / Behavior Example: User[presses power button] / shut down()
The UML further recognizes five types of events that can lead to a transition. These include the call event, the change event, the signal event, the time event, and the any receive event. The time event can, in turn, be divided into relative and absolute time events.
The following table shows the elements mentioned above graphically and briefly describes them.
Images can be clicked to enlarge.
Example
If you don't want to use automatic code generation or state machine execution in specific programs, it's generally recommended to keep the state machine as simple as possible. The following is an example of a state machine for a fan:

Figure 2 shows the state machine of a very simple fan. It knows the states "off" and "on." The fan is turned on via a button. It either turns off automatically after two hours to save energy or can be turned off by the user. The fan remembers the user's selected intensity via a dial. It can choose between three intensity levels. The fan never leaves the state machine.
















