1
+ namespace Fenstererkennung {
1
2
type GroupType = {
2
3
"radiator" :string ;
3
4
"contact" :string ;
5
+ "name" :string ;
4
6
} ;
5
7
8
+ enum radiatorManufacturer {
9
+ hama ,
10
+ shelly
11
+ }
12
+ enum contactManufacturer {
13
+ sonoff
14
+ }
15
+
6
16
const HamaRadiatorMode = {
7
17
heat : "heat" ,
8
18
off : "off"
@@ -11,26 +21,31 @@ const HamaRadiatorMode = {
11
21
const livingRoom :GroupType = {
12
22
"radiator" : 'zigbee.0.2c1165fffeb3dc7b.mode' , // Hama Radiator
13
23
"contact" : 'zigbee.0.00124b002fbdc865.opened' , //open or close
24
+ "name" : "Wohnzimmer" ,
14
25
} ;
15
26
16
27
const sleepingRoom :GroupType = {
17
28
"radiator" : "2" ,
18
29
"contact" : '2' ,
30
+ "name" :"Schlafzimmer" ,
19
31
} ;
20
32
21
33
const kitchen :GroupType = {
22
- "radiator" : "3" ,
34
+ "radiator" : 'zigbee.0.cc86ecfffec8882f.mode' ,
23
35
"contact" : '3' ,
36
+ "name" : "Küche" ,
24
37
} ;
25
38
26
39
const childrensRoom :GroupType = {
27
- "radiator" : "4" ,
28
- "contact" : '4' ,
29
- } ;
40
+ "radiator" : 'zigbee.0.cc86ecfffec3b6cf.mode' ,
41
+ "contact" : 'zigbee.0.00124b002fbae5b2.opened' /*Is open*/ ,
42
+ "name" : "Kinderzimmer" ,
43
+ } ;
30
44
31
45
const toilet :GroupType = {
32
- "radiator" : "5" ,
46
+ "radiator" : 'zigbee.0.cc86ecfffec3996b.mode' ,
33
47
"contact" : '5' ,
48
+ "name" : "Toilette" ,
34
49
} ;
35
50
36
51
const house :GroupType [ ] = [ childrensRoom , kitchen , livingRoom , sleepingRoom , toilet ] ;
@@ -66,11 +81,19 @@ const activateAllRadiators = (rooms:GroupType[]) => {
66
81
}
67
82
68
83
const deactivateRadiator = ( room :GroupType ) => {
69
- setState ( room . radiator , HamaRadiatorMode . off ) ;
84
+
85
+ if ( getState ( room . radiator ) . val == HamaRadiatorMode . heat ) {
86
+ sendDiscordMessage ( "Thermostat in " + room . name + " abgeschaltet" ) ;
87
+ setState ( room . radiator , HamaRadiatorMode . off ) ;
88
+ }
70
89
}
71
90
72
91
const activateRadiator = ( room :GroupType ) => {
73
- setState ( room . radiator , HamaRadiatorMode . heat ) ;
92
+
93
+ if ( getState ( room . radiator ) . val == HamaRadiatorMode . off ) {
94
+ sendDiscordMessage ( "Thermostat in " + room . name + " eingeschaltet" ) ;
95
+ setState ( room . radiator , HamaRadiatorMode . heat ) ;
96
+ }
74
97
}
75
98
76
99
const checkGroup = ( group :GroupType [ ] ) :boolean => {
@@ -80,18 +103,33 @@ const checkGroup = (group:GroupType[]):boolean => {
80
103
}
81
104
}
82
105
return false ;
106
+
107
+ }
108
+
109
+ const sendDiscordMessage = ( message :string ) => {
110
+ const discordAdapter = 'discord.0' ;
111
+ const discordServerId = '' ;
112
+ const discordChannelId = '' ;
113
+
114
+ sendTo ( discordAdapter , 'sendMessage' , { serverId : discordServerId , channelId : discordChannelId , content : { content : message } } ) ;
115
+
83
116
}
84
117
85
118
86
119
const checkAllWindows = ( ) => {
87
120
121
+
122
+
88
123
const northOpen = checkGroup ( northGroup ) ;
89
124
const southOpen = checkGroup ( southGroup ) ;
125
+
90
126
if ( northOpen && southOpen ) {
127
+
91
128
deactivateAllRadiators ( house ) ;
92
129
return ;
93
130
}
94
131
if ( ! northOpen && ! southOpen ) {
132
+
95
133
activateAllRadiators ( house ) ;
96
134
return ;
97
135
}
@@ -120,3 +158,4 @@ on ({id: kitchen.contact}, (obj) =>{
120
158
on ( { id : sleepingRoom . contact } , ( obj ) => {
121
159
checkAllWindows ( ) ;
122
160
} ) ;
161
+ }
0 commit comments