Capture switch event when already on/off?

I want to be able to determine when a switch button is pressed, but when the switch is ‘on’, and I press the ‘on’ button again, all I see in the log is this:

Parsed BasicReport(value: 66) to [name:level, value:66, unit:%, isStateChange:false, displayed:false, linkText:Bedroom Fan Lights, descriptionText:Bedroom Fan Lights level is 66%]

Is there no way in a smartapp to have it receive the notice of button pressed when already on and take some secondary action? (found a post that said you can not, but that was in 2015).

Thanks,
Marc

Assuming you are talking about an smartThings integrated switch…

If you have access to the Device Handler code and Smart App Code, there may be something to do. Essentially, you have two options, both requiring modifying some code:

a. Modify the device handler to access a parent routine when the press is detected, then write the smart app code to with the external action, or

b. Set the on/off event to hard code “isStateChange” to true (This may adversely impact other functions in smartThings by too many false state changes being reported!) (Not recommended.)

awesome thanks… can you point me to any examples of (a)? I have access to the code as I’ve had to load a custom device handler anyways (Leviton Decora Z-Wave Plus Dimmer by jasonxh)

I do not have an explicit example. Part is what are your explicitly trying to accomplish. I do notice that driver you mention does not have a Service Manager. May or may not complicate, depending on what you are trying to do. For example, doing another action within the device, sending a SMS message, etc. Talking to other devices will take some thinking - but I think it can be done.

What are you trying to do?

I was hoping to capture the second ‘on’ command to then set the dim level to 100%.
Default on is the last dimmer setting… which I like/don’t mind. However, having to press and hold the dimmer control to get to max brightness takes longer than i’d like and would be great to just be able to hit the ‘on’ button again and have it go to 100 instantly (well, as fast as the processing goes :slight_smile: )

That is easy. I assume set the level to 100%. I will look at code and provide instructions to test (probably tomorrow - I am releasing some code currently).

1 Like

Here is the modified sections. Starting at line 238 in your current code, there are two methods: on and off. You will first turn off the light. Then, replace these two methods with the below, save, and publish. The timer is set for 5 seconds, so if you press within 5 seconds, it will go to 100% brightness. However, if you double press too fast, it may fail (the state may not update in time).

We may have to tweak or it may not work at all. It should work; however.

Code:

> def on() {
>     def fadeOnTime = device.currentValue("fadeOnTime")
>     def presetLevel = device.currentValue("presetLevel")
> 
>     short duration = fadeOnTime == null ? 255 : fadeOnTime
>     short level = presetLevel == null || presetLevel == 0 ? 0xFF : toZwaveLevel(presetLevel as short)
>     delayBetween([
>             zwave.switchMultilevelV2.switchMultilevelSet(value: level, dimmingDuration: duration).format(),
>             zwave.switchMultilevelV1.switchMultilevelGet().format()
>     ], durationToSeconds(duration) * 1000 + commandDelayMs)
> 
> //	NEW CODE FOR DUAL PRESS
> 	state.onTimer = "on"
> 	runIn(5, onTimerOff)
> //	END NEW CODE
> 
> }
> 
> def off() {
> 
> //	NEW CODE FOR DUAL PRESS
> 	if (state.onTimer == "on") {
> 		setLevel(100)
> 	}
> //	END NEW CODE
> 
>     def fadeOffTime = device.currentValue("fadeOffTime")
> 
>     short duration = fadeOffTime == null ? 255 : fadeOffTime
>     delayBetween([
>             zwave.switchMultilevelV2.switchMultilevelSet(value: 0x00, dimmingDuration: duration).format(),
>             zwave.switchMultilevelV1.switchMultilevelGet().format()
>     ], durationToSeconds(duration) * 1000 + commandDelayMs)
> }
> 
> 
> //	START NEW METHOD
> def onTimerOff() {
> 	state.onTimer = "off"
> }
> //	END NEW METHOD
2 Likes