Skip to content
9 changes: 6 additions & 3 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,8 +195,12 @@ function handleSubscribeEvent (req, res) {
subscriptions = [];
Object.keys(req.body.devices).forEach(function (property) {
req.body.devices[property].forEach(function (device) {
subscriptions.push(getTopicFor(device, property, TOPIC_COMMAND));
subscriptions.push(getTopicFor(device, property, TOPIC_WRITE_STATE));
var cmdTopic = getTopicFor(device, property, TOPIC_COMMAND);
var writeTopic = getTopicFor(device, property, TOPIC_WRITE_STATE);
subscriptions.push(cmdTopic);
if (writeTopic !== cmdTopic) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice catch!

subscriptions.push(writeTopic);
}
});
});

Expand Down Expand Up @@ -258,7 +262,6 @@ function parseMQTTMessage (topic, message) {
device = pieces[0],
property = pieces[1],
topicReadState = getTopicFor(device, property, TOPIC_READ_STATE),
topicWriteState = getTopicFor(device, property, TOPIC_WRITE_STATE),
topicSwitchState = getTopicFor(device, 'switch', TOPIC_READ_STATE),
topicLevelCommand = getTopicFor(device, 'level', TOPIC_COMMAND);

Expand Down
15 changes: 11 additions & 4 deletions smartapps/stj/mqtt-bridge.src/mqtt-bridge.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ import groovy.transform.Field
capability: "capability.contactSensor",
attributes: [
"contact"
]
],
action: "actionOpenClosed"
],
"doorControl": [
name: "Door Control",
Expand Down Expand Up @@ -611,11 +612,17 @@ def actionColor(device, attribute, value) {
}
}

//Action for contactSensors,doorControl,garageDoors,valve and windowShades.
//contactSensors don't have action but a simulated contact sensor can hence the hasCommand() check.
def actionOpenClosed(device, attribute, value) {
if (value == "open") {
device.open()
if (device.hasCommand("open")) {
device.open()
}
} else if (value == "closed") {
device.close()
if (device.hasCommand("close")) {
device.close()
}
}
}

Expand Down Expand Up @@ -721,4 +728,4 @@ def actionTimedSession(device, attribute, value) {
if (attribute == "timeRemaining") {
device.setTimeRemaining(value)
}
}
}