Garage Door with Amazon Echo modification of "Ridiculously Automated Garage Door"

To use SmarttThings with an Amazon Echo devices need to be virtual switches. Since most of the garage door automation apps require doorControlers they are not compatible. I have forked the above code and modified it to use a ‘switch’ instead of a ‘doorControler’ making it compatible with an Echo. code can be found here https://github.com/dr-seth/SmartThings

1 Like

Folks could write their Garage Door Types to have both Capability Switch and Door Control, then custom SmartApp code not needed.

The Device Type can alias the on-open and off-close Commands (and Attributes…).

Let me know if this makes sense…

Makes sense to me… I’m not using a virtual switch on my door… But I am using your device type code… J/s

That’s what I’ve done, and it works nicely.

2 Likes

I’ve never done that before, how do I do it?

Depending upon what you are using for a garage door controller, you could create your own device type modeled exactly from ST’s, and then just add those capabilities. Here’s an example of mine (it’s for a MIMOLite):

https://raw.githubusercontent.com/constjs/SmartThings-Devices/master/mimolite_garage_door_v4.device.groovy

You’ll see where on, off, open, close, and push commands can be received because “switch”, “momentary”, and “door control” capabilities are there.

1 Like

Wouldn’t it be “safer” to have on() call open(), and off() call close()? … By just calling push(), you risk on() and off() leaving the door in an unknown state.

def on() {
	//push()
        open()    // Now we take advantage of all the code below!
}

def off() {
	//push()
        close()   //Ditto!
}

def open() {
	if (device.currentValue("contact") != "open") {
		log.debug "Sending ACTUATE event to open door"
		push()
	}
	else {
		log.debug "Not opening door since it is already open"
	}
}

def close() {
	if (device.currentValue("contact") != "closed") {
		log.debug "Sending ACTUATE event to close door"
		push()
	}
	else {
		log.debug "Not closing door since it is already closed"
	}
}

Hi @tgauchat , yes it would especially if a contact sensor isn’t incorporated into the device and someone was just tripping a relay. Since the mimolite device type gives contact state, I didn’t consider that. I’ll make the changes in case someone uses this not as I intended, or for codes examples.

1 Like

I’m using the “ST Anything” Arduino/ThingShield solution for my garage doors, which uses a virtual device for the door controller. It works fine with the RAGD app, but not with my Echo or any other smartapp/routine. Can anyone please help me modify this device type so I can get it working without using custom smartapps? https://github.com/DanielOgorchock/ST_Anything/blob/master/Groovy/VirtualDevices/VirtualDoorControl.device.groovy

1 Like

I posted a proposed modification. I’m am not fully aware of how the Shield is using this particular Virtual Device Type you supplied, but theorize that added “Capability Switch” is sufficient for Echo, IFTTT, SmartTiles, etc.

Here is a link to the GitHub changes:

And the complete file:

  • If it works, then please add my name (Terry Gauchat) to the Change History, with my GitHub handle @CosmicPuppy (and/or I will do a pull request to the original repository).

Let me know the results and any questions! Good-luck!

1 Like

First of all, thank you! I gave it a shot, the door did not open or close with the code as is, the virtual device tile did however change from closed to open and vice-versa immediately when I told Alexa to turn the door on/off. I then removed the comments on the following line, and tried push(), then actuate() in both the open/close sections, with no success either unfortunately.

**// push() // Not sure if calling push() or actuate() here is needed or not. Test without first. **

Not sure if you’ve had a look at the ST Anything project, essentially it uses virtual control devices in conjunction with a multiplexer app which then relays commands to/from the actual ThingShield device.

I know of it, but not specific use cases…

What SmartApp links the Virtual Switch to the Relay / ThingShield?

This is the one I use and it shows the garage door as a momentary switch, which works well with a lot of door control apps.

