Let’s look at the “hook” DTH. It is a http-only (not zwave or zigbee) dth. Has a single tile with two states, “on” and “off”. Two commands, consistent with the switch capability, on() and off() The dth does not receive any messages from the physical device, and so it does not know the state of the physical door.
The dth also does not generate any “events”. Events, in ST, are notifications seen by the hub and smartapps. In a dth like this, events are traditionally created and sent by the command methods (as opposed to within the parse method). Events generated by a switch dth would be [name: “switch”, value: “on”] and [name: “switch”, value: “off”].
You’re using a contact sensor to determine if the door is open or closed. Need to have a helper app subscribe to “contact” events from the contact sensor and send the events to the door dth. The door dth will then create/send the state of the door (except it sees it as a “switch”) and its own UI will reflect the state.
Further suggested revision:
The dth should use a different capability, capability.doorControl
http://docs.smartthings.com/en/latest/capabilities-reference.html?highlight=capabilities#door-control
The commands would be open() and close(), the attribute name would be “door” and the states “unknown” “closed” “open” “closing” “opening”.
The dth would sendEvent of opening/closing while the helper app would notify the dth when the state should be changed to open/closed based on the contact sensor. Should also add a delay to correspond to how long the door takes to open (since contact sensor “open” event will fire at the beginning of the opening action, not once the door is fully opened).
I have not run these, so there might be errors – let me know.
Helper app:
/**
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*
*/
definition(
name: "Hook helper",
namespace: "gkl-sf",
author: "gkl_sf",
description: "Hook helper",
category: "Convenience",
iconUrl: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience.png",
iconX2Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png",
iconX3Url: "https://s3.amazonaws.com/smartapp-icons/Convenience/Cat-Convenience@2x.png")
preferences {
section {
input "hookDevice", "capability.switch", title: "Select the hook device", required: true, multiple: false
input "doorSensor", "capability.contactSensor", title: "Select the contact sensor", required: true, multiple: false
}
}
def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}
def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}
def initialize() {
subscribe(doorSensor, "contact", sensorHandler)
}
def sensorHandler(evt) {
hookDevice.statusReceive(evt)
}
DTH:
/**
* Copyright 2015 SmartThings
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
* for the specific language governing permissions and limitations under the License.
*
*/
metadata {
definition (name: "Hook", namespace: "smartthings", author: "BeckyR") {
capability "Switch"
command "statusReceive", ["string"] //added a custom command for helper app to send door status to the dth
}
// tile definitions -- changed labels to Open and Closed
tiles {
standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
state "on", label: "Open", action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
state "off", label: "Closed", action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
}
main "switch"
details "switch"
}
}
def parse(String description) {
log.error "This device does not support incoming events"
return null
}
def on() {
put('On')
}
def off() {
put('Off')
}
private put(toggle) {
def params = [
uri: "https://api.gethook.io/v1/device/trigger/${device.deviceNetworkId}/${toggle}/?token=yourhooktoken"
]
httpGet(params)
}
def statusReceive(evt) {
if (evt == "open") switchValue = "on"
else if (evt == "closed") switchValue = "off"
sendEvent(name: "switch", value: switchValue, descriptionText: "Door is ${evt}")
}