EcoSwitch

This commit is contained in:
Wolfgang Hottgenroth
2018-01-12 10:50:25 +01:00
parent 5eac6dfab6
commit c474d22265
6 changed files with 143 additions and 1 deletions

66
src/MaxEcoSwitch.ts Normal file
View File

@ -0,0 +1,66 @@
import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { AHomematicItem } from './AHomematicItem'
import { LightScene } from './Scene'
export class MaxEcoSwitch extends AHomematicItem {
private ecoTopic: string
private mainTopic: string
private buttonTopic2: string
private buttonTopic1: string
private state: string
constructor(floor: string, room: string, item: string, label: string, hmId: number,
mainScene: LightScene, ecoScene: LightScene) {
super(floor, room, item, label, hmId)
this.buttonTopic1 = `${this.deviceTopicPre}/1/PRESS`
this.buttonTopic2 = `${this.deviceTopicPre}/2/PRESS`
this.subscribeTopics = [ this.buttonTopic1, this.buttonTopic2 ]
this.mainTopic = mainScene.getStateTopic()
this.ecoTopic = ecoScene.getStateTopic()
this.state = 'OFF'
}
processMessage(topic: string, payload: string) : void {
switch(this.state) {
case 'OFF':
if (topic == this.mainTopic) {
this.state = 'ON'
} else if (topic == this.ecoTopic) {
this.state = 'ECO'
}
break
case 'ON':
if (topic == this.mainTopic) {
this.state = 'OFF'
} else if (topic == this.ecoTopic) {
this.state = 'ECO'
}
break
case 'ECO':
if (topic == this.mainTopic) {
this.state = 'ON'
} else if (topic == this.ecoTopic) {
this.state = 'OFF'
}
break
}
switch(this.state) {
case 'OFF':
mqttHandler.send(this.mainTopic, 'OFF')
break
case 'ON':
mqttHandler.send(this.mainTopic, 'ON')
break
case 'ECO':
mqttHandler.send(this.ecoTopic, 'ON')
break
}
}
}

View File

@ -3,7 +3,7 @@ import * as logger from './log'
import { mqttHandler } from './MqttDispatcher'
import { ExportType, SwitchExport } from './Export'
export class LightScene extends AItem {
export class LightScene extends AItem implements HasStateAndFeedbackTopic {
private onFeedbackTopics: string[]
private offFeedbackTopics: string[]
private onTopics: string[]
@ -17,6 +17,13 @@ export class LightScene extends AItem {
private onItems: HasStateAndFeedbackTopic[]
private myLastFeedbackState: string
getStateTopic() {
return this.stateTopic
}
getStateFeedbackTopic() {
return this.stateFeedbackTopic
}
constructor(floor: string, room: string, item: string, label: string = '',
onItems: HasStateAndFeedbackTopic[], offItems: HasStateAndFeedbackTopic[]) {
super(floor, room, item, label)

View File

@ -14,6 +14,7 @@ import { HomematicDimmerItem } from './HomematicDimmerItem'
import { HomematicSwitchItem } from './HomematicSwitchItem'
import { Forwarder } from './Forwarder'
import { LightScene } from './Scene'
import { MaxEcoSwitch } from './MaxEcoSwitch'
logger.info("Dispatcher starting")
@ -158,6 +159,9 @@ let ecoLightScene = new LightScene('Gnd', 'Hallway', 'EcoLight', 'EcoLight',
ecoLightScene.start()
allLabeledItems.push(ecoLightScene)
let ecoSwitch = new MaxEcoSwitch('Gnd', 'Hallway', 'EcoSwitch', 'EcoSwitch', 5, dayLightScene, ecoLightScene)
ecoSwitch.start()
let morningLightScene = new LightScene('Gnd', 'Hallway', 'MorningLight', 'MorningLight',
[
kitchenWindowLight, kitchenCeilingLight, hallwayDeskLight, hallwayWardrobeLight,