/**

  • Z-Wave Garage Door Opener
  • Copyright 2014 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: “My Z-Wave Garage Door Opener”, namespace: “smartthings”, author: “SmartThings”) {
capability "Actuator"
capability "Door Control"
capability "Contact Sensor"
capability "Refresh"
capability "Sensor"
capability "Polling"
capability "Switch"
capability "Momentary"
capability “Relay Switch”

	fingerprint deviceId: "0x4007", inClusters: "0x98"
	fingerprint deviceId: "0x4006", inClusters: "0x98"
}

simulator {
	status "closed": "command: 9881, payload: 00 66 03 00"
	status "opening": "command: 9881, payload: 00 66 03 FE"
	status "open": "command: 9881, payload: 00 66 03 FF"
	status "closing": "command: 9881, payload: 00 66 03 FC"
	status "unknown": "command: 9881, payload: 00 66 03 FD"

	reply "988100660100": "command: 9881, payload: 00 66 03 FC"
	reply "9881006601FF": "command: 9881, payload: 00 66 03 FE"
}

tiles {
	standardTile("toggle", "device.door", width: 2, height: 2) {
		state("unknown", label:'${name}', action:"refresh.refresh", icon:"st.doors.garage.garage-open", backgroundColor:"#ffa81e")
		state("closed", label:'${name}', action:"door control.open", icon:"st.doors.garage.garage-closed", backgroundColor:"#79b821", nextState:"opening")
		state("open", label:'${name}', action:"door control.close", icon:"st.doors.garage.garage-open", backgroundColor:"#ffa81e", nextState:"closing")
		state("opening", label:'${name}', icon:"st.doors.garage.garage-opening", backgroundColor:"#ffe71e")
		state("closing", label:'${name}', icon:"st.doors.garage.garage-closing", backgroundColor:"#ffe71e")
		
	}
	standardTile("open", "device.door", inactiveLabel: false, decoration: "flat") {
		state "default", label:'open', action:"door control.open", icon:"st.doors.garage.garage-opening"
	}
	standardTile("close", "device.door", inactiveLabel: false, decoration: "flat") {
		state "default", label:'close', action:"door control.close", icon:"st.doors.garage.garage-closing"
	}
	standardTile("refresh", "device.door", inactiveLabel: false, decoration: "flat") {
		state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
	}
	main "toggle"
	details(["toggle", "open", "close", "refresh"])
}

}

import physicalgraph.zwave.commands.barrieroperatorv1.*

def parse(String description) {
def result = null
if (description.startsWith(“Err”)) {
if (state.sec) {
result = createEvent(descriptionText:description, displayed:false)
} else {
result = createEvent(
descriptionText: “This device failed to complete the network security key exchange. If you are unable to control it via SmartThings, you must remove it from your network and add it again.”,
eventType: “ALERT”,
name: “secureInclusion”,
value: “failed”,
displayed: true,
)
}
} else {
def cmd = zwave.parse(description, [ 0x98: 1, 0x72: 2 ])
if (cmd) {
result = zwaveEvent(cmd)
}
}
log.debug “”$description" parsed to ${result.inspect()}"
result
}

def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityMessageEncapsulation cmd) {
def encapsulatedCommand = cmd.encapsulatedCommand([0x71: 3, 0x80: 1, 0x85: 2, 0x63: 1, 0x98: 1])
log.debug "encapsulated: $encapsulatedCommand"
if (encapsulatedCommand) {
zwaveEvent(encapsulatedCommand)
}
}

def zwaveEvent(physicalgraph.zwave.commands.securityv1.NetworkKeyVerify cmd) {
createEvent(name:“secureInclusion”, value:“success”, descriptionText:“Secure inclusion was successful”)
}

def zwaveEvent(physicalgraph.zwave.commands.securityv1.SecurityCommandsSupportedReport cmd) {
state.sec = cmd.commandClassSupport.collect { String.format("%02X “, it) }.join()
if (cmd.commandClassControl) {
state.secCon = cmd.commandClassControl.collect { String.format(”%02X “, it) }.join()
}
log.debug “Security command classes: $state.sec"
createEvent(name:“secureInclusion”, value:“success”, descriptionText:”$device.displayText is securely included”)
}

def zwaveEvent(BarrierOperatorReport cmd) {
def result = []
def map = [ name: “door” ]
def switchMap = [ name: “switch” ]

switch (cmd.barrierState) {
	case BarrierOperatorReport.BARRIER_STATE_CLOSED:
		map.value = "closed"
		result << createEvent(name: "contact", value: "closed", displayed: false)
        result << createEvent(name: "switch", value: "off", displayed: false)
		break
	case BarrierOperatorReport.BARRIER_STATE_UNKNOWN_POSITION_MOVING_TO_CLOSE:
		map.value = "closing"
		break
	case BarrierOperatorReport.BARRIER_STATE_UNKNOWN_POSITION_STOPPED:
		map.descriptionText = "$device.displayName door state is unknown"
		map.value = "unknown"
		break
	case BarrierOperatorReport.BARRIER_STATE_UNKNOWN_POSITION_MOVING_TO_OPEN:
		map.value = "opening"
		result << createEvent(name: "contact", value: "open", displayed: false)
		break
	case BarrierOperatorReport.BARRIER_STATE_OPEN:
		map.value = "open"
		result << createEvent(name: "contact", value: "open", displayed: false)
        result << createEvent(name: "switch", value: "on", displayed: false)
		break
}
result + createEvent(map)

}

def zwaveEvent(physicalgraph.zwave.commands.notificationv3.NotificationReport cmd) {
def result = []
def map = [:]
if (cmd.notificationType == 6) {
map.displayed = true
switch(cmd.event) {
case 0x40:
if (cmd.eventParameter[0]) {
map.descriptionText = “$device.displayName performing initialization process”
} else {
map.descriptionText = “$device.displayName initialization process complete”
}
break
case 0x41:
map.descriptionText = "$device.displayName door operation force has been exceeded"
break
case 0x42:
map.descriptionText = "$device.displayName motor has exceeded operational time limit"
break
case 0x43:
map.descriptionText = "$device.displayName has exceeded physical mechanical limits"
break
case 0x44:
map.descriptionText = "$device.displayName unable to perform requested operation (UL requirement)"
break
case 0x45:
map.descriptionText = "$device.displayName remote operation disabled (UL requirement)"
break
case 0x46:
map.descriptionText = "$device.displayName failed to perform operation due to device malfunction"
break
case 0x47:
if (cmd.eventParameter[0]) {
map.descriptionText = “$device.displayName vacation mode enabled”
} else {
map.descriptionText = “$device.displayName vacation mode disabled”
}
break
case 0x48:
if (cmd.eventParameter[0]) {
map.descriptionText = “$device.displayName safety beam obstructed”
} else {
map.descriptionText = “$device.displayName safety beam obstruction cleared”
}
break
case 0x49:
if (cmd.eventParameter[0]) {
map.descriptionText = “$device.displayName door sensor ${cmd.eventParameter[0]} not detected”
} else {
map.descriptionText = “$device.displayName door sensor not detected”
}
break
case 0x4A:
if (cmd.eventParameter[0]) {
map.descriptionText = “$device.displayName door sensor ${cmd.eventParameter[0]} has a low battery”
} else {
map.descriptionText = “$device.displayName door sensor has a low battery”
}
result << createEvent(name: “battery”, value: 1, unit: “%”, descriptionText: map.descriptionText)
break
case 0x4B:
map.descriptionText = "$device.displayName detected a short in wall station wires"
break
case 0x4C:
map.descriptionText = "$device.displayName is associated with non-Z-Wave remote control"
break
default:
map.descriptionText = "$device.displayName: access control alarm $cmd.event"
map.displayed = false
break
}
} else if (cmd.notificationType == 7) {
switch (cmd.event) {
case 1:
case 2:
map.descriptionText = "$device.displayName detected intrusion"
break
case 3:
map.descriptionText = "$device.displayName tampering detected: product cover removed"
break
case 4:
map.descriptionText = "$device.displayName tampering detected: incorrect code"
break
case 7:
case 8:
map.descriptionText = "$device.displayName detected motion"
break
default:
map.descriptionText = "$device.displayName: security alarm $cmd.event"
map.displayed = false
}
} else if (cmd.notificationType){
map.descriptionText = “$device.displayName: alarm type $cmd.notificationType event $cmd.event”
} else {
map.descriptionText = “$device.displayName: alarm $cmd.v1AlarmType is ${cmd.v1AlarmLevel == 255 ? ‘active’ : cmd.v1AlarmLevel ?: ‘inactive’}”
}
result ? [createEvent(map), *result] : createEvent(map)
}

def zwaveEvent(physicalgraph.zwave.commands.batteryv1.BatteryReport cmd) {
def map = [ name: “battery”, unit: “%” ]
if (cmd.batteryLevel == 0xFF) {
map.value = 1
map.descriptionText = “$device.displayName has a low battery”
} else {
map.value = cmd.batteryLevel
}
state.lastbatt = new Date().time
createEvent(map)
}

def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
def result = []

def msr = String.format("%04X-%04X-%04X", cmd.manufacturerId, cmd.productTypeId, cmd.productId)
log.debug "msr: $msr"
updateDataValue("MSR", msr)

result << createEvent(descriptionText: "$device.displayName MSR: $msr", isStateChange: false)
result

}

def zwaveEvent(physicalgraph.zwave.commands.versionv1.VersionReport cmd) {
def fw = "${cmd.applicationVersion}.${cmd.applicationSubVersion}"
updateDataValue(“fw”, fw)
def text = "$device.displayName: firmware version: $fw, Z-Wave version: ${cmd.zWaveProtocolVersion}.${cmd.zWaveProtocolSubVersion}"
createEvent(descriptionText: text, isStateChange: false)
}

def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationBusy cmd) {
def msg = cmd.status == 0 ? “try again later” :
cmd.status == 1 ? “try again in $cmd.waitTime seconds” :
cmd.status == 2 ? “request queued” : "sorry"
createEvent(displayed: true, descriptionText: “$device.displayName is busy, $msg”)
}

def zwaveEvent(physicalgraph.zwave.commands.applicationstatusv1.ApplicationRejectedRequest cmd) {
createEvent(displayed: true, descriptionText: “$device.displayName rejected the last request”)
}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
createEvent(displayed: false, descriptionText: “$device.displayName: $cmd”)
}

def open() {
secure(zwave.barrierOperatorV1.barrierOperatorSet(requestedBarrierState: BarrierOperatorSet.REQUESTED_BARRIER_STATE_OPEN))
}

def close() {
secure(zwave.barrierOperatorV1.barrierOperatorSet(requestedBarrierState: BarrierOperatorSet.REQUESTED_BARRIER_STATE_CLOSE))
}

def refresh() {
secure(zwave.barrierOperatorV1.barrierOperatorGet())
}

def poll() {
secure(zwave.barrierOperatorV1.barrierOperatorGet())
}

def on() {
log.debug “on() was called and ignored”
}

def off() {
log.debug “off() was called and ignored”
}

def push() {

// get the current "door" attribute value
//
// For some reason, I can't use "device.doorState" or just "doorState".  Not sure why not.

def lastValue = device.latestValue("door");

// if its open, then close the door
if (lastValue == "open") {
    return close()
    
// if its closed, then open the door
} else if (lastValue == "closed") {
    return open()
    
} else {
	log.debug "push() called when door state is $lastValue - there's nothing push() can do"
}

}

private secure(physicalgraph.zwave.Command cmd) {
zwave.securityV1.securityMessageEncapsulation().encapsulate(cmd).format()
}

private secureSequence(commands, delay=200) {
delayBetween(commands.collect{ secure(it) }, delay)
}

Try my garage door smartapp . I am using it in two locations and I modified the virtual device to also work with Alexa.

I’m using your app and it’s great but how do you modify the device to work with Alexa?

Thanks for your hard work! The garage door automation used to work great with my v1, been quite a chore to get it working with v2.