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, ExportType } from './Export' import { M433SwitchItem } from './M433SwitchItem' import { HomematicFourButtonThing, HomematicFourButtonSingleItem } from './HomematicFourButtonThing' import { DimmerAdaptor } from './DimmerAdaptor' import { TimerAdaptor } from './TimerAdaptor' import { HomematicDimmerItem } from './HomematicDimmerItem' import { HomematicSwitchItem } from './HomematicSwitchItem' import { Forwarder } from './Forwarder' import { LightScene } from './Scene' import { MaxEcoSwitch } from './MaxEcoSwitch' import { MaxThermostat } from './MaxThermostat' import { MaxWindowContact } from './MaxWindowContact' import { UrlSwitchItem } from './UrlSwitchItem' import { Cron } from './Cron' import { HueColorBulbItem } from './HueColorBulbItem' import { TouchSwitchMultiButtonThing, TouchSwitchButtonSingleItem } from './TouchSwitchMultiButtonThing' logger.info("Dispatcher starting") let allLabeledItems : Array = new Array() // 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) let aquariumLightCron = new Cron('aquariumLightCron', aquariumLight, [ {cronTime: '00 00 07 * * mon-fri', output: 'ON'}, {cronTime: '00 00 09 * * sat-sun', output: 'ON'}, {cronTime: '00 00 13 * * *', output: 'OFF'}, {cronTime: '00 00 14 * * *', output: 'ON'}, {cronTime: '00 00 22 * * *', output: 'OFF'} ]) aquariumLightCron.start() // 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', 'StandLight', 'Stehlampen Matthias', '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) // Esszimmer Regallicht let diningRoomShelfLight = new UrlSwitchItem('Gnd', 'DiningRoom', 'ShelfLight', 'Regallicht Esszimmer', 'http://regallampe/dv?dv=1023', 'http://regallampe/dv?dv=0') diningRoomShelfLight.start() allLabeledItems.push(diningRoomShelfLight) let diningRoomNaehkaestchenLight = new HueColorBulbItem('Gnd', 'DiningRoom', 'NaehkaestchenLight', 'Lampe Naehkaestchen', 15) diningRoomNaehkaestchenLight.start() allLabeledItems.push(diningRoomNaehkaestchenLight) // 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', 'WardrobeLight', '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') kitchenCeilingLight.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) let bedRoomWolfgangBedLight = new HueColorBulbItem('1st', 'BedRoom', 'WolfgangBedLight', 'Bettlicht', 16) bedRoomWolfgangBedLight.start() allLabeledItems.push(bedRoomWolfgangBedLight) let bedRoomWolfgangBedLightDimmerAdaptor = new DimmerAdaptor('1st', 'BedRoom', 'WolfgangBedLight') bedRoomWolfgangBedLightDimmerAdaptor.start() let touchSwitchMultiButtonThing = new TouchSwitchMultiButtonThing('1st', 'Bedroom', 'Wolfgang', [ new TouchSwitchButtonSingleItem(bedRoomWolfgangBedLightDimmerAdaptor.getInTopic())]) touchSwitchMultiButtonThing.start() // 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 windowContactBedroomStreet1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContactStreet', 'Fenster Schlafzimmer Strasse', 17) windowContactBedroomStreet1st.start() allLabeledItems.push(windowContactBedroomStreet1st) let windowContactBedroomGarden1st = new MaxWindowContact('1st', 'Bedroom', 'WindowContactGarden', 'Fenster Schlafzimmer Garten', 18) windowContactBedroomGarden1st.start() allLabeledItems.push(windowContactBedroomGarden1st) let thermostatBedroom1st = new MaxThermostat('1st', 'Bedroom', 'Thermostat', 'Thermostat Schlafzimmer', 19, [windowContactBedroomGarden1st, windowContactBedroomStreet1st]) thermostatBedroom1st.start() allLabeledItems.push(thermostatBedroom1st) let thermostatBedroom1stCron = new Cron('thermostatBedroom1stCron', thermostatBedroom1st, [ {cronTime: '00 00 06 * * mon-fri', output: '21.0'}, {cronTime: '00 00 09 * * mon-fri', output: '5.0'}, {cronTime: '00 00 08 * * sat-sun', output: '21.0'}, {cronTime: '00 00 11 * * sat-sun', output: '5.0'}, {cronTime: '00 00 17 * * *', output: '21.0'}, {cronTime: '00 59 23 * * *', output: '5.0'} ]) thermostatBedroom1stCron.start() // --------------------------------------------------------------------------------------------------------- let dayLightScene = new LightScene('Gnd', 'Hallway', 'DayLight', 'DayLight', [ kitchenWindowLight, kitchenCeilingLight, hallwayDeskLight, hallwayStandLight, hallwayWardrobeLight, diningRoomSmallLight, diningRoomStandLight, diningRoomCupboardLight, diningRoomShelfLight, livingRoomLargeLight, livingRoomSmallLight, livingRoomStars, livingRoomStandLight, diningRoomNaehkaestchenLight ], [] ) dayLightScene.start() allLabeledItems.push(dayLightScene) let ecoLightScene = new LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight', [ kitchenWindowLight, hallwayDeskLight, hallwayWardrobeLight, diningRoomSmallLight, diningRoomStandLight, diningRoomCupboardLight, diningRoomShelfLight, livingRoomStars, livingRoomStandLight, diningRoomNaehkaestchenLight ], [ kitchenCeilingLight, hallwayStandLight, livingRoomLargeLight, livingRoomSmallLight ] ) ecoLightScene.start() allLabeledItems.push(ecoLightScene) let ecoSwitch = new MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 6, dayLightScene, ecoLightScene) ecoSwitch.start() let morningLightScene = new LightScene('Gnd', 'Hallway', 'MorningLight', 'MorningLight', [ kitchenWindowLight, kitchenCeilingLight, hallwayDeskLight, hallwayWardrobeLight, hallwayStandLight ], [ diningRoomSmallLight, diningRoomStandLight, diningRoomCupboardLight, diningRoomShelfLight, livingRoomStars, livingRoomStandLight, livingRoomLargeLight, livingRoomSmallLight, diningRoomNaehkaestchenLight ] ) morningLightScene.start() 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 * * mon-fri', output: '21.0'}, {cronTime: '00 00 08 * * sat-sun', output: '21.0'}, {cronTime: '00 00 11 * * *', output: '5.0'}, {cronTime: '00 00 19 * * *', output: '21.0'}, {cronTime: '00 00 23 * * *', output: '5.0'} ]) 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 * * mon-fri', output: '21.0'}, {cronTime: '00 00 08 * * sat-sun', output: '21.0'}, {cronTime: '00 00 11 * * *', output: '5.0'}, {cronTime: '00 00 19 * * *', output: '21.0'}, {cronTime: '00 00 23 * * *', output: '5.0'} ]) 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 * * mon-fri', output: '19.0'}, {cronTime: '00 00 08 * * sat-sun', output: '19.0'}, {cronTime: '00 00 10 * * mon-wed', output: '5.0'}, {cronTime: '00 30 13 * * mon-wed', output: '19.0'}, {cronTime: '00 00 23 * * *', output: '5.0'} ]) thermostatKitchenCron.start() // ---------------------------------------------------------------------------------------------------------- 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'), new HomematicFourButtonSingleItem('test/button/3'), new HomematicFourButtonSingleItem('test/button/4') ]) testFourButton.start() let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight') testDimmerAdaptor.start() let testTimerAdaptor = new TimerAdaptor('Gnd', 'Hallway', 'DeskLight', 10) testTimerAdaptor.start() let testLight = new HomematicDimmerItem('Gnd', 'Hallway', 'Testlight', 'Testlampe mit Dimmer', 8) testLight.start() let testLight2 = new HomematicSwitchItem('Gnd', 'Hallway', 'Testlight2', 'Testlampe ohne Dimmer', 5) testLight2.start() let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', 'TestForwarder', [ 'dispatcher_ng/items/Gnd/Hallway/Testlight2/state', 'dispatcher_ng/items/Gnd/Hallway/DeskLight/state' ]) testForwarder.start() let testScene = new LightScene('Gnd', 'Hallway', 'TestScene', 'TestScene', [aquariumLight, annaBedLight], [matthiasStandLights, matthiasBedLight] ) testScene.start() // ---------------------------------------------------------------------------------------------------------- // Homekit export let homekitObject : { [key:string]:{} } = {} let openhabList : string[] = [] allLabeledItems.forEach((item: AItem) => { let exportData : ExportType|null = item.exportItem() if (exportData != null) { if ('id' in exportData['homekit']) { homekitObject[exportData['homekit']['id']] = exportData['homekit']['object'] } openhabList.push(exportData['openhab']) } }) fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4)) fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n')) // ---------------------------------------------------------------------------------------------------------- mqttHandler.exec() logger.info("Dispatcher running")