Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
10386: Added rule example
Browse files Browse the repository at this point in the history
Signed-off-by: Sönke Küper <[email protected]>
soenkekueper committed Apr 29, 2021
1 parent 099474c commit 08ad87c
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions bundles/org.openhab.binding.ahawastecollection/README.md
Original file line number Diff line number Diff line change
@@ -69,3 +69,71 @@ DateTime collectionDay_leightweightPackaging "Next lightweight packaging collect
DateTime collectionDay_bioWaste "Next bio waste collection" {channel="ahawastecollection:collectionSchedule:wasteCollectionSchedule:bioWaste"}
DateTime collectionDay_paper "Next paper collection" {channel="ahawastecollection:collectionSchedule:wasteCollectionSchedule:paper"}
```


Example for rule that sends an notification with collected waste types on day before collection

```
triggers:
- id: "1"
configuration:
time: 18:00
type: timer.TimeOfDayTrigger
conditions: []
actions:
- inputs: {}
id: "2"
configuration:
type: application/javascript
script: >-
// Determine next day with time 00:00:00
var today = items['LokaleZeit_DatumundZeit'];
var tomorrow = today
.getZonedDateTime()
.plusDays(1)
.withHour(0)
.withMinute(0)
.withSecond(0)
.withNano(0);
// Get next collection dates from items
var biomuellDate = items['collectionDay_bioWaste'].getZonedDateTime();
var leichtverpackungDate = items['collectionDay_leightweightPackaging'].getZonedDateTime();
var papierDate = items['collectionDay_paper'].getZonedDateTime();
var restmuellDate = items['collectionDay_generalWaste'].getZonedDateTime();
// Check which waste types are collected on the next day
var biomuellCollection = biomuellDate.equals(tomorrow);
var leichtverpackungCollection = leichtverpackungDate.equals(tomorrow);
var papierCollection = papierDate.equals(tomorrow);
var restmuellCollection = restmuellDate.equals(tomorrow);
// Transfer booleans to waste type names
var toBeCollected = [];
if (biomuellCollection) {
toBeCollected.push('bio waste');
}
if (leichtverpackungCollection) {
toBeCollected.push('leihtweight packaging');
}
if (papierCollection) {
toBeCollected.push('paper');
}
if (restmuellCollection) {
toBeCollected.push('general waste');
}
// Send message (or something else) if at least one waste type is collected
if (toBeCollected.length > 0) {
var message = "Tomorrow the following waste will be collected:\n" + toBeCollected.join(', ');
events.sendCommand('SignalSmartHome_Eingabewert', message);
}
type: script.ScriptAction
```

0 comments on commit 08ad87c

Please sign in to comment.