What this does:
------------------------------
Update event basically is the MAIN script I use to coordinate everything in my house. updateevent is generic and as stated on the third line, takes in a delay time (default is minutes), device code (no names!), if you want it to be set to ON or OFF, then a Yes/No if the delay time should be seconds or not.
I would like to add in delayed event triggering and DIM control. That is fire off an event after so much time has passed. Or instead of just triggering ON/OFF trigger to a DIM level.
Right now I get around it by triggering a UPB link for the dim level I want. So, that has NOT been a priority.
Basically the steps to the code are:
" ' As an event cannot trigger itself in seconds of resolution
' while it would be noticable, just trigger the event with a
' seconds resolute function"
At least this is how my experimentation seemed to show the events being fired.
Basically, if you triggered update event at 11:30:32, then added 4 minutes to "NOW" to trigger. It would not trigger at 11:34:32, it would trigger at 11:34:00. So, I fixed that. For anything that was less than 4 minutes, the offset did not really matter in the grand scheme of things...so I do not bother with the helper event.
Copy the above code into a file updateevent.vb
Example use:
Create an event that calls the script:
Then, add a sub to handle the logic. You can do something like the below (which should compile and run for you, just change the variables...this is ONLY a snippet of the control code for the master bathroom). What is nice about this, you can GROUP logic by the parameter. So, ONLY when the door is changed, does the above parameter get used.
That is this line:
if(param = "doorChange") then
Basically, you could have a whole host of those, one for EACH sensor in the room. In my bathrooms, I have a few motion sensors, pressure pad, and the light switches themselves. I make ONE event per trigger device, and make them trigger the script.
So, the REAL sub for this has:
if(param = "doorChange") then
if(param = "showerMotion") then
if(param = "resetOccupied") then
if(param = "sinkPad") then
The reset is only used to reset a few counters (you need multiple triggers in the shower to determine that someone is IN the shower).
So, IF the door is closed, create a timed event that waits a "longTime", if the door is opened, then create a timed event for "shortTime". In either case, if there is a timed event for overheadLight, remove it first, THEN create the new timed event.
Discussion goes here:
http://forums.homeseer.com/showthread.php?p=985608
------------------------------
Update event basically is the MAIN script I use to coordinate everything in my house. updateevent is generic and as stated on the third line, takes in a delay time (default is minutes), device code (no names!), if you want it to be set to ON or OFF, then a Yes/No if the delay time should be seconds or not.
I would like to add in delayed event triggering and DIM control. That is fire off an event after so much time has passed. Or instead of just triggering ON/OFF trigger to a DIM level.
Right now I get around it by triggering a UPB link for the dim level I want. So, that has NOT been a priority.
Basically the steps to the code are:
- you trigger it
- the script looks for anything that is in existence for the device. Remove that if it exists
- Then create a "NewTimeEvent" for that device.
- If you say seconds only, OR if the time delay you ask for is less than 4 minutes, create the NewTimeEvent much later in time, however make a tigger event for the NewTimeEvent, which will trigger the NewTimeEvent in seconds of resolution. Best explained by the comment in the code:
" ' As an event cannot trigger itself in seconds of resolution
' while it would be noticable, just trigger the event with a
' seconds resolute function"
At least this is how my experimentation seemed to show the events being fired.
Basically, if you triggered update event at 11:30:32, then added 4 minutes to "NOW" to trigger. It would not trigger at 11:34:32, it would trigger at 11:34:00. So, I fixed that. For anything that was less than 4 minutes, the offset did not really matter in the grand scheme of things...so I do not bother with the helper event.
Code:
' par should be of the format ' Delay Time (in minutes), device Code, On/Off, Yes/No 'UPB Link Values 'UNKNOWN = 0 'ACTIVATE = 1 'DEACTIVATE = 2 'FADE ON = 3 'FADE OFF = 4 'SNAP ON = 5 'SNAP OFF = 6 'DIM to 10% = 7 'DIM to 20% = 8 'DIM to 30% = 9 'DIM to 40% = 10 'DIM to 50% = 11 'DIM to 60% = 12 'DIM to 70% = 13 'DIM to 80% = 14 'DIM to 90% = 15 'BLINK = 16 'LAST ON LEVEL = 17 Sub updateEvent(ByVal par as object) dim delaySecs,delayMins, ev, eventName, devCode, onOff, onlySeconds delaySecs = 0 delayMins = hs.stringitem(par, 1, "|") devCode = hs.stringitem(par, 2, "|") onOff = ucase(hs.stringitem(par, 3, "|")) onlySeconds = ucase(hs.stringitem(par, 4, "|")) 'hs.writelog("Info", par) 'hs.writelog("Info", delayMins) 'hs.writelog("Info", devCode) 'hs.writelog("Info", onOff) 'hs.writelog("Info", onlySeconds) ev = hs.GetDeviceByRef(hs.GetDeviceRef(devCode)) eventName = ev.location & " " & ev.name & " " & onOff & " (delayed event)" ' if we need to remove the event ONLY if(UCASE(onlySeconds) = "REM") then hs.DeleteEvent(eventName) hs.DeleteEvent(eventName & " (delayed event)") 'hs.writelog("Test", "deleted events!") 'hs.writelog("Test", "Deleting: " & eventName & " (delayed event)") exit sub end if if(UCASE(onlySeconds) = "YES") then delaySecs = delayMins delayMins = 30 else ' As an event cannot trigger itself in seconds of resolution ' while it would be noticable, just trigger the event with a ' seconds resolute function if(delayMins < 4) then delaySecs = delayMins * 60 delayMins = 30 end if end if if hs.EventExists(eventName) then hs.DeleteEvent(eventName) end if if hs.EventExists(eventName & " (delayed event)") then hs.DeleteEvent(eventName & " (delayed event)") end if hs.NewTimeEvent(eventName, _ timevalue(DateAdd("n",delayMins,Now)),datevalue(DateAdd("n",delayMins,Now)), _ 1,1,1,1,1,1,1,devCode & ":" & onOff,true,"","Delayed Actions") if(delaySecs > 0) then hs.DelayTrigger(delaySecs, eventName) ev = hs.GetEventEx(eventName & " (delayed event)") '16384 turns OFF logging '16400 turns off logging and Delete After Execute ev.misc = 16400 hs.EnableEvent(eventName & " (delayed event)") end if ev = hs.GetEventEx(eventName) '16384 turns OFF logging '16400 turns off logging and Delete After Execute ev.misc = 16400 hs.EnableEvent(eventName) End Sub
Example use:
Create an event that calls the script:
PHP Code:
Name: Fan on by Door
PHP Code:
Trigger:
Device Top Master Bathroom Door changed to status *Any*
WHEN
Everyday
PHP Code:
Run script: updateEvent.vb("masterBathLighting","doorChange")
That is this line:
if(param = "doorChange") then
Basically, you could have a whole host of those, one for EACH sensor in the room. In my bathrooms, I have a few motion sensors, pressure pad, and the light switches themselves. I make ONE event per trigger device, and make them trigger the script.
So, the REAL sub for this has:
if(param = "doorChange") then
if(param = "showerMotion") then
if(param = "resetOccupied") then
if(param = "sinkPad") then
The reset is only used to reset a few counters (you need multiple triggers in the shower to determine that someone is IN the shower).
Code:
sub masterBathLighting(ByVal param as String) Dim mBathDoor Dim mBathLight Dim mBathFan Dim mBathBrightTo100 Dim myCount Dim longTime Dim showerLongTime '************************************* '* Setup Variables * '************************************* mBathDoor = hs.GetDeviceCode("Master Bathroom Door") mBathLight = hs.GetDeviceCode("Master Bathroom Overhead Light") mBathFan = hs.GetDeviceCode("Master Bathroom Fan") mBathBrightTo100 = hs.GetDeviceCode("UPB Device Link Master Bathroom Bright to 100 Link") myCount = getMyVar("showerCount") longTime = 10 showerLongTime = 30 if(param = "doorChange") then ' off is door closed if (hs.isOff(door)) then updateEvent(longTime & "|" & overheadLight & "|" & "OFF") else updateEvent(shortTime & "|" & overheadLight & "|" & "OFF") end if end if end sub
Discussion goes here:
http://forums.homeseer.com/showthread.php?p=985608
Comment