Skip to content

Commit 4c479dd

Browse files
authored
Update radiator_window.ts
added function for messages to discord
1 parent 0b551bb commit 4c479dd

File tree

1 file changed

+46
-7
lines changed

1 file changed

+46
-7
lines changed

radiator_window.ts

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
namespace Fenstererkennung {
12
type GroupType = {
23
"radiator":string;
34
"contact":string;
5+
"name":string;
46
};
57

8+
enum radiatorManufacturer {
9+
hama,
10+
shelly
11+
}
12+
enum contactManufacturer {
13+
sonoff
14+
}
15+
616
const HamaRadiatorMode = {
717
heat: "heat",
818
off: "off"
@@ -11,26 +21,31 @@ const HamaRadiatorMode = {
1121
const livingRoom:GroupType = {
1222
"radiator": 'zigbee.0.2c1165fffeb3dc7b.mode', // Hama Radiator
1323
"contact": 'zigbee.0.00124b002fbdc865.opened', //open or close
24+
"name": "Wohnzimmer",
1425
} ;
1526

1627
const sleepingRoom:GroupType = {
1728
"radiator": "2",
1829
"contact": '2',
30+
"name":"Schlafzimmer",
1931
};
2032

2133
const kitchen:GroupType = {
22-
"radiator": "3",
34+
"radiator": 'zigbee.0.cc86ecfffec8882f.mode',
2335
"contact": '3',
36+
"name": "Küche",
2437
};
2538

2639
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+
};
3044

3145
const toilet:GroupType = {
32-
"radiator": "5",
46+
"radiator": 'zigbee.0.cc86ecfffec3996b.mode',
3347
"contact": '5',
48+
"name": "Toilette",
3449
} ;
3550

3651
const house:GroupType[] = [childrensRoom, kitchen, livingRoom, sleepingRoom, toilet];
@@ -66,11 +81,19 @@ const activateAllRadiators = (rooms:GroupType[]) => {
6681
}
6782

6883
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+
}
7089
}
7190

7291
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+
}
7497
}
7598

7699
const checkGroup = (group:GroupType[]):boolean => {
@@ -80,18 +103,33 @@ const checkGroup = (group:GroupType[]):boolean => {
80103
}
81104
}
82105
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+
83116
}
84117

85118

86119
const checkAllWindows = () => {
87120

121+
122+
88123
const northOpen = checkGroup(northGroup);
89124
const southOpen = checkGroup(southGroup);
125+
90126
if (northOpen && southOpen) {
127+
91128
deactivateAllRadiators(house);
92129
return;
93130
}
94131
if (!northOpen && !southOpen) {
132+
95133
activateAllRadiators(house);
96134
return;
97135
}
@@ -120,3 +158,4 @@ on ({id: kitchen.contact}, (obj) =>{
120158
on ({id: sleepingRoom.contact}, (obj) =>{
121159
checkAllWindows();
122160
});
161+
}

0 commit comments

Comments
 (0)