Timer that works in seconds?


(Victor Sanchez) #1

Hi every one!

I’m new into SmartThings so i apologies if this is to silly.

I’m looking for a timer that allow me to turn of a relay/switch after few seconds. 2 to 5 seconds to be correct.

Why? I have in my work shop a big ( 26 x 13 ft) gate I install a solenoid that allows me to open the door with a push of a button. And in my house something similar to this.

So i need to tell my Enerwave relay to start working and 2 or 5 seconds later stop working again. I try to make it work with a Virtual Momentary Device, Momentary Capability, etc, with out success, @RBoy Suggest i should use an smart app thats why i’m asking to all the forum.

Thanks for the helo in advance!!!


(Convinced ST will never be unbroken…) #2

Yes, a SmartApp can be designed to do this… but think about it. You ask SmartThings to turn the relay on, and 2 to 5 seconds later turn it off.

1.) Initial on request goes to SmartThings cloud, then back to your hub, and then to the switch.

2.) SmartApp sets a scheduled handler to turn the switch off in 3 seconds, scheduler is instantiated in the SmartThings cloud, scheduled time elapses, handler is triggered, off instruction sent back to your hub, and then to the switch.

There is a RunIn() method, but it has been notoriously flaky for periods that short. RunOnce() lets you specify a specific time for the schedule event rather than a period of seconds, and has been more reliable for short periods. I have to ask what are the consequences if the relay never gets the scheduled off; it is bound to happen sometimes.


(Ray) #3

For such short amount of time. You are better off connecting this timer to a smart plug instead.

http://www.amazon.com/gp/aw/d/B00ZOEQJUC/ref=pd_aw_sim_469_1?ie=UTF8&dpID=41kNrAibakL&dpSrc=sims&preST=AC_UL100_SR100%2C100&refRID=1XCADVN7C096SRX2H5ZB


(Kevin) #4

If every time you turn the Enerwave relay on, you want it to automatically stop 2-5 seconds later, and the Enerwave relay is a zwave device, you should be able to do this by modifying the device handler.

A DH should be able to get around both of the problems that @scottinpollock mentioned because the on and off commands can be sent together and the delay command doesn’t seem to have the same problems that the scheduler does.

I’ve built a beep feature into my Aeon Labs Siren and GoControl Siren device handlers that turn the device on and then turns it off after a specified amount of milliseconds. Occasionally the GoControl siren stays on for 2-3 seconds instead of 100 ms, but the Aeon Labs Siren doesn’t have that problem.

I’ve never worked with relays so I’m assuming it works like a switch, but if it works more like a momentary switch and requires you to send it the same command to start and stop it, the same concept shown below applies.

The on command in your device handler probably looks something like:

  def on () {
    [
      zwave.basicV1.basicSet(value: 0xFF).format(),
      zwave.basicV1.basicGet().format()
    ]
  }

If you modified it to look like below, it should turn on, wait 2 seconds, and turn off. It may occasionally take a couple of extra seconds to turn off, but it should still stay within the 2-5 seconds you said you wanted.

  def on () {
    [
      zwave.basicV1.basicSet(value: 0xFF).format(),
      zwave.basicV1.basicGet().format(),
      "delay 2000",
      zwave.basicV1.basicSet(value: 0x00).format(),
      zwave.basicV1.basicGet().format()
    ]
  }

(Victor Sanchez) #5

Holly mother of all smartthings programers, i know this its easy for you, but i’m not a programmer, but a good learner. i will give it a try to day.

Sounds logic to me the DH.

I will try the code and if doesn’t work probably my go to options will be the relay option.

Thanks for to all!!!


(Kevin) #6

If you get stuck, send me a link to the DH and I’ll take a look at it.


(Victor Sanchez) #7

Sorry for the delay in my update i have so much thins going on (i’m gonna be married in 1.5 months lol )

I use the code you give with no luck.

here is the full code i use to give it a try.

Hope @krlaframboise can help me or some one else, i’m really stuck in here.

