1
1
namespace Fenstererkennung {
2
- type GroupType = {
3
- "radiator" :string ;
4
- "contact" :string ;
2
+ type Room = {
3
+ "radiator" :string | null ;
4
+ "contact" :string | null ;
5
5
"name" :string ;
6
6
} ;
7
7
@@ -18,85 +18,94 @@ const HamaRadiatorMode = {
18
18
off : "off"
19
19
}
20
20
21
- const livingRoom :GroupType = {
21
+ const ShellyRadiatorMode = {
22
+
23
+ }
24
+
25
+ const livingRoom :Room = {
22
26
"radiator" : 'zigbee.0.2c1165fffeb3dc7b.mode' , // Hama Radiator
23
27
"contact" : 'zigbee.0.00124b002fbdc865.opened' , //open or close
24
28
"name" : "Wohnzimmer" ,
25
29
} ;
26
30
27
- const sleepingRoom :GroupType = {
28
- "radiator" : "2" ,
29
- "contact" : '2' ,
31
+ const sleepingRoom :Room = {
32
+ "radiator" : null ,
33
+ "contact" : null ,
30
34
"name" :"Schlafzimmer" ,
31
35
} ;
32
36
33
- const kitchen :GroupType = {
37
+ const kitchen :Room = {
34
38
"radiator" : 'zigbee.0.cc86ecfffec8882f.mode' ,
35
- "contact" : '3' ,
39
+ "contact" : 'zigbee.0.00124b002fbdabcb.opened' , /*Is open*/
36
40
"name" : "Küche" ,
37
41
} ;
38
42
39
- const childrensRoom :GroupType = {
43
+ const childrensRoom :Room = {
40
44
"radiator" : 'zigbee.0.cc86ecfffec3b6cf.mode' ,
41
45
"contact" : 'zigbee.0.00124b002fbae5b2.opened' /*Is open*/ ,
42
46
"name" : "Kinderzimmer" ,
43
47
} ;
44
48
45
- const toilet : GroupType = {
49
+ const bath : Room = {
46
50
"radiator" : 'zigbee.0.cc86ecfffec3996b.mode' ,
47
- "contact" : '5' ,
48
- "name" : "Toilette " ,
51
+ "contact" : null ,
52
+ "name" : "Bdezimmer " ,
49
53
} ;
50
54
51
- const house :GroupType [ ] = [ childrensRoom , kitchen , livingRoom , sleepingRoom , toilet ] ;
55
+ const house :Room [ ] = [ childrensRoom , kitchen , livingRoom , sleepingRoom , bath ] ;
52
56
53
- const northGroup :GroupType [ ] = [
57
+ const northGroup :Room [ ] = [
54
58
childrensRoom ,
55
59
sleepingRoom ,
56
- toilet
60
+ bath
57
61
] ;
58
- const southGroup :GroupType [ ] = [
62
+ const southGroup :Room [ ] = [
59
63
livingRoom ,
60
64
kitchen
61
65
] ;
62
66
63
- const checkIsWindowOpen = ( room : GroupType ) :boolean => {
67
+ const checkIsWindowOpen = ( room : Room ) :boolean => {
68
+ if ( room . contact == null ) return false ;
64
69
if ( getState ( room . contact ) . val ) {
65
70
return true ;
66
71
} else {
67
72
return false ;
68
73
}
69
74
}
70
75
71
- const deactivateAllRadiators = ( rooms :GroupType [ ] ) => {
76
+ const deactivateAllRadiators = ( rooms :Room [ ] ) => {
72
77
for ( const room of rooms ) {
78
+ if ( room . radiator == null ) continue ;
73
79
deactivateRadiator ( room ) ;
74
80
}
75
81
}
76
82
77
- const activateAllRadiators = ( rooms :GroupType [ ] ) => {
83
+ const activateAllRadiators = ( rooms :Room [ ] ) => {
78
84
for ( const room of rooms ) {
85
+ if ( room . radiator == null ) continue ;
79
86
activateRadiator ( room ) ;
80
87
}
81
88
}
82
89
83
- const deactivateRadiator = ( room :GroupType ) => {
90
+ const deactivateRadiator = ( room :Room ) => {
84
91
85
92
if ( getState ( room . radiator ) . val == HamaRadiatorMode . heat ) {
86
93
sendDiscordMessage ( "Thermostat in " + room . name + " abgeschaltet" ) ;
94
+ sendNtfyMessage ( "Thermostat in " + room . name + " abgeschaltet" ) ;
87
95
setState ( room . radiator , HamaRadiatorMode . off ) ;
88
96
}
89
97
}
90
98
91
- const activateRadiator = ( room :GroupType ) => {
99
+ const activateRadiator = ( room :Room ) => {
92
100
93
101
if ( getState ( room . radiator ) . val == HamaRadiatorMode . off ) {
94
102
sendDiscordMessage ( "Thermostat in " + room . name + " eingeschaltet" ) ;
103
+ sendNtfyMessage ( "Thermostat in " + room . name + " eingeschaltet" ) ;
95
104
setState ( room . radiator , HamaRadiatorMode . heat ) ;
96
105
}
97
106
}
98
107
99
- const checkGroup = ( group :GroupType [ ] ) :boolean => {
108
+ const checkGroup = ( group :Room [ ] ) :boolean => {
100
109
for ( const room of group ) {
101
110
if ( checkIsWindowOpen ( room ) ) {
102
111
return true ;
@@ -114,6 +123,31 @@ const sendDiscordMessage = (message:string) => {
114
123
sendTo ( discordAdapter , 'sendMessage' , { serverId : discordServerId , channelId : discordChannelId , content : { content : message } } ) ;
115
124
116
125
}
126
+ const sendNtfyMessage = ( message :string ) => {
127
+ const ntfyAdapter = 'ntfy.0' ;
128
+ const ntfySubscription = 'iobroker' ;
129
+ const ntfyTitle = 'Heizung' ;
130
+
131
+ const data = {
132
+ "instance" : ntfyAdapter ,
133
+ "topic" : ntfySubscription ,
134
+ "title" : ntfyTitle ,
135
+ "message" : message ,
136
+ "priority" : 5 ,
137
+ "tags" : null ,
138
+ "attachment" : null ,
139
+ "clickURL" : null ,
140
+ "actionButton" : null ,
141
+ "delay" : null
142
+ }
143
+ try {
144
+ sendTo ( ntfyAdapter , "send" , data , ( value ) => {
145
+ console . log ( value ) ;
146
+ } ) ;
147
+ } catch ( error ) {
148
+ console . error ( "Error: " + error ) ;
149
+ }
150
+ }
117
151
118
152
119
153
const checkAllWindows = ( ) => {
@@ -154,8 +188,8 @@ on ({id: childrensRoom.contact}, (obj) =>{
154
188
on ( { id : kitchen . contact } , ( obj ) => {
155
189
checkAllWindows ( ) ;
156
190
} ) ;
157
-
191
+ /*
158
192
on ({id: sleepingRoom.contact}, (obj) =>{
159
193
checkAllWindows();
160
- } ) ;
194
+ });*/
161
195
}
0 commit comments