Change Dimmer Level Without Turning it Off then On?

I’ve been doing a lot of work with the REST API and trying to get some URLs setup so that I can use them in Tasker. I am now at a point though that my Z-Wave dimmer switch will not change its level until it is turned off then back on. So my update level function looks like this:

private void updateLvl(devices) {
log.debug "update, request: params: ${params}, devices: $devices.id, levl: ${params.param4}"

//def command = request.JSON?.command
def command = params.command
def lvel = params.lvl
log.debug "level: ${params.lvl}"
//let's create a toggle option here
if (command) 
{

	def device = devices.find { it.id == params.id }
	if (!device) {
		httpError(404, "Device not found")
	} else {
        	
            if(command == "toggle")
            {
                if(device.currentValue('switch') == "on"){
                  device.setLevel(lvel)
                  device.off()
                  }
                else{
                  device.setLevel(lvel)
            		device.off()
                	device.on();
            	}
            }
            else
            {
            	device.setLevel(lvel)
            	device.off()
                device."$command"()
            }
       
	}
}

}

Special thanks to @NickW for the hint about doing this and @korban_hadley for the idea! And of course, thanks to @csader for the tasker>ST tutorial that @Ben reposted.

After I get this working, I will be publishing an extended version of the original SmartApp and PHP file that will hopefully help some of those that needed info like myself. SmartApp REST API for Tasker(I was wanting to get Tasker to grab the current status of stuff and interact with it based on other criteria, like leaving a geoFence around the end of my work shift, popping up and asking me if I’m headed home. If so, send a remote command to tasker on my HA tablet then do things like set the Nest thermostat. Once I scan the NFC badge in my car as I enter my subdivision, my garage will open, the garage door will unlock and if it’s near or after dark, the side lights will come on. Once it detects that I’ve entered into my house, it’ll ask if I want to watch today’s news and will turn the TV on and change to the channel if I reply yes.) Anyways, dreams to be… I want this dang dimmer to work first. Any help is appreciated!

1 Like

I am also in need of presetting dimmer levels, been on my wish list for a month…

Well I can set dimmer levels and even get their current status but I can’t get it to apply a new dimmer level if the switch is on without it first needing to be turned off after setting the new level. Is what happens is I have to:
1 set new level
2 turn switch off
3 turn switch back on

It is frustrating because the api should be able to do everything the app can do without these little caveats. It looks like the tasked automation demo has actually got the dimmers to adjust without a need for them to flash off then back on.

I hope to have a semi complete api ready soon. I haven’t touched locks though because I don’t have one to test with.