Announcement

Collapse
No announcement yet.

Is there a way to use a variable duration in a timer?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sparkman
    replied
    Originally posted by cc4005 View Post

    Thanks a lot Al. I'm at the earliest stage of learning scripting, and this will be a good study.
    You're welcome and let me know if you have any questions.

    Leave a comment:


  • Wade
    replied
    Originally posted by sparkman View Post

    Hi Wade, here's a sample of what I use:


    Hope that helps.

    Cheers
    Al
    Thanks a lot Al. I'm at the earliest stage of learning scripting, and this will be a good study.

    Leave a comment:


  • sparkman
    replied
    Originally posted by cc4005 View Post

    sparkman would you mind sharing an example for those of us who are scripting-challenged? Thanks.

    -Wade
    Hi Wade, here's a sample of what I use:

    Code:
    Sub Main(ByVal Parms As String)
        Dim logName As String = "Delayed Off"    'set log type for HS log
        Dim Debug As Boolean = False            
    
        Dim ParmArray() as String
        ParmArray = Parms.tostring.split(",")
        dim ControlDevice as Integer = CInt(ParmArray(0))    'reference ID of the device to turn off
        dim DelayDevice as Integer = CInt(ParmArray(1))        'reference ID of the virtual device that holds the delay value in minutes
    
        Dim Delay As Integer = hs.DeviceValue(DelayDevice)
            If Debug Then hs.writelog(logName,"Delay: " & Cstr(Delay))
    
        Dim StopDateTime As Date = DateAdd(DateInterval.Minute, Delay, Now)
        Dim EventName As String = "Device Off " & Cstr(ControlDevice) ' Make sure to give it a unique name
    
        'Delete Event if it already Exists and wait to ensure it is deleted
        hs.DeleteEvent(EventName)
        hs.waitsecs(5)
        'Create event
        Dim Evref As Integer = hs.NewEventEx(EventName, "Event Group", "Event Type")
        ' set the trigger time of the event
        Dim Ok As Boolean = hs.EventSetTimeTrigger(Evref, CStr(StopDateTime))
        ' set the event to delete itself after it runs
        hs.DeleteAfterTrigger_Set(Evref)
        ' add a device action to the event
        Dim CC as CAPIControl = hs.CAPIGetSingleControlByUse(ControlDevice, ePairControlUse._Off)
        hs.AddDeviceActionToEvent(Evref, CC)
        ' enable event
        hs.EnableEventByRef(Evref)
    End Sub
    The script expects two parameters to be passed to it, separated by a comma. The first is the reference ID of the device that needs to be turned off, and the second one is the virtual device that has a value (in minutes) for the delay.

    Click image for larger version  Name:	Capture.PNG Views:	1 Size:	49.6 KB ID:	1289418

    Hope that helps.

    Cheers
    Al

    Leave a comment:


  • Wade
    replied
    Originally posted by sparkman View Post
    I use a script for things like that. When the device is turned on, the script is triggered and it creates an event that turns it back off after the number of minutes specified in a virtual device. The event deletes itself after running.
    sparkman would you mind sharing an example for those of us who are scripting-challenged? Thanks.

    -Wade

    Leave a comment:


  • sparkman
    replied
    I use a script for things like that. When the device is turned on, the script is triggered and it creates an event that turns it back off after the number of minutes specified in a virtual device. The event deletes itself after running.

    Leave a comment:


  • Wade
    replied
    Originally posted by SeattleDavid View Post
    Does this sound correct and include the essential (but missing) information?
    I believe you have the gist of it.

    Originally posted by SeattleDavid View Post
    And, do timer devices have an especially high overhead? It would seem that updating a timer device every second is a lot of work for the system, since every time a device is updated it seems to be written to the SQL database.
    I can't say. I have 26 timer devices I use for various purposes--occupancy, fan control, etc. I'm not aware of them creating any performance issues, but it's a good question that others on the forum with more experience can possibly answer. Randy, do you know?

    Leave a comment:


  • SeattleDavid
    replied
    OK, so let me see if I can piece together the essential but missing details from the original suggestion...

    A global timer can be used. Then, it’s value can be set and tested. BUT...

    A global timer cannot normally be referenced, read, or set as it is a special class of device. That has no handle (Ref ID). SO...

    If you turn on a option in settings, then timers will have a companion device created that looks like a normal device. This companion (linked) device will then be able to be read and set and therefore be used in events. Now an expression can be created that will compare the timer value with a value stored in a virtual device using Easy Trigger.

    Does this sound correct and include the essential (but missing) information?

    And, do timer devices have an especially high overhead? It would seem that updating a timer device every second is a lot of work for the system, since every time a device is updated it seems to be written to the SQL database.

    Leave a comment:


  • Wade
    replied
    Originally posted by SeattleDavid View Post
    I like the approach. I am a bit green in this area...

    What is a “Timer Device”?

    Are these timers, or devices that are special? How do you create a “TimerDevice” and how do you get it to time/count?
    Yes, they are a special type of device. You create them by going to Tools > Global Variables, Timers, & Counters. They can also be created on the fly during event creation by selecting "A Timer's Value becomes..." as a trigger or condition, or by selecting "Control a Timer" as your action. In my example above it would be your trigger. By event you can start, set or stop a timer.

    Also, go to Tools > Setup > General and check the box "Create Devices for Counters and Timers". This will cause HS to create a virtual device for each counter or timer you create. They will be created with default Location 2 of Counters-Timers and Location 1 of Timers.

    Here are some of 's great event clinics that explain in detail. Link1 Link2 Randy has assembled an amazing set of how-to's in the HS3 Event Clinic section. Highly recommend spending time there if you haven't discovered it yet.

    Leave a comment:


  • SeattleDavid
    replied
    I like the approach. I am a bit green in this area...

    What is a “Timer Device”?

    Are these timers, or devices that are special? How do you create a “TimerDevice” and how do you get it to time/count?

    Leave a comment:


  • Wade
    replied
    Apologies for repeating some of what Randy said. Our suggestions are very similar.

    Leave a comment:


  • Wade
    replied

    I've not tested this but I think the concept would work. You should be able to do it with EasyTrigger using "this device had its value set and expression is true".

    Let's say you have a timer device called TimerDevice whose device ref is 1000 and your duration device set in HS Mobile (in minutes) has device ref 2000. Then you could have the drip turn off like this:

    IF TimerDevice has its value set and expression is true: $$DVR:1000: = $$DVR:2000: * 60
    THEN Turn off drip

    Timer values are in seconds; hence the multiplier on the duration device.

    Leave a comment:


  • randy
    replied
    It is a little bit of a kludge but the HomeSeer timer device has its value set in seconds. You can create a virtual device where you store your intended time in seconds - you can set the Status Values for an entire range or for specific time values. Then use an Event to run when the value of HS timer device becomes greater than the value set in the virtual device.

    Leave a comment:


  • Is there a way to use a variable duration in a timer?

    I would like to have a setting (stored in a virtual device) that then specifies a duration for something.

    For example, turning off a drip irrigation system after X minutes. But I would like to be able to specify and save "X" in a virtual device so that I can easily change it periodically using HS Mobile. So I would set the number of minutes in HS Mobile, this would be stored in a Virtual Device and would then be used to turn off the drip system after this many minutes.

    I cannot think of or find any way in HS3 to do this, without resorting to scripting.

    Any thoughts?
Working...
X