/**

  • 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.

*/
metadata {

definition (name: "Z-Wave Relay Push", namespace: "smartthings", author: "SmartThings") {
	capability "Actuator"
	capability "Switch"
	capability "Polling"
	capability "Refresh"
	capability "Sensor"
	capability "Relay Switch"

	fingerprint deviceId: "0x1001", inClusters: "0x20,0x25,0x27,0x72,0x86,0x70,0x85"
	fingerprint deviceId: "0x1003", inClusters: "0x25,0x2B,0x2C,0x27,0x75,0x73,0x70,0x86,0x72"
}

// simulator metadata
simulator {
	status "on":  "command: 2003, payload: FF"
	status "off": "command: 2003, payload: 00"

	// reply messages
	reply "2001FF,delay 100,2502": "command: 2503, payload: FF"
	reply "200100,delay 100,2502": "command: 2503, payload: 00"
}

// tile definitions
tiles {
	standardTile("switch", "device.switch", width: 2, height: 2, canChangeIcon: true) {
		state "on", label: '${name}', action: "switch.off", icon: "st.switches.switch.on", backgroundColor: "#79b821"
		state "off", label: '${name}', action: "switch.on", icon: "st.switches.switch.off", backgroundColor: "#ffffff"
	}
	standardTile("refresh", "device.switch", inactiveLabel: false, decoration: "flat") {
		state "default", label:'', action:"refresh.refresh", icon:"st.secondary.refresh"
	}

	main "switch"
	details(["switch","refresh"])
}

}

def installed() {
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
}

def parse(String description) {
def result = null
def cmd = zwave.parse(description, [0x20: 1, 0x70: 1])
if (cmd) {
result = createEvent(zwaveEvent(cmd))
}
if (result?.name == ‘hail’ && hubFirmwareLessThan(“000.011.00602”)) {
result = [result, response(zwave.basicV1.basicGet())]
log.debug “Was hailed: requesting state update”
} else {
log.debug “Parse returned ${result?.descriptionText}”
}
return result
}

def zwaveEvent(physicalgraph.zwave.commands.basicv1.BasicReport cmd) {
[name: “switch”, value: cmd.value ? “on” : “off”, type: “physical”]
}

def zwaveEvent(physicalgraph.zwave.commands.switchbinaryv1.SwitchBinaryReport cmd) {
[name: “switch”, value: cmd.value ? “on” : “off”, type: “digital”]
}

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 zwaveEvent(physicalgraph.zwave.commands.hailv1.Hail cmd) {
[name: “hail”, value: “hail”, descriptionText: “Switch button was pressed”, displayed: false]
}

def zwaveEvent(physicalgraph.zwave.commands.manufacturerspecificv2.ManufacturerSpecificReport cmd) {
if (state.manufacturer != cmd.manufacturerName) {
updateDataValue(“manufacturer”, cmd.manufacturerName)
}

final relays = [
    [manufacturerId:0x0113, productTypeId: 0x5246, productId: 0x3133, productName: "Evolve LFM-20"],
    [manufacturerId:0x0113, productTypeId: 0x5246, productId: 0x3133, productName: "Linear FS20Z-1"],
	[manufacturerId:0x5254, productTypeId: 0x8000, productId: 0x0002, productName: "Remotec ZFM-80"]
]

def productName  = null
for (it in relays) {
	if (it.manufacturerId == cmd.manufacturerId && it.productTypeId == cmd.productTypeId && it.productId == cmd.productId) {
		productName = it.productName
		break
	}
}

if (productName) {
	log.debug "Relay found: $productName"
	updateDataValue("productName", productName)
}
else {
	log.debug "Not a relay, retyping to Z-Wave Switch"
	setDeviceType("Z-Wave Switch")
}
[name: "manufacturer", value: cmd.manufacturerName]

}

def zwaveEvent(physicalgraph.zwave.Command cmd) {
// Handles all Z-Wave commands we aren’t interested in
[:]
}

def on() {
[
zwave.basicV1.basicSet(value: 0xFF).format(),
zwave.basicV1.basicGet().format(),
“delay 3000”,
zwave.basicV1.basicSet(value: 0x00).format(),
zwave.basicV1.basicGet().format()
]
}

def off() {
sendEvent( name: “switch”, value: “off”)
return zwave.basicV1.basicSet(value: 0x00).format()
}

def poll() {
zwave.switchBinaryV1.switchBinaryGet().format()
}

