Skip to content

Commit c6a6644

Browse files
authored
Add ifelse and bool2int (#1067)
1 parent 106e9cd commit c6a6644

3 files changed

Lines changed: 73 additions & 2 deletions

File tree

astro.config.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ export default defineConfig({
137137
link: "/heating",
138138
},
139139
{
140-
label: "User-defined",
141-
translations: { de: "Benutzerdefiniert" },
140+
label: "Plugins",
142141
link: "/plugins",
143142
},
144143
],

src/content/docs/de/plugins.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Zusätzlich können Plugins auch für die in [Messaging](/de/reference/configura
4141
- [Convert Plugin](#convert) - Meta-Plugin zur Datentyp-Konvertierung beim Schreiben (z. B. float zu int).
4242
- [Delta Plugin](#delta) - Meta-Plugin zur Umwandlung von absoluten Werten in Änderungswerte (Deltas) beim Schreiben.
4343
- [Ignore Plugin](#ignore) - Meta-Plugin zum Unterdrücken spezifischer Fehlermeldungen.
44+
- [IfElse Plugin](#ifelse) - Meta-Plugin für bedingte Schreibvorgänge mit zwei Zweigen (if/else).
4445
- [Map Plugin](#map) - Meta-Plugin zur Übersetzung von Integer-Werten (z. B. gerätespezifische Modi in evcc-Modi).
4546
- [Meter Plugin](#meter-plugin) - Plugin um ein anderes Messgerät als Datenquelle zu verwenden.
4647
- [Sequence Plugin](#sequence) - Meta-Plugin zur sequentiellen Ausführung mehrerer Schreibvorgänge.
@@ -1039,6 +1040,7 @@ Es wird verwendet, wenn ein Plugin einen anderen Datentyp erwartet als evcc lief
10391040
| float2int | Float64 → Int64 (Nachkommastellen werden abgeschnitten) |
10401041
| int2float | Int64 → Float64 |
10411042
| int2bytes | Int64 → Byte-Array (Big Endian, 8 Bytes) |
1043+
| bool2int | Bool → Int64 (true=1, false=0) |
10421044

10431045
**Beispiel** (evcc liefert float, Gerät erwartet int):
10441046

@@ -1188,6 +1190,40 @@ batterymode:
11881190

11891191
In diesem Beispiel gibt das Gerät einen harmlosen Modbus-Fehler zurück, der ignoriert wird.
11901192

1193+
### IfElse <Badge text="schreiben" variant="caution" size="small" />
1194+
1195+
Das `ifelse` Plugin führt bedingte Schreibvorgänge mit zwei Zweigen aus.
1196+
Je nach Eingabewert wird entweder das `if` oder das `else` Plugin ausgeführt.
1197+
1198+
**Parameter**:
1199+
1200+
| Parameter | Typ | Erfordert | Beschreibung |
1201+
| --------- | ------ | --------- | --------------------------------------------------------- |
1202+
| if | config | ja | Plugin, das bei erfüllter Bedingung ausgeführt wird |
1203+
| else | config | ja | Plugin, das bei nicht erfüllter Bedingung ausgeführt wird |
1204+
1205+
**Funktionsweise**:
1206+
1207+
- Bei `bool` Werten: `true` führt `if` aus, `false` führt `else` aus
1208+
- Bei `int64` Werten: `> 0` führt `if` aus, sonst `else`
1209+
1210+
**Unterstützte Datentypen**: `int64`, `bool`
1211+
1212+
**Beispiel** (unterschiedliche Endpunkte für An- und Ausschalten):
1213+
1214+
```yaml
1215+
enable:
1216+
source: ifelse
1217+
if:
1218+
source: http
1219+
uri: http://device.local/api/on
1220+
method: POST
1221+
else:
1222+
source: http
1223+
uri: http://device.local/api/off
1224+
method: POST
1225+
```
1226+
11911227
### Map <Badge text="lesen" variant="tip" size="small" /> <Badge text="schreiben" variant="caution" size="small" />
11921228

11931229
Das `map` Plugin übersetzt Integer-Werte in andere Integer-Werte mithilfe einer Lookup-Tabelle.

src/content/docs/en/plugins.mdx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Additionally, plugins can also be used for the endpoints described in [Messaging
4141
- [Convert Plugin](#convert) - Meta-plugin for data type conversion when writing (e.g., float to int).
4242
- [Delta Plugin](#delta) - Meta-plugin for converting absolute values to delta/increment values when writing.
4343
- [Ignore Plugin](#ignore) - Meta-plugin for suppressing specific error messages.
44+
- [IfElse Plugin](#ifelse) - Meta-plugin for conditional write operations with two branches (if/else).
4445
- [Map Plugin](#map) - Meta-plugin for translating integer values (e.g., device-specific modes to evcc modes).
4546
- [Meter Plugin](#meter-plugin) - Plugin to use another meter as a data source.
4647
- [Sequence Plugin](#sequence) - Meta-plugin for sequential execution of multiple write operations.
@@ -1039,6 +1040,7 @@ It is used when a plugin expects a different data type than evcc provides.
10391040
| float2int | Float64 → Int64 (decimal places are truncated) |
10401041
| int2float | Int64 → Float64 |
10411042
| int2bytes | Int64 → Byte array (Big Endian, 8 bytes) |
1043+
| bool2int | Bool → Int64 (true=1, false=0) |
10421044

10431045
**Example** (evcc provides float, device expects int):
10441046

@@ -1188,6 +1190,40 @@ batterymode:
11881190

11891191
In this example, the device returns a harmless modbus error that is ignored.
11901192

1193+
### IfElse <Badge text="write" variant="caution" size="small" />
1194+
1195+
The `ifelse` plugin performs conditional write operations with two branches.
1196+
Depending on the input value, either the `if` or the `else` plugin is executed.
1197+
1198+
**Parameters**:
1199+
1200+
| Parameter | Type | Required | Description |
1201+
| --------- | ------ | -------- | --------------------------------------------- |
1202+
| if | config | yes | Plugin executed when the condition is met |
1203+
| else | config | yes | Plugin executed when the condition is not met |
1204+
1205+
**How it works**:
1206+
1207+
- For `bool` values: `true` runs `if`, `false` runs `else`
1208+
- For `int64` values: `> 0` runs `if`, otherwise runs `else`
1209+
1210+
**Supported data types**: `int64`, `bool`
1211+
1212+
**Example** (different endpoints for enabling and disabling):
1213+
1214+
```yaml
1215+
enable:
1216+
source: ifelse
1217+
if:
1218+
source: http
1219+
uri: http://device.local/api/on
1220+
method: POST
1221+
else:
1222+
source: http
1223+
uri: http://device.local/api/off
1224+
method: POST
1225+
```
1226+
11911227
### Map <Badge text="read" variant="tip" size="small" /> <Badge text="write" variant="caution" size="small" />
11921228

11931229
The `map` plugin translates integer values to other integer values using a lookup table.

0 commit comments

Comments
 (0)