Exposing push buttons in the mobile app and integrations

smartapp
echo

(Rick Spickelmier) #1

What am I doing wrong here? I have created a virtual pushbutton and assigned it to a smartapp that I published and configured. The smartapp triggers routines (Good Night! Good Morning! etc.) and the pushbutton calls the smartapp to trigger the routine. Pushing the button in the iOS application does trigger the appropriate routine so that all works.

The plan is to expose this pushbutton to IFTTT and Alexa integrations so I can trigger routines from these integrations (i.e., “Alexa, trigger Good Morning”). The problem is that while I can see my push button in the ‘My Home -> Things’ panel, I don’t see it in the ‘Dashboard -> Lights and Switches’ panel, and I don’t see it in the ‘Amazon Echo’ SmartApp list of switches. I assume it has something to do with it being a pushbutton rather than an off/on switch.

Any ideas here?


(Rick Spickelmier) #2

Here are the other images of the panels… as a new user I can only put in one image per post :slight_smile:


(Rick Spickelmier) #3


(Kevin) #4

I’m assuming by “pushbutton” you’re referring to the “Momentary” capability. If that’s the case, the easiest solution is to add the Switch Capability to your DTH and implement it something like:

def on() {
    sendEvent(name: "switch", value: "on", isStateChange: true, displayed: false)
}

def off() {
    sendEvent(name: "switch", value: "off", isStateChange: true, displayed: false)
}

def push() {
    on()    
    sendEvent(name: "momentary", value: "pushed", isStateChange: true, displayed:false)
    off()
}

(Rick Spickelmier) #5

Thanks! I ended up hacking it - changing my simulated pushbutton to a simulated switch and having the event handler ‘on’ event immediately turn off the switch. That allowed me to export the switch via the Alexa SmartApp and import into Alexa… “Alexa, turn on Good Night”, “Alexa, turn on Good Morning”

/**

  • Routine Trigger 2
  • Copyright 2016 Rick Spickelmier
  • 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: “Routine Trigger 2”,
namespace: “spickelmier”,
author: “Rick Spickelmier”,
description: “Trigger SmartThings routines from switches”,
category: “”,
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 {
page(name: “configure”)
}

def configure() {
dynamicPage(name: “configure”, title: “Configure Switch and Routine”, install: true, uninstall: true) {
section(“Select your switch”) {
input “theswitch”, “capability.switch”, required: true
}

        def actions = location.helloHome?.getPhrases()*.label
        if (actions) {
            actions.sort()
            section("Routine to Trigger") {
                log.trace actions
                input "onAction", "enum", title: "Routine to execute when button pushed", options: actions, required: true
            }
        }
}

}

def installed() {
log.debug "Installed with settings: ${settings}"
initialize()
}

def updated() {
log.debug "Updated with settings: ${settings}"
unsubscribe()
initialize()
}

def initialize() {
subscribe(theswitch, “switch”, handler)
log.debug “selected on routine $onAction”
}

def handler(evt) {
if (evt.value == “on”) {
log.debug "switch turned on, will execute routine ${settings.onAction}"
location.helloHome?.execute(settings.onAction)
theswitch.off();
}
}


(Kevin) #6

fyi, if you select all your code after pasting it and click the </> button, it will display it as a single block of code.