# SwitchTimeS

## `SwitchTimeS` (FB)

FUNCTION\_BLOCK SwitchTimeS

### Short description

> Switch clock with 5 adjustable time periods and binary output.\
> Each time period is defined by an on-time / off-time and a date.

### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-8e9b25951ebbfd7f18f5ba5857cec1591c4e886c%2FSwitchTimeS_FB.png?alt=media" alt=""><figcaption></figcaption></figure>

### Interfaces

#### Inputs

| Name  | Data type | Value range | Initial value | Function     |
| ----- | --------- | ----------- | ------------- | ------------ |
| *xEn* | BOOL      |             |               | Enable input |

#### Outputs

| Name               | Data type | Value range | Initial value | Function                                                   |
| ------------------ | --------- | ----------- | ------------- | ---------------------------------------------------------- |
| *xActive*          | BOOL      |             |               | Display of active time periods                             |
| *todActivatedFrom* | TOD       |             |               | On time of the last active time period of the current day  |
| *todActivatedTo*   | TOD       |             |               | Off time of the last active time period of the current day |

#### Setpoints / Parameters

| Name                 | Data type | Value range | Initial value   | Function                       |
| -------------------- | --------- | ----------- | --------------- | ------------------------------ |
| **datCH1\_Date**     | DATE      |             | DATE#2022-01-01 | Date of time period 1          |
| **todCH1\_TimeFrom** | TOD       |             | TOD#07:00       | On time of time period 1       |
| **todCH1\_TimeTo**   | TOD       |             | TOD#12:00       | Off time of time period 1      |
| **xCH1\_Mode**       | BOOL      |             | TRUE            | Display mode for time period 1 |
| **sCH1\_Notice**     | STRING    |             | ‘Notice’        | Text for time period 1         |
| **datCH2\_Date**     | DATE      |             | DATE#2022-01-01 | Date of time period 2          |
| **todCH2\_TimeFrom** | TOD       |             | TOD#07:00       | On time of time period 2       |
| **todCH2\_TimeTo**   | TOD       |             | TOD#12:00       | Off time of time period 2      |
| **xCH2\_Mode**       | BOOL      |             | TRUE            | Display mode for time period 2 |
| **sCH2\_Notice**     | STRING    |             | ‘Notice’        | Text for time period 2         |
| **datCH3\_Date**     | DATE      |             | DATE#2022-01-01 | Date of time period 3          |
| **todCH3\_TimeFrom** | TOD       |             | TOD#07:00       | On time of time period 3       |
| **todCH3\_TimeTo**   | TOD       |             | TOD#12:00       | Off time of time period 3      |
| **xCH3\_Mode**       | BOOL      |             | TRUE            | Display mode for time period 3 |
| **sCH3\_Notice**     | STRING    |             | ‘Notice’        | Text for time period 3         |
| **datCH4\_Date**     | DATE      |             | DATE#2022-01-01 | Date of time period 4          |
| **todCH4\_TimeFrom** | TOD       |             | TOD#07:00       | On time of time period 4       |
| **todCH4\_TimeTo**   | TOD       |             | TOD#12:00       | Off time of time period 4      |
| **xCH4\_Mode**       | BOOL      |             | TRUE            | Display mode for time period 4 |
| **sCH4\_Notice**     | STRING    |             | ‘Notice’        | Text for time period 4         |
| **datCH5\_Date**     | DATE      |             | DATE#2022-01-01 | Date of time period 5          |
| **todCH5\_TimeFrom** | TOD       |             | TOD#07:00       | On time of time period 5       |
| **todCH5\_TimeTo**   | TOD       |             | TOD#12:00       | Off time of time period 5      |
| **xCH5\_Mode**       | BOOL      |             | TRUE            | Display mode for time period 5 |
| **sCH5\_Notice**     | STRING    |             | ‘Notice’        | Text for time period 5         |

### Function description

#### General

The current time (date / time) is continuously compared with the 5 defined time periods.\
The display output *xActive* assumes the state TRUE if, with the enable input active (*xEn* = TRUE) at least one of the 5 time periods is active.

> **Prerequisite for using the function block SwitchTimeS**
>
> For correct operation, the use of the function block TimeRead2 is required.

#### Enable input *xEn*

| *xEn* | *xActive*                             | *todActivatedFrom*                                        | *todActivatedTo*                                           | Note        |
| ----- | ------------------------------------- | --------------------------------------------------------- | ---------------------------------------------------------- | ----------- |
| FALSE | FALSE                                 | unchanged                                                 | unchanged                                                  | FB disabled |
| TRUE  | State dependent on the 5 time periods | On time of the last active time period of the current day | Off time of the last active time period of the current day | FB enabled  |

#### Display output *xActive*

The display output assumes the state TRUE if, with the enable input active (*xEn* = TRUE) at least one of the 5 time periods is active.

| *xActive* | *xEn* | Time period 1 | Time period 2 | Time period 3 | Time period 4 | Time period 5 | Note                            |
| --------- | ----- | ------------- | ------------- | ------------- | ------------- | ------------- | ------------------------------- |
| FALSE     | FALSE | X             | X             | X             | X             | X             | FB disabled                     |
| FALSE     | TRUE  | FALSE         | FALSE         | FALSE         | FALSE         | FALSE         | No time period active           |
| TRUE      | TRUE  | FALSE         | FALSE         | TRUE          | FALSE         | FALSE         | At least one time period active |