def refresh() {
delayBetween([
zwave.switchBinaryV1.switchBinaryGet().format(),
zwave.manufacturerSpecificV1.manufacturerSpecificGet().format()
])


(Kevin) #8

What do you mean by “no luck”?

Does it not turn on, does it take to long to automatically shut off, does it not automatically shut off, etc. ?


(Victor Sanchez) #9

Sorry I forgot to elaborate.

The relay turns on. Doesn’t turn off automatically. The icon turn on and off but no the relay.

I have to press again to turn it off.

I starting to think that the relay isn’t compatible with something like that.

Any other suggestions?


(Mike Maxwell) #10

should work, but try this.

replace the existing on method with this:

def on() {
device.off(delay: 3000) 
[
 zwave.basicV1.basicSet(value: 0xFF).format(),
 zwave.basicV1.basicGet().format()
]
 }

BTW the correct form for inline delays is delayBetween([zwavecmd,zwavecmd],3000)
And if that first one doesn’t work try this

def on() {
 delayBetween([
 zwave.basicV1.basicSet(value: 0xFF).format(),
 zwave.basicV1.basicSet(value: 0x00).format(),
 zwave.basicV1.basicGet().format()],3000)
 ]
}

(Kevin) #11

The SmartThings documentation uses both methods of inline delays and it would only be the “correct” way if you wanted the same delay between all the commands.

If it’s a relay, it may require the on command to turn it on and turn it off. Try this:

  def on () {
    [
      zwave.basicV1.basicSet(value: 0xFF).format(),
      zwave.basicV1.basicGet().format(),
      "delay 3000",
      zwave.basicV1.basicSet(value: 0xFF).format(),
      "delay 200",
      zwave.basicV1.basicSet(value: 0x00).format(),
      zwave.basicV1.basicGet().format()
    ]
  }

(Victor Sanchez) #12

YOU ARE THE MAN!!!

I just try this and the relay turns on and off after 3 sec.

O man this open the use of this devices to a new level.

I can use it to open garage doors. Activate the motors of the gate to let the big trucks in etc!!

Also use it to open a valve for some second to fill the water tanks in the workshop

Thanks a lot.


(Kevin) #13

Which solution ended up solving the problem?


(Victor Sanchez) #14

Yours @krlaframboise you are the Man!! know i can automate the gates of the workshop and a lot of things i was planing to do!!

You should expand the option in this, i see a lot of potential in this DH, made putting a menu to select the quantity of seconds or minutes and made some intervals.

Well maybe because i use it a lot in home and in the work i see a lot of use, other people may say “wtf” but for me its a time saver!!!

THANKS!!!


(Jody) #15

This looks like something we could clarify in the docs. Thanks for this thread.


(Kevin) #16

Are you referring to the use of delay between or …?


(Jody) #17

Delays in general.


(Matias) #18

Hello!! Thanks to everyone for the post, I have been useful.

First of all, excuse my English. I use a translator.

I would like to ask what seems to do something like this:

def on_t2() {
    [
      zwave.basicV1.basicSet(value: 0xFF).format(),
      zwave.basicV1.basicGet().format(),
      "delay 1000",
      zwave.basicV1.basicSet(value: 0xFF).format(),
      "delay 200",
      zwave.basicV1.basicSet(value: 0x00).format(),
      zwave.basicV1.basicGet().format(),

      "delay 12000",

      zwave.basicV1.basicSet(value: 0xFF).format(),
      zwave.basicV1.basicGet().format(),
      "delay 1000",
      zwave.basicV1.basicSet(value: 0xFF).format(),
      "delay 200",
      zwave.basicV1.basicSet(value: 0x00).format(),
      zwave.basicV1.basicGet().format()
    ]
}

I turn on the relay for 1 second, wait 12 seconds and then turn on the relay 1 second more.

I have a 7 meter sliding gate. And I want to open it halfway to enter a single car.
From the remote control, when I press the button it starts to open and when I press it again it stops in the position.
To open the gate enough to enter a car delay about 12 seconds.

The code seems to work, but I would like to know if I am jamming the system with the delay command for 12 seconds.

Regards!


(Pavel Kratunkov) #19

Hi krlaframboise,
First, Thank you for the nice piece of code :smiley:

Now , my question is how did you come up with this ? Why do the relays require on command (0xFF) two times ? What is the logic behind this ?


(Sarah Archer) #20

Hi, I know this is an old thread but I’m trying to do something very similar and I wondered if you could point me in the right direction?

I have an electronic lock release that I’m operating through a smartthings power outlet. Ideally I’d like to be able to have the power outlet switch on for maybe 5 seconds (just long enough for the door to be pushed) and then switch off again.

Unfortunately I’m completely new to this and have no idea where to start - smartapp/device handler - no idea! Do you think something similar to this could be applied to the power outlet?

Many thanks
Sarah