Beispiel: Mitteilung "Waschmaschine ist fertig"


In diesem Beispiel wird eine Mitteilung an das iPhone von Matthias versendet, wenn die Waschmaschine fertig ist.

Waschgang beendet
Jetzt
Der Waschgang wurde beendet und die Waschmaschine kann entleert werden.

Dazu wird der Stromverbrauch einer Steckdose über die Gruppenadresse 0/0/1 gemessen. Ist der Stromverbrauch größer als 1A für eine Dauer von 10 Minuten, dann wurde ein Waschgang gestartet. Sobald der Stromverbrauch 1 Minute lang unter 500mA sinkt, gilt der Waschgang als beendet.

Mit der Funktion SendNotification wird dann eine Mitteilung an das Apple-Gerät “Matthias iPhone” versendet.

 1hkknx, time = import("hkknx"), import("time")
 2
 3ch = hkknx.GroupWriteNotify("0/0/1")
 4
 5// valueWithinRange returns true, if the value received from 0/0/1 
 6// stays within a range (min and max) for a specific duration.
 7valueWithinRange = func(min, max, duration) {
 8    timeout = time.After(duration)
 9    for {
10        select {
11		case value = <-ch:
12            current = hkknx.ParseDPT9001(value)
13            if current < min || current > max {
14                return false
15            }
16        case <-timeout:
17            return true
18        }
19    }
20}
21
22for {
23    // Check if the electric current stays within 
24    // 1 and 10 A for at least 10 minutes.
25    if !valueWithinRange(1000, 10000, 10 * time.Minute) {
26        continue
27    }
28    
29    for {
30        // Check if the electric current stays within 
31        // 0 and 500 mA for at least 1 minute.
32        if !valueWithinRange(0, 500, 1 * time.Minute) {
33            continue
34        }
35        hkknx.SendNotification("Waschgang beendet", "Der Waschgang wurde beendet und die Waschmaschine kann entleert werden.", "Matthias iPhone")
36        break // Break out of loop
37    }
38}

Auf dieser Seite
Ähnliche Beiträge
© Matthias Hochgatterer – MastodonGithubRésumé