add summer/winter switch

This commit is contained in:
2018-04-09 15:53:38 +02:00
parent 00ba130010
commit b8dcece64e
7 changed files with 83 additions and 36 deletions

View File

@ -51,6 +51,11 @@ export function RelayBoxExport(itemId: string, stateTopicPre: string, feedbackTo
'openhab': RelayBoxOpenHABExport(itemId, stateTopicPre, feedbackTopicPre, conflictTopicPre, itemNames)}
}
export function SummerSwitchExport(summerSwitchTopic: string) : ExportType {
return {'homekit': {'id':'', 'object': {}},
'openhab': `Switch SummerSwitch "Winter?" {mqtt=">[localbroker:${summerSwitchTopic}:command:*:default],<[localbroker:${summerSwitchTopic}:state:default]"}`}
}
function RelayBoxHomekitExport(itemId: string, stateTopicPre: string, feedbackTopicPre: string, conflictTopicPre: string, itemNames: string[]) : HomekitExportType{
return {'id': '', 'object': {}}
}

View File

@ -3,11 +3,10 @@ import { mqttHandler } from './MqttDispatcher'
import { HasInTopic } from './AItem'
import { AHomegearItem } from './AHomegearItem'
// import { MaxWindowContact } from './MaxWindowContact';
import { ThermostatExport, ExportType } from './Export'
import { ThermostatExport, SummerSwitchExport, ExportType } from './Export'
import { Disabler } from './Disabler'
const DISABLED_TEMPERATURE = 5.0
const DISABLED_TEMPERATURE: number = 5.0
type DisabledHolder = {
disabler : Disabler
@ -27,6 +26,9 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
private hardDisabled: boolean
private commandTopic: string
static summerSwitchTopic : string = 'dispatcher_ng/items/summerSwitch'
private summerFlag: boolean = false
// Thermostat: homegear/instance1/set/3/1/SET_TEMPERATURE
getInTopic() : string {
@ -37,6 +39,10 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
return ThermostatExport(this.itemId, this.label, this.temperatureTopic, this.temperatureFeedbackTopic, this.presetTemperatureTopic, this.presetTemperatureFeedbackTopic)
}
static exportSummerSwitchItem() : ExportType|null {
return SummerSwitchExport(MaxThermostat.summerSwitchTopic)
}
constructor(floor: string, room: string, item: string, label: string, hmId: number, hardDisablers: Disabler[]) {
super(floor, room, item, label, hmId)
this.temperatureTopic = `${this.topicFirstPart}/temperature`
@ -50,7 +56,8 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
this.temperatureTopic,
this.presetTemperatureTopic,
this.deviceFeedbackTopic,
this.commandTopic
this.commandTopic,
MaxThermostat.summerSwitchTopic
]
this.hardDisabled = false
this.hardDisablerMap = {}
@ -74,12 +81,16 @@ export class MaxThermostat extends AHomegearItem implements HasInTopic {
this.temperature = parseFloat(payload)
setTemperature = true
} else if (topic == this.commandTopic) {
if (payload == 'ON') {
this.temperature = this.presetTemperature
} else if (payload == 'OFF') {
this.temperature = DISABLED_TEMPERATURE
if (! this.summerFlag) {
if (payload == 'ON') {
this.temperature = this.presetTemperature
} else if (payload == 'OFF') {
this.temperature = DISABLED_TEMPERATURE
}
setTemperature = true
}
setTemperature = true
} else if (topic == MaxThermostat.summerSwitchTopic) {
this.summerFlag = (payload == 'ON')
} else if (topic == this.presetTemperatureTopic) {
this.presetTemperature = parseFloat(payload)
mqttHandler.send(this.presetTemperatureFeedbackTopic, `${this.presetTemperature}`)

View File

@ -337,6 +337,8 @@ let relayBox = new RelayBoxThing('base', 'labor', 'relaybox', 'IoT/Command/Relay
relayBox.start()
allLabeledItems.push(relayBox)
// ----------------------------------------------------------------------------------------------------------
let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton', 9, [
new HomematicFourButtonSingleItem('dispatcher_ng/items/Gnd/Hallway/Testlight/dimmerIn'),
@ -398,6 +400,13 @@ allLabeledItems.forEach((item: AItem) => {
// logger.info(JSON.stringify(openhabList))
}
})
let summerSwitchExport : ExportType|null = MaxThermostat.exportSummerSwitchItem()
if (summerSwitchExport != null) {
let da : string = summerSwitchExport['openhab'] as string
openhabList.push(da)
}
fs.writeFileSync(config.dict.homekitFile, JSON.stringify(homekitObject, null, 4))
fs.writeFileSync(config.dict.openhabItemFile, openhabList.join('\n'))