Open mike1237 opened 6 years ago
For what it's worth, I've modified the Go Control Switch's Device Handler to include the button number in the event payload. However, it appears that most button devices include the button number in the data portion of an event payload, rather than the value portion.
createEvent(name: "button", value: "pushed $button", data: [buttonNumber: button], descriptionText: "$device.displayName button $button was pushed", isStateChange: true)
Notice (including my modification of $button):
value: "pushed $button"
And:
data: [buttonNumber: button]
By including the data portion of the event in the MQTT message by default would fix this out of the box.
Here's an updated version of the inputHandler function in the smartapp that I modified to account for button numbers. I don't have my github linked back to SmartThings to submit a proper pull request but I welcome anyone to clean up this code and commit it if it works. It specifically targets button events so it should have no effect on other types.
With this change implemented, button presses have their name extended from "button" to "button <number>
". For example, I have a Homeseer HS-WS100+ in the living room that I have the double and triple tap functions mapped to various things. A double tap down is received by SmartThings as a press of button 2. The event is then published to the topic with the exact button name.
smartthings/Living Room Ceiling Fan/button pushed
becomes
smartthings/Living Room Ceiling Fan/button 2 pushed
// Receive an event from a device
def inputHandler(evt) {
if (
state.ignoreEvent
&& state.ignoreEvent.name == evt.displayName
&& state.ignoreEvent.type == evt.name
&& state.ignoreEvent.value == evt.value
) {
log.debug "Ignoring event ${state.ignoreEvent}"
state.ignoreEvent = false;
}
else {
// If we're dealing with a button (even a single button device),
// it's pretty likely that the data contains a buttonNumber specifying which button
def name = null
if ( evt.name == "button" ) {
def data = parseJson(evt.data)
name = "${evt.name} ${data.buttonNumber}"
}
else {
name = evt.name
}
def json = new JsonOutput().toJson([
path: "/push",
body: [
name: evt.displayName,
value: evt.value,
type: name
]
])
log.debug "Forwarding device event to bridge: ${json}"
bridge.deviceNotification(json)
}
}
Thank you so much for this example, @dgz. I came here to create an issue requesting the bridge to properly relay the individual button presses for my HS-WD200+ dimmers and HS-WS200+ switches. The tweak to the inputHandler method worked beautifully.
Hopefully this will get integrated into the branch so I don't have to maintain this manual tweak in the future.
Thanks again!
All,
I'm reopening Issue #35 to report that the bridge does not properly transmit button device information. Using a GoControl WA00Z-1 Z-Wave Wireless Light Switch with two buttons, each button push event results in the same MQTT message, making it impossible to discern which button was pushed.
Issue #35 was closed because the discussion started to focus on the Aeon Minimote, and a workaround was discovered by modifying the Device Handler for the Aeon Minimote, which obviously will not resolve the issue for other button devices, like the GoControl Wireless Switch that I use.
Please let me know if I can provide any further information.
Thanks,