> For the complete documentation index, see [llms.txt](https://support.powerio.com/hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/general/changestateupdown.md).

# ChangeStateUpDown

## `ChangeStateUpDown` (FB)

FUNCTION\_BLOCK ChangeStateUpDown

### Short description

> Switching between freely definable states (UP and DOWN button)\
> Prerequisite: Connection of a suitable array to the input 'arStates' with elements of type 'stChangeStateUpDown'\
> Typical application: Switching operating modes

### Representation

<figure><img src="/files/366be8afb097e37f2319d37687d2bf5fe683e99f" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name         | Data type           | Value range | Initial value | Function                                         |
| ------------ | ------------------- | ----------- | ------------- | ------------------------------------------------ |
| *xStateUp*   | BOOL                |             | FALSE         | Switch to the next higher state (rising edge)    |
| *xStateDown* | BOOL                |             | FALSE         | Switch to the next lower state (rising edge)     |
| *xResInit*   | BOOL                |             | FALSE         | Switch to the initialization state (rising edge) |
| *bInitState* | BYTE                |             | 0             | Index of the initialization state                |
| arStates     | stChangeStateUpDown |             |               | Array with the individual states                 |

#### Outputs

| Name          | Data type | Value range | Initial value | Function                    |
| ------------- | --------- | ----------- | ------------- | --------------------------- |
| sStateName    | STRING    |             |               | Name of the current state   |
| iStateNumber’ | INT       |             |               | Number of the current state |

### Function description

\
This FB is used to switch between freely definable states (each state is defined by a state text and a state number) via the inputs 'xStateUp' and 'xStateDown'.\
After the first download, a subsequent download, every online change and at every rising edge on the 'xResInit' input, the initial state is set. The index of the initial state is defined by the input 'bInitState'.

{% hint style="info" %}
In case of error, the string 'Error' is output at the 'sStateName' output and the value -1 is output at the 'iStateNumber' output.
{% endhint %}

#### This function block can be applied as follows:

This function block can be applied as follows:

<figure><img src="/files/cedd049689f55dae3ba0ba151b093ddbdff39745" alt=""><figcaption></figcaption></figure>

### CODESYS

InOut:

| Scope  | Name           | Type                           | Initial |
| ------ | -------------- | ------------------------------ | ------- |
| Input  | `xStateUp`     | `BOOL`                         | FALSE   |
| Input  | `xStateDown`   | `BOOL`                         | FALSE   |
| Input  | `xStateInit`   | `BOOL`                         | FALSE   |
| Input  | `bInitState`   | `BYTE`                         | 0       |
| Output | `sStateName`   | `STRING`                       |         |
| Output | `iStateNumber` | `INT`                          |         |
| Input  | `arStates`     | POINTER TO stChangeStateUpDown |         |


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://support.powerio.com/hub/codesys-hvac/en/hvac-library/functionblocks/general/changestateupdown.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
