Try to write a smart app for garage opener

hi

I am trying to write a small apps that do on/off/on/off for a switch that will activate a garage opener,
but if i use subscribe i get into an endless loop/ anyone have idea how to do it ?

Where are you getting an endless loop? Do you have code already written?

Also, I have a WebCoRE piston already written for this. I was thinking about porting it to groovy but awesome you’re getting started. I can share the Piston for the logic I use.

Can you share your code and also why you need to write a smartapp for that?

To me, a Device Handler is responsible to On/Off a device. I made several. Some are just sending the On/Off without transitions, some send the command and wait the device to acknowledge it to modify state.
Now a Smartapp would be there to manage event in order to connect other devices or sent notifications but I would not have it managing the on/off as it will basically send a Off upon reception of a On event and vice versa. That’s maybe what happens to you.

hi Phiplippe

see the code i did a trick to avoid the loop but it is not working good :frowning_face:
can you send an example for device handler that do switch on/off/on/off with 2 sec delay between each state

Copyright 2015 SmartThings
*

  • Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  •  http://www.apache.org/licenses/LICENSE-2.0
    
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
  • Garage Door Opener
  • Author: SmartThings
    */
    definition(
    name: “My Garage Door Opener”,
    namespace: “smartthings”,
    author: “SmartThings”,
    description: “Open your garage door when a switch is turned on.”,
    category: “Convenience”,
    iconUrl: “https://s3.amazonaws.com/smartapp-icons/Meta/garage_outlet.png”,
    iconX2Url: “https://s3.amazonaws.com/smartapp-icons/Meta/garage_outlet@2x.png
    )

preferences {
section(“When the garage door switch is turned on, open the garage door…”) {
input “outlet1”, “capability.switch”
}
}

def installed() {
subscribeToCommand(outlet1, “on”, onCommand)
}

def updated() {
unsubscribe()
subscribeToCommand(outlet1, “on”, onCommand)
}

def onCommand(evt) {
unsubscribe()
log.debug “event name: ${evt.name}”
log.debug “event value: ${evt.value}”
log.debug “onCommand1: $evt.value, $evt”
outlet1?.off(delay: 2000)
log.debug “onCommand2: $evt.value, $evt”
outlet1?.on(delay: 2000)
log.debug “onCommand3: $evt.value, $evt”
outlet1?.off(delay: 2000)
runIn( 8, mySubscribe )
}

def mySubscribe () {
// subscribe(outlet1, “switch”, handlerMethod)
subscribeToCommand(outlet1, “on”, onCommand)

}

def appTouchHandler(evt) {
log.debug “appTouch: $evt.value, $evt”
outlet1?.on()

}

austin,

i shared the code below i am not familiar with WebCore will try to read on that.
can you share the piston for the logic?

Here’s the piston I use. Also a scan from when I was coming up with the logic. I use my door with a FortrezZ MIMOLite, a momentary relay. Some considerations had to be taken into account.

-Disable command Optimizations - Sends the "on event even if the relay is already on. More of a WebCoRE thing and not important to Groovy.
-Refresh command is sent 2 seconds after event. This is done as a means to try to keep the relay state right because it turns off faster than ST refreshes. A linear opener won’t have this issue.