/* Dimmer-Switch Levels-Reset.device.groovy
*
* Variation of the stock SmartThings "Dimmer-Switch"
* Variation of the twack "Better-Dimmer-Switch"
* Variation of the bravenel "Dimmer Switch with Reset"
* Variation of the ChadCK "Z-Wave Smart Fan Control"
*
* Device type adds set levels low, medium, and High for preset levels (Moods).
* Adds increment up and down buttons, hardcoded to increment by 10.
*
* pmjoen@yahoo.com
* 20160501
*
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "Dimmer-Switch-Levels-Reset", namespace: "pmjoen", author: "SmartThings") {
capability "Switch Level"
capability "Actuator"
capability "Indicator"
capability "Switch"
capability "Polling"
capability "Refresh"
capability "Sensor"
command "low"
command "med"
command "high"
command "levelUp"
command "levelDown"
command "resetLevel"
// fingerprint inClusters: "0x26"
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
status "09%": "command: 2003, payload: 09"
status "10%": "command: 2003, payload: 0A"
status "33%": "command: 2003, payload: 21"
status "66%": "command: 2003, payload: 42"
status "99%": "command: 2003, payload: 63"
// reply messages
reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
reply "200100,delay 5000,2602": "command: 2603, payload: 00"
reply "200119,delay 5000,2602": "command: 2603, payload: 19"
reply "200132,delay 5000,2602": "command: 2603, payload: 32"
reply "20014B,delay 5000,2602": "command: 2603, payload: 4B"
reply "200163,delay 5000,2602": "command: 2603, payload: 63"
}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4
, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "default", label:'ADJUSTING', action:"refresh.refresh", icon:"st.Lighting.light24", backgroundColor:"#2179b8", nextState: "turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "LOW", label:'LOW', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
attributeState "MED", label:'MED', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
attributeState "HIGH", label:'HIGH', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
}
tileAttribute("device.switch", key: "VALUE_CONTROL") {
attributeState("VALUE_UP", action: "levelUp")
attributeState("VALUE_DOWN", action: "levelDown")
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
}
standardTile("indicator", "device.indicatorStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
}
standardTile("low", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#ffffff"
state "ADJUSTING.LOW", label:'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#2179b8"
state "LOW", label:'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#79b821"
}
standardTile("med", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff"
state "ADJUSTING.MED", label:'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#2179b8"
state "MED", label: 'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#79b821"
}
standardTile("high", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#ffffff"
state "ADJUSTING.HIGH", label:'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#2179b8"
state "HIGH", label: 'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#79b821"
}
main(["switch"])
details(["switch", "low", "med", "high", "level", "indicator", "refresh"])
}
preferences {
section("Light Thresholds") {
input "lowThreshold", "number", title: "Low Light Level", range: "1..99"
input "medThreshold", "number", title: "Medium Light Level", range: "1..99"
input "highThreshold", "number", title: "High Light Level", range: "1..99"
}
}
}
def parse(String description) {
def item1 = [
canBeCurrentState: false,
linkText: getLinkText(device),
isStateChange: false,
displayed: false,
descriptionText: description,
value: description
]
def result
def cmd = zwave.parse(description, [0x20: 1, 0x26: 1, 0x70: 1])
if (cmd) {
result = createEvent(cmd, item1)
}
else {
item1.displayed = displayed(description, item1.isStateChange)
result = [item1]
}
log.debug "Parse returned ${result?.descriptionText}"
result
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelStartLevelChange cmd, Map item1) {
[]
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelStopLevelChange cmd, Map item1) {
[response(zwave.basicV1.basicGet())]
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelSet cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
result[0].descriptionText = "${item1.linkText} is ${item1.value}"
result[0].handlerName = cmd.value ? "statusOn" : "statusOff"
for (int i = 0; i < result.size(); i++) {
result[i].type = "digital"
}
log.trace "SwitchMultilevelReport"
result
}
def doCreateEvent(physicalgraph.zwave.Command cmd, Map item1) {
def result = [item1]
def lowThresholdvalue = (settings.lowThreshold != null && settings.lowThreshold != "") ? settings.lowThreshold.toInteger() : 33
def medThresholdvalue = (settings.medThreshold != null && settings.medThreshold != "") ? settings.medThreshold.toInteger() : 67
def highThresholdvalue = (settings.highThreshold != null && settings.highThreshold != "") ? settings.highThreshold.toInteger() : 99
item1.name = "switch"
item1.value = cmd.value ? "on" : "off"
if (item1.value == "off") {
sendEvent(name: "currentState", value: "OFF" as String)
}
item1.handlerName = item1.value
item1.descriptionText = "${item1.linkText} was turned ${item1.value}"
item1.canBeCurrentState = true
item1.isStateChange = isStateChange(device, item1.name, item1.value)
item1.displayed = false
if (cmd.value) {
def item2 = new LinkedHashMap(item1)
item2.name = "level"
item2.value = cmd.value as String
item2.unit = "%"
item2.descriptionText = "${item1.linkText} dimmed ${item2.value} %"
item2.canBeCurrentState = true
item2.isStateChange = isStateChange(device, item2.name, item2.value)
item2.displayed = false
if (item2.value.toInteger() <= lowThresholdvalue) { sendEvent(name: "currentState", value: "LOW" as String) }
if (item2.value.toInteger() >= lowThresholdvalue+1 && item2.value.toInteger() <= medThresholdvalue) { sendEvent(name: "currentState", value: "MED" as String) }
if (item2.value.toInteger() >= medThresholdvalue+1) { sendEvent(name: "currentState", value: "HIGH" as String) }
result << item2
}
log.trace "doCreateEvent"
result
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
def value = "when off"
if (cmd.configurationValue[0] == 1) {value = "when on"}
if (cmd.configurationValue[0] == 2) {value = "never"}
[name: "indicatorStatus", value: value, display: false]
}
def createEvent(physicalgraph.zwave.Command cmd, Map map) {
// Handles any Z-Wave commands we aren't interested in
log.debug "UNHANDLED COMMAND $cmd"
}
def on() {
log.info "on"
delayBetween([zwave.basicV1.basicSet(value: 0xFF).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def off() {
delayBetween ([zwave.basicV1.basicSet(value: 0x00).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def setLevel(value) {
log.debug "Setting the level to: ${value}"
def lowThresholdvalue = (settings.lowThreshold != null && settings.lowThreshold != "") ? settings.lowThreshold.toInteger() : 33
def medThresholdvalue = (settings.medThreshold != null && settings.medThreshold != "") ? settings.medThreshold.toInteger() : 75
def highThresholdvalue = (settings.highThreshold != null && settings.highThreshold != "") ? settings.highThreshold.toInteger() : 99
if (value == "LOW") { value = lowThresholdvalue }
if (value == "MED") { value = medThresholdvalue }
if (value == "HIGH") { value = highThresholdvalue }
def level = Math.min(value as Integer, 99)
log.trace "lowThreshold(value): ${lowThreshold}"
if (level == lowThresholdvalue){
sendEvent(name: "switch", value: "low")
}
if (level == medThresholdvalue){
sendEvent(name: "switch", value: "med")
}
if (level == highThresholdvalue){
sendEvent(name: "switch", value: "high")
}
if (level == 0){
sendEvent(name: "switch", value: "off")
}
sendEvent(name: "level", value: level, unit: "%")
log.trace "setLevel(value): ${level}"
if (level == lowThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.LOW" as String, displayed: false) }
if (level == medThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.MED" as String, displayed: false) }
if (level == highThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.HIGH" as String, displayed: false) }
delayBetween ([zwave.basicV1.basicSet(value: level as Integer).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1000)
}
def setLevel(value, duration) {
log.debug "Firing the multi arg version"
def lowThresholdvalue = (settings.lowThreshold != null && settings.lowThreshold != "") ? settings.lowThreshold.toInteger() : 20
def medThresholdvalue = (settings.medThreshold != null && settings.medThreshold != "") ? settings.medThreshold.toInteger() : 50
def highThresholdvalue = (settings.highThreshold != null && settings.highThreshold != "") ? settings.highThreshold.toInteger() : 80
if (value == "LOW") { value = lowThresholdvalue }
if (value == "MED") { value = medThresholdvalue }
if (value == "HIGH") { value = highThresholdvalue }
def level = Math.min(value as Integer, 99)
def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
def getStatusDelay = duration < 128 ? (duration*1000)+2000 : (Math.round(duration / 60)*60*1000)+2000
log.trace "setLevel(value): ${level}"
if (level == lowThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.LOW" as String, displayed: false) }
if (level == medThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.MED" as String, displayed: false) }
if (level == highThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.HIGH" as String, displayed: false) }
zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: dimmingDuration).format()
}
def resetLevel(value) {
def level = Math.min(value as Integer, 99)
delayBetween ([
delayBetween ([ zwave.basicV1.basicSet(value: level).format(),
zwave.basicV1.basicSet(value: 0x00).format()], 10),
zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def levelUp(){
int nextLevel = device.currentValue("level") + 10.0
if( nextLevel > 100){
nextLevel = 99
}
log.debug "Setting dimmer level up to: ${nextLevel}"
delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1500)
}
def levelDown(){
int nextLevel = device.currentValue("level") - 10.0
if (nextLevel < 0){
nextLevel = 0
}
if (nextLevel == 0){
off()
}
else
{
log.debug "Setting dimmer level down to: ${nextLevel}"
delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1500)
}
}
def low() {
setLevel("LOW")
}
def med() {
setLevel("MED")
}
def high() {
setLevel("HIGH")
}
def poll() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def refresh() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def indicatorWhenOn() {
sendEvent(name: "indicatorStatus", value: "when on", display: false)
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()
}
def indicatorWhenOff() {
sendEvent(name: "indicatorStatus", value: "when off", display: false)
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()
}
def indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", display: false)
zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()
}
def invertSwitch(invert=true) {
if (invert) {
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
}
else {
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
}
}
what parts of this aren’t working?
I can’t get the status of the switch to change in the detail and the level up and level down produce an error in the log
Got the status update to work as well as the level up and down but still have the following issues:
- Reset level is not occurring upon turning off.
- Buttons for low, med, high i need them to not be active if the light is not on and only display active if on and at the value specified for the threshold.
This forum uses “Markdown” formatting … Please surround your code with 3 backquotes or use the </>
formatting option, or link to GitHub.
Result:
Backquote example:
def indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", display: false)
zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()
}
Thanks!
I am doing all the code in the IDE not sure how to get it onto github…
He means when you post code on the community page, Highlight it all then press the </>
formatting button to make it look pretty. It would look like this:
/* Dimmer-Switch Levls-Reset.device.groovy
*
* Variation of the stock SmartThings "Dimmer-Switch"
* Variation of the twack "Better-Dimmer-Switch"
* Variation of the bravenel "Dimmer Switch with Reset"
* Variation of the ChadCK "Z-Wave Smart Fan Control"
*
* Device type adds set levels low, medium, and High for preset levels (Moods).
* adds increment up and down buttons. Hardcoded to increment by 10.
*
* pmjoen@yahoo.com
* 20160501
*
*/
metadata {
// Automatically generated. Make future change here.
definition (name: "Dimmer-Switch-Levels-Reset", namespace: "pmjoen", author: "SmartThings") {
capability "Switch Level"
capability "Actuator"
capability "Indicator"
capability "Switch"
capability "Polling"
capability "Refresh"
capability "Sensor"
command "low"
command "med"
command "high"
command "levelUp"
command "levelDown"
command "resetLevel"
// fingerprint inClusters: "0x26"
}
simulator {
status "on": "command: 2003, payload: FF"
status "off": "command: 2003, payload: 00"
status "09%": "command: 2003, payload: 09"
status "10%": "command: 2003, payload: 0A"
status "33%": "command: 2003, payload: 21"
status "66%": "command: 2003, payload: 42"
status "99%": "command: 2003, payload: 63"
// reply messages
reply "2001FF,delay 5000,2602": "command: 2603, payload: FF"
reply "200100,delay 5000,2602": "command: 2603, payload: 00"
reply "200119,delay 5000,2602": "command: 2603, payload: 19"
reply "200132,delay 5000,2602": "command: 2603, payload: 32"
reply "20014B,delay 5000,2602": "command: 2603, payload: 4B"
reply "200163,delay 5000,2602": "command: 2603, payload: 63"
}
tiles(scale: 2) {
multiAttributeTile(name:"switch", type: "lighting", width: 6, height: 4
, canChangeIcon: true){
tileAttribute ("device.switch", key: "PRIMARY_CONTROL") {
attributeState "default", label:'ADJUSTING', action:"refresh.refresh", icon:"st.Lighting.light24", backgroundColor:"#2179b8", nextState: "turningOff"
attributeState "on", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "off", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "turningOn", label:'${name}', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState:"turningOff"
attributeState "turningOff", label:'${name}', action:"switch.on", icon:"st.switches.switch.off", backgroundColor:"#ffffff", nextState:"turningOn"
attributeState "LOW", label:'LOW', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
attributeState "MED", label:'MED', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
attributeState "HIGH", label:'HIGH', action:"switch.off", icon:"st.switches.switch.on", backgroundColor:"#79b821", nextState: "turningOff"
}
tileAttribute("device.switch", key: "VALUE_CONTROL") {
attributeState("VALUE_UP", action: "levelUp")
attributeState("VALUE_DOWN", action: "levelDown")
}
tileAttribute ("device.level", key: "SLIDER_CONTROL") {
attributeState "level", action:"switch level.setLevel"
}
}
standardTile("indicator", "device.indicatorStatus", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "when off", action:"indicator.indicatorWhenOn", icon:"st.indicators.lit-when-off"
state "when on", action:"indicator.indicatorNever", icon:"st.indicators.lit-when-on"
state "never", action:"indicator.indicatorWhenOff", icon:"st.indicators.never-lit"
}
standardTile("refresh", "device.switch", width: 2, height: 2, inactiveLabel: false, decoration: "flat") {
state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
}
valueTile("level", "device.level", inactiveLabel: false, decoration: "flat", width: 2, height: 2) {
state "level", label:'${currentValue} %', unit:"%", backgroundColor:"#ffffff"
}
standardTile("low", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#ffffff"
state "LOW", label:'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#79b821"
state "ADJUSTING.LOW", label:'LOW', action: "low", icon:"st.Weather.weather4", backgroundColor: "#2179b8"
}
standardTile("med", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#ffffff"
state "MED", label: 'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#79b821"
state "ADJUSTING.MED", label:'MED', action: "med", icon:"st.illuminance.illuminance.light", backgroundColor: "#2179b8"
}
standardTile("high", "device.currentState", inactiveLabel: false, width: 2, height: 2) {
state "default", label: 'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#ffffff"
state "HIGH", label: 'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#79b821"
state "ADJUSTING.HIGH", label:'HIGH', action: "high", icon:"st.illuminance.illuminance.bright", backgroundColor: "#2179b8"
}
main(["switch"])
details(["switch", "low", "med", "high", "level", "indicator", "refresh"])
}
preferences {
section("Light Thresholds") {
input "lowThreshold", "number", title: "Low Light Level", range: "1..99"
input "medThreshold", "number", title: "Medium Light Level", range: "1..99"
input "highThreshold", "number", title: "High Light Level", range: "1..99"
}
}
}
def parse(String description) {
def item1 = [
canBeCurrentState: false,
linkText: getLinkText(device),
isStateChange: false,
displayed: false,
descriptionText: description,
value: description
]
def result
def cmd = zwave.parse(description, [0x20: 1, 0x26: 1, 0x70: 1])
if (cmd) {
result = createEvent(cmd, item1)
}
else {
item1.displayed = displayed(description, item1.isStateChange)
result = [item1]
}
log.debug "Parse returned ${result?.descriptionText}"
result
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.basicv1.BasicSet cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelStartLevelChange cmd, Map item1) {
[]
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelStopLevelChange cmd, Map item1) {
[response(zwave.basicV1.basicGet())]
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelSet cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
for (int i = 0; i < result.size(); i++) {
result[i].type = "physical"
}
result
}
def createEvent(physicalgraph.zwave.commands.switchmultilevelv1.SwitchMultilevelReport cmd, Map item1) {
def result = doCreateEvent(cmd, item1)
result[0].descriptionText = "${item1.linkText} is ${item1.value}"
result[0].handlerName = cmd.value ? "statusOn" : "statusOff"
for (int i = 0; i < result.size(); i++) {
result[i].type = "digital"
}
result
}
def doCreateEvent(physicalgraph.zwave.Command cmd, Map item1) {
def result = [item1]
item1.name = "switch"
item1.value = cmd.value ? "on" : "off"
item1.handlerName = item1.value
item1.descriptionText = "${item1.linkText} was turned ${item1.value}"
item1.canBeCurrentState = true
item1.isStateChange = isStateChange(device, item1.name, item1.value)
item1.displayed = item1.isStateChange
if (cmd.value >= 5) {
def item2 = new LinkedHashMap(item1)
item2.name = "level"
item2.value = cmd.value as String
item2.unit = "%"
item2.descriptionText = "${item1.linkText} dimmed ${item2.value} %"
item2.canBeCurrentState = true
item2.isStateChange = isStateChange(device, item2.name, item2.value)
item2.displayed = false
result << item2
}
result
}
def zwaveEvent(physicalgraph.zwave.commands.configurationv1.ConfigurationReport cmd) {
def value = "when off"
if (cmd.configurationValue[0] == 1) {value = "when on"}
if (cmd.configurationValue[0] == 2) {value = "never"}
[name: "indicatorStatus", value: value, display: false]
}
def createEvent(physicalgraph.zwave.Command cmd, Map map) {
// Handles any Z-Wave commands we aren't interested in
log.debug "UNHANDLED COMMAND $cmd"
}
def on() {
log.info "on"
delayBetween([zwave.basicV1.basicSet(value: 0xFF).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def off() {
delayBetween ([zwave.basicV1.basicSet(value: 0x00).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def setLevel(value) {
log.debug "Setting the level to: ${value}"
def lowThresholdvalue = (settings.lowThreshold != null && settings.lowThreshold != "") ? settings.lowThreshold.toInteger() : 33
def medThresholdvalue = (settings.medThreshold != null && settings.medThreshold != "") ? settings.medThreshold.toInteger() : 75
def highThresholdvalue = (settings.highThreshold != null && settings.highThreshold != "") ? settings.highThreshold.toInteger() : 99
if (value == "LOW") { value = lowThresholdvalue }
if (value == "MED") { value = medThresholdvalue }
if (value == "HIGH") { value = highThresholdvalue }
def level = Math.min(value as Integer, 99)
if (level > 0) {
sendEvent(name: "switch", value: "on")
}
if (level == lowThreshold){
sendEvent(name: "switch", value: "low")
}
if (level == medThreshold){
sendEvent(name: "switch", value: "med")
}
if (level == highThresholdvalue){
sendEvent(name: "switch", value: "high")
}
if (level == 0){
sendEvent(name: "switch", value: "off")
}
sendEvent(name: "level", value: level, unit: "%")
log.trace "setLevel(value): ${level}"
if (level == lowThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.LOW" as String, displayed: false) }
if (level == medThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.MED" as String, displayed: false) }
if (level == highThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.HIGH" as String, displayed: false) }
delayBetween ([zwave.basicV1.basicSet(value: level as Integer).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1000)
}
def setLevel(value, duration) {
log.debug "Firing the multi arg version"
def lowThresholdvalue = (settings.lowThreshold != null && settings.lowThreshold != "") ? settings.lowThreshold.toInteger() : 20
def medThresholdvalue = (settings.medThreshold != null && settings.medThreshold != "") ? settings.medThreshold.toInteger() : 50
def highThresholdvalue = (settings.highThreshold != null && settings.highThreshold != "") ? settings.highThreshold.toInteger() : 80
if (value == "LOW") { value = lowThresholdvalue }
if (value == "MED") { value = medThresholdvalue }
if (value == "HIGH") { value = highThresholdvalue }
def level = Math.min(value as Integer, 99)
def dimmingDuration = duration < 128 ? duration : 128 + Math.round(duration / 60)
def getStatusDelay = duration < 128 ? (duration*1000)+2000 : (Math.round(duration / 60)*60*1000)+2000
log.trace "setLevel(value): ${level}"
if (level == lowThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.LOW" as String, displayed: false) }
if (level == medThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.MED" as String, displayed: false) }
if (level == highThresholdvalue) { sendEvent(name: "currentState", value: "ADJUSTING.HIGH" as String, displayed: false) }
zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: dimmingDuration).format()
}
def resetLevel(value) {
def level = Math.min(value as Integer, 99)
delayBetween ([
delayBetween ([ zwave.basicV1.basicSet(value: level).format(),
zwave.basicV1.basicSet(value: 0x00).format()], 10),
zwave.switchMultilevelV1.switchMultilevelGet().format()], 5000)
}
def levelUp(){
int nextLevel = device.currentValue("level") + 10.0
if( nextLevel > 100){
nextLevel = 100
}
log.debug "Setting dimmer level up to: ${nextLevel}"
delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1500)
}
def levelDown(){
int nextLevel = device.currentValue("level") - 10.0
if (nextLevel < 5){
nextLevel = 0
}
if (nextLevel == 0){
off()
}
else
{
log.debug "Setting dimmer level down to: ${nextLevel}"
delayBetween ([zwave.basicV1.basicSet(value: nextLevel).format(), zwave.switchMultilevelV1.switchMultilevelGet().format()], 1500)
}
}
def low() {
setLevel("LOW")
}
def med() {
setLevel("MED")
}
def high() {
setLevel("HIGH")
}
def poll() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def refresh() {
zwave.switchMultilevelV1.switchMultilevelGet().format()
}
def indicatorWhenOn() {
sendEvent(name: "indicatorStatus", value: "when on", display: false)
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 3, size: 1).format()
}
def indicatorWhenOff() {
sendEvent(name: "indicatorStatus", value: "when off", display: false)
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 3, size: 1).format()
}
def indicatorNever() {
sendEvent(name: "indicatorStatus", value: "never", display: false)
zwave.configurationV1.configurationSet(configurationValue: [2], parameterNumber: 3, size: 1).format()
}
def invertSwitch(invert=true) {
if (invert) {
zwave.configurationV1.configurationSet(configurationValue: [1], parameterNumber: 4, size: 1).format()
}
else {
zwave.configurationV1.configurationSet(configurationValue: [0], parameterNumber: 4, size: 1).format()
}
}
instead of the three " you posted it should have been three of these ` I.E.
```
{Code here}
```
You can copy / paste into a “new file” in GitHub as a temporary measure until you integrate your SmartThings Account with GitHub and/or install a Windows/Mac git client like SourceTree.
Copy / Paste to/from the IDE is right now not a bad way to manually use GitHub.
I have modified the original post with the updated code. The only issue I am facing now is the Low, Med, High tiles are updating even though the threshold value is not equal. Im still new, please be kind…
I’m definitely going to be kind and nice, even if my posts are short and sound kurt, ok?
-
Can you describe what happens in more detail?
-
I’m wondering if there is some value to stub-down the code a bit (unless you already have?) in order to get it to work for simplest of cases. e.g., instead of ranges of dimmers, hard-code values for low, med, high. This is what I’ve had to do for all my Device Type development. Build up from something simple that works, until it breaks…
What I wanted out of this device type:
- Be able to turn on/off dimmer light.
- Have slider to provide quick level set.
- Be able to turn up/down dimmer by increments of 10
- Have a parameter value for low, med, high that will quickly set accurate level of the dimmer.
- Show level value of dimmer light.
- Set the indicator light.
- Refresh the dimmer light status.
All of these are working, but I’m running into one last issue and its more of an annoyance cause it looks bad.
If you change the value on the slider to something other than a threshold value the low, med, high tiles should show the default status. For some reason it is showing the on status depending on where the level is.
There are a few other UI things I would like to do but I wanted to fix that last bug. I know the functionality is overkill but I like the flexibility.
You must be sending an Event that is triggering the Tile, right?
This comes up a lot, but I never have built a solution myself. The idea I always offer is to use a “shadow attribute” that you can control when to keep in sync. I’m not sure it is possible, but ?
ie, the Tile attribute is different than the real attribute. When the tile is clicked, you change both, otherwise you leave the tile attribute unchanged (at the default value).
Maybe too complicated or impossible, but eventually SmartThings will have HTML5 tiles/cards support.