Background:
I have recently installed Leviosa Shades. It does work in the new ST app but not in the Classic app.
I noticed that Leviosa creates a device for each shade group but they don’t have a device type. ie. “placeholder”. After playing around with those devices and trying different device handlers, I realized that some other shades like Springs will actually work meaning if I change the Leviosa shades to that device type, I’m able to open/close the shades via the classic app. (by tapping on the tile icon).
However, unfortunately, the routines/automations doesn’t work (e.g. I cannot open the shades automatically at sunrise).
After some research and debugging I realized the automation routines calls a method called setLevel()
and this is why it doesn’t work because Leviosa shades (and many others) do not support that.
Therefore, I decided to create my own DH and implement setLevel too.
Ok, here’s the actual question:
In the classic app, when we tap on a tile, apparently SmartThings sends an action command to the device (i.e “open”/“close”) and then calls the corresponding method in the DH. All I want to do is doing the same in the setLevel method. Directly calling open() or close() doesn’t work as it doesn’t actually send the command to the device itself. All I know is that ST sends an “open” or “close” action and that must be generic because I didn’t do any coding for it.
Does anyone know how to accomplish that?
Here’s the DH code that can open/close the shade:
metadata {
definition (name: "sk-generic-window-shade", namespace: "sk", author: "sk", cstHandler: true) {
capability "Window Shade"
}
simulator {
}
tiles {
standardTile("switchmain", "device.windowShade") {
state "open", label:'${name}', action:"close", icon:"st.shades.shade-open", backgroundColor:"#79b821", nextState:"closing"
state "closed", label:'${name}', action:"open", icon:"st.shades.shade-closed", backgroundColor:"#ffffff", nextState:"opening"
state "partially open", label:'Open', action:"close", icon:"st.shades.shade-open", backgroundColor:"#79b821", nextState:"closing"
state "opening", label:'${name}', action:"stop", icon:"st.shades.shade-opening", backgroundColor:"#79b821"
state "closing", label:'${name}', action:"stop", icon:"st.shades.shade-closing", backgroundColor:"#ffffff"
}
main(["switchmain"])
}
}
def parse(String description) {
log.debug "Parsing '${description}'"
}
// handle commands
def open() {
log.debug ">>> Executing 'open'"
}
def close() {
log.debug ">>> Executing 'close'"
}
def pause() {
log.debug ">>> Executing 'pause'"
}
def setLevel(level) {
//send "open" or "close" commands to the device based on the given level
//direct calling close() or open() doesn't work
}
P.S. I’m a software engineer and been using ST since 2014 but I’m new to writing device handlers.