#### On time of the last active time period of the current day *todActivatedFrom*

This display output assumes the value of the on-time of the last active time period if, with the enable input active (*xEn* = TRUE) the date of the current time matches the date of the time period.\
In all other situations it is not changed.

#### Off time of the last active time period of the current day *todActivatedTo*

This display output assumes the value of the off-time of the last active time period if, with the enable input active (*xEn* = TRUE) the date of the current time matches the date of time period 5.\
In all other situations it is not changed.

#### Time periods 1 - 5 (X = 1 .. 5)

Each time period is defined by adjustable data (on-time **todCHX\_TimeFrom**, off-time **todCHX\_TimeTo** and date **datCHX\_Date**) defined\
In addition, an operating mode (**xCHX\_Mode**) as well as a descriptive text (**sCHX\_Notice**) can be set.\
If the off-time is before the on-time, then for the check the off-time is set to the value of the on-time.\
A time period is active if the current date matches the date of the time period and the time is within the time period (**xCHX\_Mode** = TRUE).\
A time period is active if the current date matches the date of the time period and the time is outside the time period (**xCHX\_Mode** = FALSE).

### Visualization

#### Representation

<figure><img src="https://2592874069-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FQR4vCFzt6ixgsqlR3pdR%2Fuploads%2Fgit-blob-fe2a5f9d2d2f49634f47d1073a1bdf1e49cd02bc%2FSwitchTimeS.PNG?alt=media" alt=""><figcaption></figcaption></figure>

#### Interfaces Visu element

| Name                | Data type   | Type         | Initial value | Function                                                                                                                                                                                                                                                                                                              |
| ------------------- | ----------- | ------------ | ------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **FB\_SwitchTimeS** | SwitchTimeS | VAR\_IN\_OUT |               | Enter FB SwitchTimeS here e.g. PRG.SwitchTimeS                                                                                                                                                                                                                                                                        |
| **BMS\_Active**     | BOOL        | VAR\_INPUT   |               | BMS (Building Management System) GLT (building management technology). If BMS\_Active = TRUE the input / editing of the clocks is disabled because they can then only be set via the BMS. Times can then only be viewed.                                                                                              |
| **DisableInput**    | BOOL        | VAR\_INPUT   |               | DisableInput = TRUE clock times of the weekly clocks can only be viewed and not edited./// - BMS (Building Management System) GLT (building management technology). If BMS\_Active = TRUE the input / editing of the clocks is disabled because they can then only be set via the BMS. Times can then only be viewed. |

\
Note: VAR\_IN\_OUT interfaces must be assigned, VAR\_INPUT are optional.

### CODESYS

InOut:

| Scope       | Name               | Type     | Initial            |
| ----------- | ------------------ | -------- | ------------------ |
| Input       | `xEn`              | `BOOL`   |                    |
| Input Const | `datCH1_Date`      | `DATE`   | DATE#2022-1-1      |
| Input Const | `todCH1_TimeFrom`  | `TOD`    | TIME\_OF\_DAY#7:0  |
| Input Const | `todCH1_TimeTo`    | `TOD`    | TIME\_OF\_DAY#12:0 |
| Input Const | `xCH1_Mode`        | `BOOL`   | TRUE               |
| Input Const | `sCH1_Notice`      | `STRING` | ‘Notice’           |
| Input Const | `datCH2_Date`      | `DATE`   | DATE#2022-1-1      |
| Input Const | `todCH2_TimeFrom`  | `TOD`    | TIME\_OF\_DAY#7:0  |
| Input Const | `todCH2_TimeTo`    | `TOD`    | TIME\_OF\_DAY#12:0 |
| Input Const | `xCH2_Mode`        | `BOOL`   | TRUE               |
| Input Const | `sCH2_Notice`      | `STRING` | ‘Notice’           |
| Input Const | `datCH3_Date`      | `DATE`   | DATE#2022-1-1      |
| Input Const | `todCH3_TimeFrom`  | `TOD`    | TIME\_OF\_DAY#7:0  |
| Input Const | `todCH3_TimeTo`    | `TOD`    | TIME\_OF\_DAY#12:0 |
| Input Const | `xCH3_Mode`        | `BOOL`   | TRUE               |
| Input Const | `sCH3_Notice`      | `STRING` | ‘Notice’           |
| Input Const | `datCH4_Date`      | `DATE`   | DATE#2022-1-1      |
| Input Const | `todCH4_TimeFrom`  | `TOD`    | TIME\_OF\_DAY#7:0  |
| Input Const | `todCH4_TimeTo`    | `TOD`    | TIME\_OF\_DAY#12:0 |
| Input Const | `xCH4_Mode`        | `BOOL`   | TRUE               |
| Input Const | `sCH4_Notice`      | `STRING` | ‘Notice’           |
| Input Const | `datCH5_Date`      | `DATE`   | DATE#2022-1-1      |
| Input Const | `todCH5_TimeFrom`  | `TOD`    | TIME\_OF\_DAY#7:0  |
| Input Const | `todCH5_TimeTo`    | `TOD`    | TIME\_OF\_DAY#12:0 |
| Input Const | `xCH5_Mode`        | `BOOL`   | TRUE               |
| Input Const | `sCH5_Notice`      | `STRING` | ‘Notice’           |
| Output      | `xActive`          | `BOOL`   |                    |
| Output      | `todActivatedFrom` | `TOD`    |                    |
| Output      | `todActivatedTo`   | `TOD`    |                    |
