homematic switch

This commit is contained in:
Wolfgang Hottgenroth
2018-01-04 20:17:58 +01:00
parent 5bc7892c86
commit eb9e2acc30
2 changed files with 45 additions and 2 deletions

View File

@ -0,0 +1,39 @@
let logger = require('./log');
let mqtt = require('./mqttHandler');
let AHomematicItem = require('./AHomematicItem')
class HomematicSwitchItem extends AHomematicItem {
constructor(floor, room, item, hmId) {
super(floor, room, item, hmId);
this.stateTopic = `${this.topicFirstPart}/state`;
this.stateFeedbackTopic = `${this.topicFirstPart}/state/feedback`;
this.actionTopic = `${this.actionTopicPre}/1/STATE`;
this.subscribeTopics = [
this.stateTopic
];
this.state = 'OFF';
this.oldState = undefined;
}
processMessage(topic, payload) {
switch (topic) {
case this.stateTopic:
this.state = payload;
mqtt.send(this.stateFeedbackTopic, this.state);
if (this.state != this.oldState) {
if (this.state == 'ON') {
mqtt.send(this.actionTopic, 'true');
} else {
mqtt.send(this.actionTopic, 'false');
}
this.oldState = this.state;
}
break;
}
}
}
module.exports = HomematicSwitchItem;

View File

@ -6,6 +6,7 @@ logger.info("Hello world!");
let HomematicDimmerItemClass = require('./HomematicDimmerItem'); let HomematicDimmerItemClass = require('./HomematicDimmerItem');
let HomematicSwitchItemClass = require('./HomematicSwitchItem');
let M433SwitchItem = require('./M433SwitchItem'); let M433SwitchItem = require('./M433SwitchItem');
let HomematicFourButtonThing = require('./HomematicFourButtonThing'); let HomematicFourButtonThing = require('./HomematicFourButtonThing');
let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem'); let HomematicFourButtonSingleItem = require('./HomematicFourButtonSingleItem');
@ -24,7 +25,7 @@ let testFourButton = new HomematicFourButtonThing('Gnd', 'Hallway', 'TestButton'
new HomematicFourButtonSingleItem('button2', 'test/button/2'), new HomematicFourButtonSingleItem('button2', 'test/button/2'),
new HomematicFourButtonSingleItem('button3', 'test/button/3'), new HomematicFourButtonSingleItem('button3', 'test/button/3'),
new HomematicFourButtonSingleItem('button4', 'test/button/4') new HomematicFourButtonSingleItem('button4', 'test/button/4')
]) ]);
testFourButton.start(); testFourButton.start();
let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight'); let testDimmerAdaptor = new DimmerAdaptor('Gnd', 'Hallway', 'Testlight');
@ -33,8 +34,11 @@ testDimmerAdaptor.start();
let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8); let testLight = new HomematicDimmerItemClass('Gnd', 'Hallway', 'Testlight', 8);
testLight.start(); testLight.start();
let testLight2 = new HomematicSwitchItemClass('Gnd', 'Hallway', 'Testlight2', 5);
testLight2.start();
let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [ let testForwarder = new Forwarder('Gnd', 'Hallway', 'TestForwarder', 'state', [
'dispatcher_ng/items/Gnd/Hallway/Testlight/state', 'dispatcher_ng/items/Gnd/Hallway/Testlight2/state',
'dispatcher_ng/items/Gnd/Hallway/DeskLight/state' 'dispatcher_ng/items/Gnd/Hallway/DeskLight/state'
]); ]);
testForwarder.start(); testForwarder.start();