Beispiel: Rollladensteuerung
In diesem Beispiel wird gezeigt, wie Rollläden zu bestimmten Tageszeiten und Raumtemperaturen geöffnet und geschloßen werden können.
1// This script automates blinds based on the following rules.
2// - Open blinds on weekdays at 7.30 AM and on weekend at 8.00 AM.
3// - Close blinds 30 minutes before sunset.
4// - Close blinds 50% if room temperature raises above 24.5°C.
5hkknx, time = import("hkknx"), import("time")
6
7// Channel sends time at 7:30 AM on weekdays.
8sevenThirtyAM = hkknx.AtTime(7, 30, 0,
9 time.Monday,
10 time.Tuesday,
11 time.Wednesday,
12 time.Thursday,
13 time.Friday)
14// Channel sends time at 8 AM on weekends.
15eightAM = hkknx.AtTime(8, 0, 0,
16 time.Saturday,
17 time.Sunday)
18// Channel sends time 30 minutes before sunset.
19thirtyMinBeforeSunset = hkknx.AtSunset(-30 * time.Minute)
20
21// Channel receives the room temperature.
22temp = hkknx.GroupWriteNotify("0/2/0")
23
24// Define the group addresses to control blinds.
25openCloseAddrs = []string{"0/0/1", "0/0/2"}
26positionAddrs = []string{"0/1/1", "0/1/2"}
27
28for { // Wait for any of the events to happen.
29 select {
30 case <-sevenThirtyAM:
31 // Open the blinds.
32 hkknx.GroupWrite(true, openCloseAddrs...)
33 case <-eightAM:
34 // Open the blinds.
35 hkknx.GroupWrite(true, openCloseAddrs...)
36 case <-thirtyMinBeforeSunset:
37 // Close the blinds.
38 hkknx.GroupWrite(false, openCloseAddrs...)
39 case buf = <-temp:
40 if hkknx.ParseDPT9001(buf) > 24.5 { // is temperature too high?
41 // Set blind positions to 50%
42 hkknx.GroupWrite(hkknx.DPT5004(50), positionAddrs...)
43 }
44 }
45}