I'm fairly new to Hubitat and nowhere ready to dive into developing device drivers. I'm looking for an Alexa virtual button driver similar to:
but that includes two buttons instead of one: turning switch ON would set button to 1 and turning it off would set button to 2,
or something equivalent. It would act as a switch and momentary button that Alexa can deal with.
I tried making a modified version of Mikee385's driver and failed miserably - the device seemed to work OK, but RM would choke during rule creation process.
I'm hoping this is a common enough requirement that this type of driver already exists. Does anyone know of one? Any help would be greatly appreciated.
This is the type of RM error I was getting:
> PMerrorgroovy.lang.MissingMethodException: No signature of method: java.lang.String.call() is applicable for argument types: (java.lang.Integer) values: [5]
> Possible solutions: take(int), wait(), any(), wait(long), wait(long, int), charAt(int) on line 3302 (method doActPage)
Here was my attempt at the modified driver (I changed "number of buttons" to 2 and modified the ON and OFF methods to invoke push(1) and push(2) respectively:
/**
- Virtual Alexa Button Driver
- Copyright 2020 Michael Pierce
- 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.
*/
String getVersionNum() { return "1.2.0" }
String getVersionLabel() { return "Virtual Alexa Button, version ${getVersionNum()} on ${getPlatform()}" }
metadata {
definition (
name: "Virtual Alexa Button",
namespace: "mikee385",
author: "Michael Pierce",
importUrl: "https://raw.githubusercontent.com/mikee385/hubitat-mikee385/master/drivers/virtual-alexa-button.groovy"
) {
capability "Actuator"
capability "Contact Sensor"
capability "Momentary"
capability "PushableButton"
capability "Sensor"
capability "Switch"
command "push", ["number"]
}
}
def installed() {
initialize()
}
def updated() {
unschedule()
initialize()
}
def initialize() {
sendEvent(name: "numberOfButtons", value: 2)
}
def toggleOff() {
sendEvent(name: "switch", value: "off", isStateChange: true)
sendEvent(name: "contact", value: "closed", isStateChange: true)
}
def push(button) {
sendEvent(name: "switch", value: "on", isStateChange: true)
sendEvent(name: "contact", value: "open", isStateChange: true)
sendEvent(name: "pushed", value: "${button}", isStateChange: true, type: "digital")
runIn(1, toggleOff)
}
def push() {
push(1)
}
def on() {
push(1)
}
def off() {
push(2)
}