add all existing items, homekit export

This commit is contained in:
Wolfgang Hottgenroth
2018-01-10 14:15:43 +01:00
parent 153b8570e4
commit 8a6547ff91
20 changed files with 746 additions and 42 deletions

View File

@ -6,5 +6,6 @@
"smtpHost": "localhost",
"smtpPort": 25,
"smtpSender": "dispatcher@hottis.de",
"smtpReceiver": "woho@hottis.de"
"smtpReceiver": "woho@hottis.de",
"homekitFile": "homekit.json"
}

View File

@ -2,8 +2,8 @@
Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
class AHomematicItem extends AItem_1.AItem {
constructor(floor, room, item, hmId) {
super(floor, room, item);
constructor(floor, room, item, label, hmId) {
super(floor, room, item, label);
this.hmId = hmId;
this.homegearTopicPre = 'homegear/instance1';
this.actionTopicPre = `${this.homegearTopicPre}/set/${this.hmId}`;

11
dist/AItem.js vendored
View File

@ -3,13 +3,22 @@ Object.defineProperty(exports, "__esModule", { value: true });
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
class AItem {
constructor(floor, room, item) {
constructor(floor, room, item, label = '') {
this.floor = floor;
this.room = room;
this.item = item;
this.itemId = `${this.floor}.${this.room}.${this.item}`;
if (label == '') {
this.label = this.itemId;
}
else {
this.label = label;
}
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`;
}
exportHomekit() {
return { 'id': this.itemId, 'object': null };
}
start() {
MqttDispatcher_1.mqttHandler.register(this.subscribeTopics, (topic, payload) => {
logger.info(`item ${this.itemId}: ${topic}, ${payload}`);

55
dist/Export.js vendored Normal file
View File

@ -0,0 +1,55 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
function SwitchHomekitExport(itemId, label, stateTopic, stateFeedbackTopic, type) {
let out;
switch (type) {
case 'bulb':
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
case 'outlet':
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic);
break;
default:
throw new Error(`no homekit export function for type ${type}`);
}
return out;
}
exports.SwitchHomekitExport = SwitchHomekitExport;
function SwitchHomekitBulbExport(id, label, setOn, statusOn) {
let o = {
"id": id,
"name": label,
"service": "Lightbulb",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
};
return { 'id': id, 'object': o };
}
function SwitchHomekitOutletExport(id, label, setOn, statusOn) {
let o = {
"id": id,
"name": label,
"service": "Outlet",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF"
},
"config": {}
};
return { 'id': id, 'object': o };
}
//# sourceMappingURL=Export.js.map

4
dist/Forwarder.js vendored
View File

@ -3,8 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
const AItem_1 = require("./AItem");
const MqttDispatcher_1 = require("./MqttDispatcher");
class Forwarder extends AItem_1.AItem {
constructor(floor, room, item, topicLastPart, targetTopics) {
super(floor, room, item);
constructor(floor, room, item, label, topicLastPart, targetTopics) {
super(floor, room, item, label);
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`;
this.subscribeTopics = [this.inTopic];
this.targetTopics = targetTopics;

View File

@ -4,8 +4,8 @@ const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
class HomematicDimmerItem extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId) {
super(floor, room, item, hmId);
constructor(floor, room, item, label, hmId) {
super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;
this.brightTopic = `${this.topicFirstPart}/bright`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;

View File

@ -28,7 +28,7 @@ class HomematicFourButtonSingleItem {
exports.HomematicFourButtonSingleItem = HomematicFourButtonSingleItem;
class HomematicFourButtonThing extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId, itemObjs) {
super(floor, room, item, hmId);
super(floor, room, item, '', hmId);
this.itemObjs = itemObjs;
if (this.itemObjs.length != 4) {
throw new Error('itemObjs for HomematicFourButtonThing must have four elements');

View File

@ -2,9 +2,10 @@
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AHomematicItem_1 = require("./AHomematicItem");
const Export_1 = require("./Export");
class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
constructor(floor, room, item, hmId) {
super(floor, room, item, hmId);
constructor(floor, room, item, label, hmId, type = 'bulb') {
super(floor, room, item, label, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`;
@ -15,6 +16,10 @@ class HomematicSwitchItem extends AHomematicItem_1.AHomematicItem {
];
this.state = 'OFF';
this.oldState = undefined;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
switch (topic) {

View File

@ -2,9 +2,10 @@
Object.defineProperty(exports, "__esModule", { value: true });
const MqttDispatcher_1 = require("./MqttDispatcher");
const AItem_1 = require("./AItem");
const Export_1 = require("./Export");
class M433SwitchItem extends AItem_1.AItem {
constructor(floor, room, item, onCode, offCode) {
super(floor, room, item);
constructor(floor, room, item, label, onCode, offCode, type = 'bulb') {
super(floor, room, item, label);
this.stateTopic = `${this.topicFirstPart}/state`;
this.subscribeTopics = [this.stateTopic];
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
@ -13,6 +14,10 @@ class M433SwitchItem extends AItem_1.AItem {
this.oldState = undefined;
this.onCode = onCode;
this.offCode = offCode;
this.type = type;
}
exportHomekit() {
return Export_1.SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type);
}
processMessage(topic, payload) {
this.state = payload;

110
dist/main.js vendored
View File

@ -1,5 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const fs = require("fs");
const config = require("./config");
const logger = require("./log");
const MqttDispatcher_1 = require("./MqttDispatcher");
const M433SwitchItem_1 = require("./M433SwitchItem");
@ -10,10 +12,95 @@ const HomematicDimmerItem_1 = require("./HomematicDimmerItem");
const HomematicSwitchItem_1 = require("./HomematicSwitchItem");
const Forwarder_1 = require("./Forwarder");
logger.info("Dispatcher starting");
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1');
let allLabeledItems = new Array();
// Anna -----------------------------------------------------------------------------------------------------
// Anna Aquarium 14665044 24 1 14665041 24 1
let aquariumLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'AquariumLight', 'Aquariumlicht', '14665044 24 1', '14665041 24 1');
aquariumLight.start();
let deskLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1');
deskLight.start();
allLabeledItems.push(aquariumLight);
// Anna Bett 14668116 24 1 14668113 24 1
let annaBedLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1');
annaBedLight.start();
allLabeledItems.push(annaBedLight);
// Matthias -------------------------------------------------------------------------------------------------
// Matthias Stehlampen 7 24 1 6 24 1
let matthiasStandLights = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'Stehlampen Matthias', 'StandLight', '7 24 1', '6 24 1');
matthiasStandLights.start();
allLabeledItems.push(matthiasStandLights);
// Matthias Bett 15 24 1 14 24 1
let matthiasBedLight = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1');
matthiasBedLight.start();
allLabeledItems.push(matthiasBedLight);
// Matthias Lautsprecher 11 24 1 10 24 1
let matthiasSpeaker = new M433SwitchItem_1.M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet');
matthiasSpeaker.start();
allLabeledItems.push(matthiasSpeaker);
// Esszimmer ------------------------------------------------------------------------------------------------
// Esszimmer kleine Lampe 69653 24 1 69652 24 1
let diningRoomSmallLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1');
diningRoomSmallLight.start();
allLabeledItems.push(diningRoomSmallLight);
// Esszimmer Stehlampe 86037 24 1 86036 24 1
let diningRoomStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1');
diningRoomStandLight.start();
allLabeledItems.push(diningRoomStandLight);
// Esszimmer Schranklicht 65813 24 1 65812 24 1
let diningRoomCupboardLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1');
diningRoomCupboardLight.start();
allLabeledItems.push(diningRoomCupboardLight);
// Wohnzimmer -----------------------------------------------------------------------------------------------
// Wohnzimmer grosse Lampe 65557 24 1 65556 24 1
let livingRoomLargeLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1');
livingRoomLargeLight.start();
allLabeledItems.push(livingRoomLargeLight);
// Wohnzimmer kleine Lampe 87061 24 1 87060 24 1
let livingRoomSmallLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1');
livingRoomSmallLight.start();
allLabeledItems.push(livingRoomSmallLight);
// Wohnzimmer Sterne 69909 24 1 69908 24 1
let livingRoomStars = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1');
livingRoomStars.start();
allLabeledItems.push(livingRoomStars);
// Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1
let livingRoomStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1');
livingRoomStandLight.start();
allLabeledItems.push(livingRoomStandLight);
// Flur -----------------------------------------------------------------------------------------------------
// Flur Schreibtisch 83221 24 1 83220 24 1
let hallwayDeskLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1');
hallwayDeskLight.start();
allLabeledItems.push(hallwayDeskLight);
// Flur Stehlampe 8704914 24 5 8793154 24 5
let hallwayStandLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5');
hallwayStandLight.start();
allLabeledItems.push(hallwayStandLight);
// Flur Schranklicht 66581 24 1 66580 24 1
let hallwayWardrobeLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1');
hallwayWardrobeLight.start();
allLabeledItems.push(hallwayWardrobeLight);
// Küche ----------------------------------------------------------------------------------------------------
// Küche Fensterbank 66837 24 1 66836 24 1
let kitchenWindowLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1');
kitchenWindowLight.start();
allLabeledItems.push(kitchenWindowLight);
// Küche Deckenlampe 82197 24 1 82196 24 1
let kitchenCeilingLight = new M433SwitchItem_1.M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1');
kitchenWindowLight.start();
allLabeledItems.push(kitchenCeilingLight);
// Schlafzimmer ---------------------------------------------------------------------------------------------
// Schlafzimmer Wolfgangs Seite 13976916 24 1 13976913 24 1
let bedRoomWolfgangsSide = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1');
bedRoomWolfgangsSide.start();
allLabeledItems.push(bedRoomWolfgangsSide);
// Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1
let bedRoomPattysSide = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1');
bedRoomPattysSide.start();
allLabeledItems.push(bedRoomPattysSide);
// Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1
let bedRoomWindowLight = new M433SwitchItem_1.M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1');
bedRoomWindowLight.start();
allLabeledItems.push(bedRoomWindowLight);
// ----------------------------------------------------------------------------------------------------------
let testFourButton = new HomematicFourButtonThing_1.HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
new HomematicFourButtonThing_1.HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
@ -25,15 +112,26 @@ let testDimmerAdaptor = new DimmerAdaptor_1.DimmerAdaptor('Gnd', 'Hallway', 'Tes
testDimmerAdaptor.start();
let testTimerAdaptor = new TimerAdaptor_1.TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10);
testTimerAdaptor.start();
let testLight = new HomematicDimmerItem_1.HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8);
let testLight = new HomematicDimmerItem_1.HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 'Testlampe mit Dimmer', 8);
testLight.start();
let testLight2 = new HomematicSwitchItem_1.HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5);
let testLight2 = new HomematicSwitchItem_1.HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 'Testlampe ohne Dimmer', 5);
testLight2.start();
let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
let testForwarder = new Forwarder_1.Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', 'TestForwarder', [
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
]);
testForwarder.start();
// ----------------------------------------------------------------------------------------------------------
// Homekit export
let homekitObject = {};
allLabeledItems.forEach((item) => {
let homekitExport = item.exportHomekit();
if ('id' in homekitExport) {
homekitObject[homekitExport['id']] = homekitExport['object'];
}
});
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4));
// ----------------------------------------------------------------------------------------------------------
MqttDispatcher_1.mqttHandler.exec();
logger.info("Dispatcher running");
//# sourceMappingURL=main.js.map

322
homekit.json Normal file
View File

@ -0,0 +1,322 @@
{
"1st.Anna.AquariumLight": {
"id": "1st.Anna.AquariumLight",
"name": "Aquariumlicht",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/Anna/AquariumLight/state",
"statusOn": "dispatcher_ng/items/1st/Anna/AquariumLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.Anna.BedLight": {
"id": "1st.Anna.BedLight",
"name": "Bettlicht Anna",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/Anna/BedLight/state",
"statusOn": "dispatcher_ng/items/1st/Anna/BedLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.Matthias.Stehlampen Matthias": {
"id": "1st.Matthias.Stehlampen Matthias",
"name": "StandLight",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state",
"statusOn": "dispatcher_ng/items/1st/Matthias/Stehlampen Matthias/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.Matthias.BedLight": {
"id": "1st.Matthias.BedLight",
"name": "Bettlicht Matthias",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/Matthias/BedLight/state",
"statusOn": "dispatcher_ng/items/1st/Matthias/BedLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.Matthias.Speaker": {
"id": "1st.Matthias.Speaker",
"name": "Lautsprecher Matthias",
"service": "Outlet",
"topic": {
"setOn": "dispatcher_ng/items/1st/Matthias/Speaker/state",
"statusOn": "dispatcher_ng/items/1st/Matthias/Speaker/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF"
},
"config": {}
},
"Gnd.DiningRoom.SmallLight": {
"id": "Gnd.DiningRoom.SmallLight",
"name": "kleine Lampe Esszimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state",
"statusOn": "dispatcher_ng/items/Gnd/DiningRoom/SmallLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.DiningRoom.StandLight": {
"id": "Gnd.DiningRoom.StandLight",
"name": "Stehlampe Esszimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/DiningRoom/StandLight/state",
"statusOn": "dispatcher_ng/items/Gnd/DiningRoom/StandLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.DiningRoom.CupboardLight": {
"id": "Gnd.DiningRoom.CupboardLight",
"name": "Schranklicht Esszimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state",
"statusOn": "dispatcher_ng/items/Gnd/DiningRoom/CupboardLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.LivingRoom.LargeLight": {
"id": "Gnd.LivingRoom.LargeLight",
"name": "große Lampe Wohnzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state",
"statusOn": "dispatcher_ng/items/Gnd/LivingRoom/LargeLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.LivingRoom.SmallLight": {
"id": "Gnd.LivingRoom.SmallLight",
"name": "kleine Lampe Wohnzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state",
"statusOn": "dispatcher_ng/items/Gnd/LivingRoom/SmallLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.LivingRoom.Stars": {
"id": "Gnd.LivingRoom.Stars",
"name": "Sterne Wohnzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/LivingRoom/Stars/state",
"statusOn": "dispatcher_ng/items/Gnd/LivingRoom/Stars/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.LivingRoom.StandLight": {
"id": "Gnd.LivingRoom.StandLight",
"name": "Stehlampe Wohnzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/LivingRoom/StandLight/state",
"statusOn": "dispatcher_ng/items/Gnd/LivingRoom/StandLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.Hallway.DeskLight": {
"id": "Gnd.Hallway.DeskLight",
"name": "Schreibtischlampe Flur",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/Hallway/DeskLight/state",
"statusOn": "dispatcher_ng/items/Gnd/Hallway/DeskLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.Hallway.StandLight": {
"id": "Gnd.Hallway.StandLight",
"name": "Schranklicht Flur",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/Hallway/StandLight/state",
"statusOn": "dispatcher_ng/items/Gnd/Hallway/StandLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.Kitchen.WindowLight": {
"id": "Gnd.Kitchen.WindowLight",
"name": "Fensterbanklicht Küche",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/Kitchen/WindowLight/state",
"statusOn": "dispatcher_ng/items/Gnd/Kitchen/WindowLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"Gnd.Kitchen.CeilingLight": {
"id": "Gnd.Kitchen.CeilingLight",
"name": "Deckenlampe Küche",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/Gnd/Kitchen/CeilingLight/state",
"statusOn": "dispatcher_ng/items/Gnd/Kitchen/CeilingLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.BedRoom.WolfgangsSide": {
"id": "1st.BedRoom.WolfgangsSide",
"name": "Wolfgangs Seite Schlafzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/BedRoom/WolfgangsSide/state",
"statusOn": "dispatcher_ng/items/1st/BedRoom/WolfgangsSide/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.BedRoom.PattysSide": {
"id": "1st.BedRoom.PattysSide",
"name": "Pattys Seite Schlafzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/BedRoom/PattysSide/state",
"statusOn": "dispatcher_ng/items/1st/BedRoom/PattysSide/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
},
"1st.BedRoom.WindowLight": {
"id": "1st.BedRoom.WindowLight",
"name": "Fensterbanklicht Schlafzimmer",
"service": "Lightbulb",
"topic": {
"setOn": "dispatcher_ng/items/1st/BedRoom/WindowLight/state",
"statusOn": "dispatcher_ng/items/1st/BedRoom/WindowLight/state/feedback"
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
}
}

View File

@ -6,8 +6,8 @@ export abstract class AHomematicItem extends AItem {
protected actionTopicPre: string;
protected homegearTopicPre: string;
protected hmId: number;
constructor(floor: string, room: string, item: string, hmId: number) {
super(floor, room, item);
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
super(floor, room, item, label);
this.hmId = hmId;
this.homegearTopicPre = 'homegear/instance1';
this.actionTopicPre = `${this.homegearTopicPre}/set/${this.hmId}`;

View File

@ -1,26 +1,37 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { HomekitExportType } from './Export'
export abstract class AItem {
protected topicFirstPart: string
protected itemId: string
protected label: string
private item: string
private room: string
private floor: string
protected subscribeTopics: string[]
constructor(floor: string, room: string, item: string) {
constructor(floor: string, room: string, item: string, label: string = '') {
this.floor = floor
this.room = room
this.item = item
this.itemId = `${this.floor}.${this.room}.${this.item}`
if (label == '') {
this.label = this.itemId
} else {
this.label = label
}
this.topicFirstPart = `dispatcher_ng/items/${this.floor}/${this.room}/${this.item}`
}
abstract processMessage(topic: string, payload: string) : void
exportHomekit() : HomekitExportType {
return {'id': this.itemId, 'object': null }
}
start() : void {
mqttHandler.register(this.subscribeTopics, (topic: string, payload: string) : void => {
logger.info(`item ${this.itemId}: ${topic}, ${payload}`)
@ -28,5 +39,3 @@ export abstract class AItem {
})
}
}

60
src/Export.ts Normal file
View File

@ -0,0 +1,60 @@
export type HomekitExportType = {
'id': string,
'object': any
}
export function SwitchHomekitExport(itemId: string, label: string, stateTopic: string, stateFeedbackTopic: string, type: string) : HomekitExportType {
let out: HomekitExportType
switch (type) {
case 'bulb':
out = SwitchHomekitBulbExport(itemId, label, stateTopic, stateFeedbackTopic)
break
case 'outlet':
out = SwitchHomekitOutletExport(itemId, label, stateTopic, stateFeedbackTopic)
break
default:
throw new Error(`no homekit export function for type ${type}`)
}
return out
}
function SwitchHomekitBulbExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType {
let o : any = {
"id": id,
"name": label,
"service": "Lightbulb",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF",
"brightnessFactor": "",
"hueFactor": "",
"saturationFactor": ""
},
"config": {}
}
return { 'id': id, 'object': o }
}
function SwitchHomekitOutletExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType {
let o : any = {
"id": id,
"name": label,
"service": "Outlet",
"topic": {
"setOn": setOn,
"statusOn": statusOn
},
"payload": {
"onTrue": "ON",
"onFalse": "OFF"
},
"config": {}
}
return { 'id': id, 'object': o }
}

View File

@ -7,13 +7,14 @@ export class Forwarder extends AItem {
private targetTopics: string[]
private inTopic: string
constructor(floor: string, room: string, item: string, topicLastPart: string, targetTopics: string[]) {
super(floor, room, item)
constructor(floor: string, room: string, item: string, label: string, topicLastPart: string, targetTopics: string[]) {
super(floor, room, item, label)
this.inTopic = `${this.topicFirstPart}/${topicLastPart}`
this.subscribeTopics = [ this.inTopic ]
this.targetTopics = targetTopics
}
processMessage(topic: string, payload: string) : void {
switch (topic) {
case this.inTopic:

View File

@ -17,8 +17,8 @@ export class HomematicDimmerItem extends AHomematicItem {
private brightTopic: string
private stateTopic: string
constructor(floor: string, room: string, item: string, hmId: number) {
super(floor, room, item, hmId)
constructor(floor: string, room: string, item: string, label: string, hmId: number) {
super(floor, room, item, label, hmId)
this.stateTopic = `${this.topicFirstPart}/state`
this.brightTopic = `${this.topicFirstPart}/bright`
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`

View File

@ -33,7 +33,7 @@ export class HomematicFourButtonThing extends AHomematicItem {
private itemObjs: HomematicFourButtonSingleItem[]
constructor(floor: string, room: string, item: string, hmId: number, itemObjs: HomematicFourButtonSingleItem[]) {
super(floor, room, item, hmId)
super(floor, room, item, '', hmId)
this.itemObjs = itemObjs
if (this.itemObjs.length != 4) {
throw new Error('itemObjs for HomematicFourButtonThing must have four elements')

View File

@ -1,7 +1,7 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem'
import { SwitchHomekitExport, HomekitExportType } from './Export'
export class HomematicSwitchItem extends AHomematicItem {
private oldState: string|undefined
@ -10,9 +10,10 @@ export class HomematicSwitchItem extends AHomematicItem {
private deviceFeedbackTopic: string
private stateFeedbackTopic: string
private stateTopic: string
private type: string
constructor(floor: string, room: string, item: string, hmId: number) {
super(floor, room, item, hmId)
constructor(floor: string, room: string, item: string, label: string, hmId: number, type: string = 'bulb') {
super(floor, room, item, label, hmId)
this.stateTopic = `${this.topicFirstPart}/state`
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
this.deviceFeedbackTopic = `${this.deviceTopicPre}/1/STATE`
@ -23,8 +24,12 @@ export class HomematicSwitchItem extends AHomematicItem {
]
this.state = 'OFF'
this.oldState = undefined
this.type = type
}
exportHomekit() : HomekitExportType {
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
}
processMessage(topic: string, payload: string) : void {
switch (topic) {

View File

@ -1,6 +1,7 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AItem } from './AItem'
import { SwitchHomekitExport, HomekitExportType } from './Export'
export class M433SwitchItem extends AItem {
@ -11,9 +12,10 @@ export class M433SwitchItem extends AItem {
private actionTopic: string
private stateFeedbackTopic: string
private stateTopic: string
private type: string
constructor(floor: string, room: string, item: string, onCode: string, offCode: string) {
super(floor, room, item)
constructor(floor: string, room: string, item: string, label: string, onCode: string, offCode: string, type: string = 'bulb') {
super(floor, room, item, label)
this.stateTopic = `${this.topicFirstPart}/state`
this.subscribeTopics = [this.stateTopic]
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`
@ -22,6 +24,11 @@ export class M433SwitchItem extends AItem {
this.oldState = undefined
this.onCode = onCode
this.offCode = offCode
this.type = type
}
exportHomekit() : HomekitExportType {
return SwitchHomekitExport(this.itemId, this.label, this.stateTopic, this.stateFeedbackTopic, this.type)
}
processMessage(topic: string, payload: string) {

View File

@ -1,7 +1,11 @@
import * as fs from 'fs'
import * as config from './config'
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AItem } from './AItem'
import { HomekitExportType } from './Export'
import { M433SwitchItem } from './M433SwitchItem'
import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing'
import { DimmerAdaptor } from './DimmerAdaptor'
@ -14,12 +18,121 @@ import { Forwarder } from './Forwarder'
logger.info("Dispatcher starting")
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', '14665044 24 1', '14665041 24 1')
aquariumLight.start()
let deskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', '83221 24 1', '83220 24 1')
deskLight.start()
let allLabeledItems : Array<AItem> = new Array<AItem>()
// Anna -----------------------------------------------------------------------------------------------------
// Anna Aquarium 14665044 24 1 14665041 24 1
let aquariumLight = new M433SwitchItem('1st', 'Anna', 'AquariumLight', 'Aquariumlicht', '14665044 24 1', '14665041 24 1')
aquariumLight.start()
allLabeledItems.push(aquariumLight)
// Anna Bett 14668116 24 1 14668113 24 1
let annaBedLight = new M433SwitchItem('1st', 'Anna', 'BedLight', 'Bettlicht Anna', '14668116 24 1', '14668113 24 1')
annaBedLight.start()
allLabeledItems.push(annaBedLight)
// Matthias -------------------------------------------------------------------------------------------------
// Matthias Stehlampen 7 24 1 6 24 1
let matthiasStandLights = new M433SwitchItem('1st', 'Matthias', 'Stehlampen Matthias', 'StandLight', '7 24 1', '6 24 1')
matthiasStandLights.start()
allLabeledItems.push(matthiasStandLights)
// Matthias Bett 15 24 1 14 24 1
let matthiasBedLight = new M433SwitchItem('1st', 'Matthias', 'BedLight', 'Bettlicht Matthias', '15 24 1', '14 24 1')
matthiasBedLight.start()
allLabeledItems.push(matthiasBedLight)
// Matthias Lautsprecher 11 24 1 10 24 1
let matthiasSpeaker = new M433SwitchItem('1st', 'Matthias', 'Speaker', 'Lautsprecher Matthias', '11 24 1', '10 24 1', 'outlet')
matthiasSpeaker.start()
allLabeledItems.push(matthiasSpeaker)
// Esszimmer ------------------------------------------------------------------------------------------------
// Esszimmer kleine Lampe 69653 24 1 69652 24 1
let diningRoomSmallLight = new M433SwitchItem('Gnd', 'DiningRoom', 'SmallLight', 'kleine Lampe Esszimmer', '69653 24 1', '69652 24 1')
diningRoomSmallLight.start()
allLabeledItems.push(diningRoomSmallLight)
// Esszimmer Stehlampe 86037 24 1 86036 24 1
let diningRoomStandLight = new M433SwitchItem('Gnd', 'DiningRoom', 'StandLight', 'Stehlampe Esszimmer', '86037 24 1', '86036 24 1')
diningRoomStandLight.start()
allLabeledItems.push(diningRoomStandLight)
// Esszimmer Schranklicht 65813 24 1 65812 24 1
let diningRoomCupboardLight = new M433SwitchItem('Gnd', 'DiningRoom', 'CupboardLight', 'Schranklicht Esszimmer', '65813 24 1', '65812 24 1')
diningRoomCupboardLight.start()
allLabeledItems.push(diningRoomCupboardLight)
// Wohnzimmer -----------------------------------------------------------------------------------------------
// Wohnzimmer grosse Lampe 65557 24 1 65556 24 1
let livingRoomLargeLight = new M433SwitchItem('Gnd', 'LivingRoom', 'LargeLight', 'große Lampe Wohnzimmer', '65557 24 1', '65556 24 1')
livingRoomLargeLight.start()
allLabeledItems.push(livingRoomLargeLight)
// Wohnzimmer kleine Lampe 87061 24 1 87060 24 1
let livingRoomSmallLight = new M433SwitchItem('Gnd', 'LivingRoom', 'SmallLight', 'kleine Lampe Wohnzimmer', '87061 24 1', '87060 24 1')
livingRoomSmallLight.start()
allLabeledItems.push(livingRoomSmallLight)
// Wohnzimmer Sterne 69909 24 1 69908 24 1
let livingRoomStars = new M433SwitchItem('Gnd', 'LivingRoom', 'Stars', 'Sterne Wohnzimmer', '69909 24 1', '69908 24 1')
livingRoomStars.start()
allLabeledItems.push(livingRoomStars)
// Wohnzimmer kleine Stehlampe 81941 24 1 81940 24 1
let livingRoomStandLight = new M433SwitchItem('Gnd', 'LivingRoom', 'StandLight', 'Stehlampe Wohnzimmer', '81941 24 1', '81940 24 1')
livingRoomStandLight.start()
allLabeledItems.push(livingRoomStandLight)
// Flur -----------------------------------------------------------------------------------------------------
// Flur Schreibtisch 83221 24 1 83220 24 1
let hallwayDeskLight = new M433SwitchItem('Gnd', 'Hallway', 'DeskLight', 'Schreibtischlampe Flur', '83221 24 1', '83220 24 1')
hallwayDeskLight.start()
allLabeledItems.push(hallwayDeskLight)
// Flur Stehlampe 8704914 24 5 8793154 24 5
let hallwayStandLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Stehlampe Flur', '8704914 24 5', '8793154 24 5')
hallwayStandLight.start()
allLabeledItems.push(hallwayStandLight)
// Flur Schranklicht 66581 24 1 66580 24 1
let hallwayWardrobeLight = new M433SwitchItem('Gnd', 'Hallway', 'StandLight', 'Schranklicht Flur', '66581 24 1', '66580 24 1')
hallwayWardrobeLight.start()
allLabeledItems.push(hallwayWardrobeLight)
// Küche ----------------------------------------------------------------------------------------------------
// Küche Fensterbank 66837 24 1 66836 24 1
let kitchenWindowLight = new M433SwitchItem('Gnd', 'Kitchen', 'WindowLight', 'Fensterbanklicht Küche', '66837 24 1', '66836 24 1')
kitchenWindowLight.start()
allLabeledItems.push(kitchenWindowLight)
// Küche Deckenlampe 82197 24 1 82196 24 1
let kitchenCeilingLight = new M433SwitchItem('Gnd', 'Kitchen', 'CeilingLight', 'Deckenlampe Küche', '82197 24 1', '82196 24 1')
kitchenWindowLight.start()
allLabeledItems.push(kitchenCeilingLight)
// Schlafzimmer ---------------------------------------------------------------------------------------------
// Schlafzimmer Wolfgangs Seite 13976916 24 1 13976913 24 1
let bedRoomWolfgangsSide = new M433SwitchItem('1st', 'BedRoom', 'WolfgangsSide', 'Wolfgangs Seite Schlafzimmer', '13976916 24 1', '13976913 24 1')
bedRoomWolfgangsSide.start()
allLabeledItems.push(bedRoomWolfgangsSide)
// Schlafzimmer Pattys Seite 13980756 24 1 13980753 24 1
let bedRoomPattysSide = new M433SwitchItem('1st', 'BedRoom', 'PattysSide', 'Pattys Seite Schlafzimmer', '13980756 24 1', '13980753 24 1')
bedRoomPattysSide.start()
allLabeledItems.push(bedRoomPattysSide)
// Schlafzimmer Fensterbank 13979988 24 1 13979985 24 1
let bedRoomWindowLight = new M433SwitchItem('1st', 'BedRoom', 'WindowLight', 'Fensterbanklicht Schlafzimmer', '13979988 24 1', '13979985 24 1')
bedRoomWindowLight.start()
allLabeledItems.push(bedRoomWindowLight)
// ----------------------------------------------------------------------------------------------------------
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/DeskLight/timerIn'),
@ -34,13 +147,13 @@ testDimmerAdaptor.start()
let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10)
testTimerAdaptor.start()
let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 8)
let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 'Testlampe mit Dimmer', 8)
testLight.start()
let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 5)
let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 'Testlampe ohne Dimmer', 5)
testLight2.start()
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', 'TestForwarder', [
'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
])
@ -48,6 +161,20 @@ testForwarder.start()
// ----------------------------------------------------------------------------------------------------------
// Homekit export
let homekitObject : { [key:string]:{} } = {}
allLabeledItems.forEach((item: AItem) => {
let homekitExport : HomekitExportType = item.exportHomekit()
if ('id' in homekitExport) {
homekitObject[homekitExport['id']] = homekitExport['object']
}
})
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))
// ----------------------------------------------------------------------------------------------------------
mqttHandler.exec()
logger.info("Dispatcher running")