Echo Integration

Thanks in advance for any help. I have combined the smartthings shield, an arduino uno and a remote control for my bedroom overhead fan and light to create a smartthings controllable light and fan. The device handler and arduino code mimics a button press. While clicking the buttons within the app works well o turn on and off the lights and fan, I can not integrate the lights or fan into any routines or have it controlled y my Amazon echo. This is my first attempt at smartthings coding. Below is the device handler code. Any help or suggestions on what I may have done wrong would be greatly appreciated.

/*original code which I hijacked was…

  • On/Off Shield (example)
  • Author: urman
  • Date: 2013-03-14
  • Revision: 2014-07-10
  • Capabilities:
  • Switch
  • Custom Attributes:
  • button
  • Custom Commands
  • hello
  • goodbyehello
    */

metadata {
definition (name: “Fan and Light Handler v4 add momentary press”, author: “jlevatino”) {
capability "Switch"
capability "Momentary"
command "lightToggle"
command "fanOff"
command "fanLow"
command "fanMed"
command “fanHigh”
//command "goodbye"
attribute “button”,“string”
}

tiles(scale: 2) {
standardTile(“switch”, “device.switch”, width: 1, height: 1, canChangeIcon: true, canChangeBackground: true) {
state “lights”, label: ‘Light’, action: “lightToggle”, icon: “st.Lighting.light11”, backgroundColor: “#79b821
}
standardTile(“lightToggleTile”, “push.momentary”, width: 3, height: 3, canChangeIcon: true, canChangeBackground: true) {
state “on”, label: ‘Light’, action: “lightToggle”, icon: “st.Lighting.light11”, backgroundColor: “#79b922
//state “on2”, label: ‘Light’, action: “lightToggle”, icon: “st.Lighting.light11”, backgroundColor: “#79b888”, nextState:“on”
}
standardTile(“fanOffTile”, “device.button”, width: 3, height: 3, canChangeIcon: true, canChangeBackground: true) {
state “default”, label: ‘Off’, action: “fanOff”, icon: “st.Lighting.light24”, backgroundColor: “#FF0000
}
standardTile(“fanLowTile”, “device.button”, width: 3, height: 3, canChangeIcon: true, canChangeBackground: true) {
state “default”, label: ‘Low’, action: “fanLow”, icon: “st.Lighting.light24”, backgroundColor: “#79b821
}
standardTile(“fanMedTile”, “device.button”, width: 3, height: 3, canChangeIcon: true, canChangeBackground: true) {
state “default”, label: ‘Med’, action: “fanMed”, icon: “st.Lighting.light24”, backgroundColor: “#79b821
}
standardTile(“fanHighTile”, “device.button”, width: 3, height: 3, canChangeIcon: true, canChangeBackground: true) {
state “default”, label: ‘High’, action: “fanHigh”, icon: “st.Lighting.light24”, backgroundColor: “#79b821
}

	main "switch"
	details(["lightToggleTile","fanOffTile", "fanLowTile", "fanMedTile", "fanHighTile"])
}
simulator {
    status "on":  "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
    status "off": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"

    // reply messages
    reply "raw 0x0 { 00 00 0a 0a 6f 6e }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6E"
    reply "raw 0x0 { 00 00 0a 0a 6f 66 66 }": "catchall: 0104 0000 01 01 0040 00 0A21 00 00 0000 0A 00 0A6F6666"
}

}

Map parse(String description) {

def value = zigbee.parse(description)?.text
def linkText = getLinkText(device)
def descriptionText = getDescriptionText(description, linkText, value)
def handlerName = value
def isStateChange = value != "ping"
def displayed = value && isStateChange

def result = [
	value: value,
	name: value in ["on","off"] ? "switch" : (value && value != "ping" ? "button" : null),
	handlerName: handlerName,
	linkText: linkText,
	descriptionText: descriptionText,
	isStateChange: isStateChange,
	displayed: displayed
]

log.debug result.descriptionText
result

}

//def on() {
// zigbee.smartShield(text: “on”).format()
//}

//def off() {
// zigbee.smartShield(text: “off”).format()
//}

def lightToggleMain() {
log.debug "Lights"
zigbee.smartShield(text: “lightToggle”).format()
}

def lightToggle() {
log.debug "Lights"
zigbee.smartShield(text: “lightToggle”).format()

}

def fanOff() {
log.debug "Fan Off"
zigbee.smartShield(text: “fanOff”).format()
}

def fanLow() {
log.debug "Fan Low"
zigbee.smartShield(text: “fanLow”).format()
}

def fanMed() {
log.debug "Hello World!"
zigbee.smartShield(text: “fanMed”).format()
}

def fanHigh() {
log.debug "Hello World!"
zigbee.smartShield(text: “fanHigh”).format()
}

def parse(String description) {
log.debug “Parsing ‘${description}’”
// TODO: handle ‘switch’ attribute
// TODO: handle ‘button’ attribute

}

I can’t read your code (I rely on text to speech) but if the device is controllable from the official SmartThings mobile app, you should be able to use it with echo just like any other device. However, you do have to individually authorize each device through the mobile app before echo can use it. I can’t read your code (I rely on text to speech) but if the device is controllable from the official SmartThings mobile app, you should be able to use it with echo just like any other device. However, you do have to individually authorize each device through the mobile app before echo can use it. This is true anytime you add a new device, regardless of type.

See step 10 in post one of the echo set up FAQ:

If you do see your devices listed in your Alexa app, they just don’t work, then that’s more likely to be a coding issue and others should be able to help.

Another possibility is that the devices are not of a device class that echo recognizes. It can only provide direct control of switches, bulbs, and thermostats. Again, I can’t read your code, but if it doesn’t show up as capability.switch, echo probably can’t see it.

The usual workaround for that is to create a virtual switch and smart things and have that then control the actual device that you want. That’s how people do things like garage doors. But again, others can look and see what your code is actually doing. :sunglasses:

Thank you JD. The device does show up in the Alexa app and when asked, Alexa says ok and “attempts” to toggle the switch.I think it may be the coding as I have used push.momentary instead of an actual on off switch in the code since the app would never know if the lights were on or off. Perhaps a device which acquires power from the light socket and goes between the bulb and the socket would be a possible way to solve the status issue in the future. I may need to change how the button is virtually pressed. Since there is a physical push button on the wall for the lights and each fan level, I initially thought this would be a better solution since the fan and lights can be controlled physically and digitally. (This was a must for my girlfriend to be on board).