Contacting HomeSeer This Week

HomeSeer is open and operational this week. All orders are being processed and shipped as usual. However, some staff are working from home. If you need to contact HomeSeer for support or customer service, please use our Email or Chat options.
See more
See less

[VB.NET Script] DelayOff Event

  • Filter
  • Time
  • Show
Clear All
new posts

  • [VB.NET Script] DelayOff Event

    I was looking for a way to add a delayed off action when I turn on a light, which is pretty simple, but I also wanted to be able to tap on multiple times and add time to the dealyed off.

    I use this in conjunction with and sometime instead of motion sensors. ie, the bathroom, the kids always have problems of the light turing off on them when they are in the shower, but I didn't just want to delay the off time, now they can hit the button twice.

    'call this script with optional parameters of ("PushOn"|"PushOff",device code ie "A11")
    'I set this script to run from 2 seperate events:
    ' - one with a trigger of Device Set to On and parameters of ("PushOn",device code)
    ' - the second with a trigger of Device Set to Off and parameters of ("PushOff",device code)
    dim speak = True 'when true Speak an announcement that the device was turned off
    Sub main (parm as object)
    end sub
    Sub PushOn (ByVal dv as string)
    dim oldEvent
    dim newEvent
    dim nn = 900 'seconds to add for delay off, 900 seconds equals 15 minutes
    dim ev
    dim eventTime
    dim dvRef
    dim dvReturn
    dim dvName
    dvRef = hs.GetDeviceRef(dv)
    oldEvent=hs.GetEventRefByName("DelayOffEvent " & dv)
    if oldEvent<0 then 'event does not exist, create a new one
    eventTime = DateAdd ("s", nn, Now) 
    newEvent=hs.NewEventGetRef("DelayOffEvent " & dv)
    ev.ev_abs_time = 0 'Time
    ev.ev_time = eventTime
    ev.misc = &h10 '&h10 is delete after trigger &h20 1 is disabled
    hs.AddAction(newEvent, 1, dvRef, "Off",,,)
    if speak=True then
    dvName = dvReturn.Location2 & " " & dvReturn.Location & " " &
    hs.AddAction(newEvent, 3, "Turning off " & dvName,,) 
    end if
    hs.writelog("DelayOffEvent","Creating delayed off for " & dv & " in " & nn & " seconds.")
    else 'event does exist, add nn seconds to it
    eventTime = DateAdd("s", nn, ev.ev_time)
    ev.ev_time = eventTime
    hs.writelog("DelayOffEvent","Adding " & nn & " seconds to delayed off event for " & dv & ".")
    end if
    End Sub
    Sub PushOff (ByVal dv as string)
    dim oldEvent
    dim dvRef
    dim dvReturn
    dim dvName
    oldEvent=hs.GetEventRefByName("DelayOffEvent " & dv)
    if oldEvent>0 then 'event does exist, let's delete it
    hs.DeleteEvent("DelayOffEvent " & dv)
    hs.writelog("DelayOffEvent","Cancelling delayed off for " & dv & ".")
    end if
    End Sub
    HS Install Date: Feb. 16, 2007

    HS3 Pro, Z-Wave, Insteon, BLStat, HS Touch Server, MyQ

    WeatherXML, BLBackup, BLLAN, BLLock, Restart, CaddX, OpenSprinkler