diff --git a/src/Export.ts b/src/Export.ts index 098018d..8172d0a 100644 --- a/src/Export.ts +++ b/src/Export.ts @@ -27,6 +27,13 @@ export function SwitchExport(itemId: string, label: string, stateTopic: string, return { 'homekit': homekitOut, 'openhab': openhabOut } } +export function ThermostatExport(itemId: string, label: string, temperatureTopic: string, temperatureFeedbackTopic: string) : ExportType { + return {'homekit': ThermostatHomekitExport(itemId, label, temperatureTopic, temperatureFeedbackTopic), 'openhab': ''} +} + +export function ContactExport(itemId: string, label: string, status: string) : ExportType { + return {'homekit': ContactHomekitExport(itemId, label, status), 'openhab': ''} +} function SwitchHomekitBulbExport(id: string, label: string, setOn: string, statusOn: string) : HomekitExportType { let o : any = { @@ -67,6 +74,36 @@ function SwitchHomekitOutletExport(id: string, label: string, setOn: string, sta return { 'id': id, 'object': o } } +function ThermostatHomekitExport(id: string, label: string, setTemperature: string, statusTemperature: string) : HomekitExportType { + let o : any = { + "id": id, + "name": label, + "service": "Thermostat", + "topic": { + "setTargetTemperature": setTemperature, + "statusTargetTemperature": statusTemperature, + "statusCurrentTemperature": statusTemperature + }, + "payload": {} + } + return { 'id': id, 'object': o } +} + +function ContactHomekitExport(id: string, label: string, status: string) : HomekitExportType { + let o : any = { + "id": id, + "name": label, + "service": "ContactSensor", + "topic": { + "statusContactSensorState": status + }, + "payload": { + "onContactDetected": "CLOSED"s + } + } + + return { 'id': id, 'object': o } +} function SwitchOpenHABExport(id: string, label: string, setOn: string, statusOn: string): string { // Switch windowLightKitchen {mqtt=">[localbroker:nodered/items/windowLightKitchen:command:*:default]", mqtt="<[localbroker:nodered/items/windowLightKitchen/feedback:state:default]"} diff --git a/src/MaxThermostat.ts b/src/MaxThermostat.ts index 0ca8a8c..c9ec901 100644 --- a/src/MaxThermostat.ts +++ b/src/MaxThermostat.ts @@ -3,7 +3,7 @@ import { mqttHandler } from './MqttDispatcher' import { HasInTopic } from './AItem' import { AHomematicItem } from './AHomematicItem' import { MaxWindowContact } from './MaxWindowContact'; -// import { SwitchExport, ExportType } from './Export' +import { ThermostatExport, ExportType } from './Export' const WINDOW_OPEN_TEMPERATURE = 4.5 @@ -27,6 +27,10 @@ export class MaxThermostat extends AHomematicItem implements HasInTopic { return this.temperatureTopic } + exportItem() : ExportType|null { + return ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic) + } + constructor(floor: string, room: string, item: string, label: string, hmId: number, windowContacts: MaxWindowContact[]) { super(floor, room, item, label, hmId) this.temperatureTopic = `${this.topicFirstPart}/temperature` diff --git a/src/MaxWindowContact.ts b/src/MaxWindowContact.ts index b73f687..223be08 100644 --- a/src/MaxWindowContact.ts +++ b/src/MaxWindowContact.ts @@ -1,7 +1,7 @@ import * as logger from './log' import { mqttHandler } from './MqttDispatcher' import { AHomematicItem } from './AHomematicItem' -// import { SwitchExport, ExportType } from './Export' +import { ContactExport, ExportType } from './Export' export class MaxWindowContact extends AHomematicItem { private deviceFeedbackTopic: string @@ -24,6 +24,10 @@ export class MaxWindowContact extends AHomematicItem { ] } + exportItem() : ExportType|null { + return ContactExport(this.itemId, this.label, this.stateFeedbackTopic) + } + processMessage(topic: string, payload: string) : void { if (payload == 'true') { this.state = 'OPEN' diff --git a/src/main.ts b/src/main.ts index 35efb1d..8049570 100644 --- a/src/main.ts +++ b/src/main.ts @@ -197,9 +197,11 @@ allLabeledItems.push(morningLightScene) // ---------------------------------------------------------------------------------------------------------- let windowContactBathroomGnd = new MaxWindowContact('Gnd', 'Bathroom', 'WindowContact', 'Fenster Bad unten', 7) windowContactBathroomGnd.start() +allLabeledItems.push(windowContactBathroomGnd) let thermostatBathroomGnd = new MaxThermostat('Gnd', 'Bathroom', 'Thermostat', 'Thermostat Bad unten', 4, [windowContactBathroomGnd]) thermostatBathroomGnd.start() +allLabeledItems.push(thermostatBathroomGnd) let thermostatBathroomGndCron = new Cron('thermostatBathroomGndCron', thermostatBathroomGnd, [ {cronTime: '00 00 06 * * 1-5', output: '21.0'}, @@ -213,9 +215,11 @@ thermostatBathroomGndCron.start() let windowContactBathroom1st = new MaxWindowContact('1st', 'Bathroom', 'WindowContact', 'Fenster Bad oben', 2) windowContactBathroom1st.start() +allLabeledItems.push(windowContactBathroom1st) let thermostatBathroom1st = new MaxThermostat('1st', 'Bathroom', 'Thermostat', 'Thermostat Bad oben', 3, [windowContactBathroom1st]) thermostatBathroom1st.start() +allLabeledItems.push(thermostatBathroom1st) let thermostatBathroom1stCron = new Cron('thermostatBathroom1stCron', thermostatBathroom1st, [ {cronTime: '00 00 06 * * 1-5', output: '21.0'}, @@ -230,16 +234,21 @@ thermostatBathroom1stCron.start() let windowContactKitchen1 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact1', 'Fenster Küche Garten', 11) windowContactKitchen1.start() +allLabeledItems.push(windowContactKitchen1) let windowContactKitchen2 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact2', 'Fenster Küche Terassentür Garten', 10) windowContactKitchen2.start() +allLabeledItems.push(windowContactKitchen2) let windowContactKitchen3 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact3', 'Fenster Küche Straße 1', 12) windowContactKitchen3.start() +allLabeledItems.push(windowContactKitchen3) let windowContactKitchen4 = new MaxWindowContact('Gnd', 'Kitchen', 'WindowContact4', 'Fenster Küche Straße 2', 13) windowContactKitchen4.start() +allLabeledItems.push(windowContactKitchen4) let thermostatKitchen = new MaxThermostat('Gnd', 'Kitchen', 'Thermostat', 'Thermostat Küche', 14, [ windowContactKitchen1, windowContactKitchen2, windowContactKitchen3, windowContactKitchen4]) thermostatKitchen.start() +allLabeledItems.push(thermostatKitchen) let thermostatKitchenCron = new Cron('thermostatKitchenCron', thermostatKitchen, [ {cronTime: '00 00 06 * * 1-5', output: '21.0'},