Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Programming
 PowerHome Messageboard : PowerHome Programming
Subject Topic: Create Timed Event Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
RichardL
Senior Member
Senior Member


Joined: December 29 2008
Location: United States
Online Status: Offline
Posts: 165
Posted: May 25 2009 at 00:38 | IP Logged Quote RichardL

I am trying to use the PH.CreateTimedEvent function in a VBS, and it seems there is something off here. I have tried to follow the help file.

The line of code in the VBS looks like:

rv = PH.CreateTimedEvent(int(2), PH_RunScript_0(6, "C:\PHScripts\Script2.vbs", "Main"), strDTSubmit)

The value of strDTSubmit would look like:
"2009-05-25 01:23:00.000 AM"

The VBS program with this command in it, gets up to but never executes the command, if I execute Script2.vbs standalone, it is OK.

This function has not been mentioned in the forums, so anyone with new comments?

Thank you,

Richard
Back to Top View RichardL's Profile Search for other posts by RichardL
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: May 25 2009 at 06:45 | IP Logged Quote grif091

The second parameter of the ph.createtimedevent function is a string. Try putting the parameter within quotes. Since that string will have quotes inside itself, you will have to use the single/double quote syntax.

rv = PH.CreateTimedEvent(int(2), 'PH_RunScript_0(6, "C:\PHScripts\Script2.vbs", "Main")', strDTSubmit)

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
RichardL
Senior Member
Senior Member


Joined: December 29 2008
Location: United States
Online Status: Offline
Posts: 165
Posted: May 25 2009 at 11:08 | IP Logged Quote RichardL

I have the VBS rigged with event log updates, so I can see how it progresses. You brought a valid point, however when I added the single quotes into the command, the code doesn't run at all (the first event log update doesn't appear). I have linked this behavior if there is a syntax error in the VBS code, ie: mismatched parenthesis, etc.

So I created a new variable to handle the 2nd param, now the code runs, and I get event log syntax errors.

I tried various tests seen below:

----

Test1 (new variable, 12 hour time format):

strParam2 = "PH_RunScript_0(6, " & CHR(34) & "C:\PHScripts\Script2.vbs" & CHR(34) & ", " & CHR(34) & "Main" & CHR(34) & ")"

Value of strDTSubmit: 2009-05-25 10:23:17.000 AM

rv = PH.CreateTimedEvent(int(2), strParam2, strDTSubmit)

Syntax Error in Formula: ph_createtimedevent(2,~'PH_RunScript_0(6, ~"C:\PHScripts\Script2.vbs~", ~"Main~")~',1899-09-?? 00:13:00)

----

Test2 (used single quotes, 12 hour time format):

strParam2 = "'PH_RunScript_0(6, " & CHR(34) & "C:\PHScripts\Script2.vbs" & CHR(34) & ", " & CHR(34) & "Main" & CHR(34) & ")'"

Value of strDTSubmit: 2009-05-25 10:25:03.000 AM

rv = PH.CreateTimedEvent(int(2), strParam2, strDTSubmit)

Syntax Error in Formula: ph_createtimedevent(2,~'~~~'PH_RunScript_0(6, ~"C:\PHScripts\Script2.vbs~", ~"Main~")~~~'~',1899-09-?? 00:00:00)

----

Test3 (single quote, changed time format to use 24-hour format, no ".000", or AMPM):

strParam2 = "'PH_RunScript_0(6, " & CHR(34) & "C:\PHScripts\Script2.vbs" & CHR(34) & ", " & CHR(34) & "Main" & CHR(34) & ")'"

Value of strDTSubmit: 2009-05-25 10:31:00

rv = PH.CreateTimedEvent(int(2), strParam2, strDTSubmit)

Syntax Error in Formula: ph_createtimedevent(2,~'~~~'PH_RunScript_0(6, "C:\PHScripts\Script2.vbs~", ~"Main~")~~~'~',1899-09-?? 00:00:00)

----

Test4 (no single quote, changed time format to use 24-hour format, no ".000", or AMPM):

strParam2 = "PH_RunScript_0(6, " & CHR(34) & "C:\PHScripts\Script2.vbs" & CHR(34) & ", " & CHR(34) & "Main" & CHR(34) & ")"

Value of strDTSubmit: 2009-05-25 10:42:43

rv = PH.CreateTimedEvent(int(2), strParam2, strDTSubmit)

Syntax Error in Formula: ph_createtimedevent(2,~'PH_RunScript_0(6, ~"C:\PHScripts\Script2.vbs~", ~"Main~")~',1899-09-?? 00:00:00)

----

So...I suspect it may be two things: Param2 and/or Param3 that is a problem, I may be possibly quote and/or date/time format challenged!

Any thoughts?

I greatly appreciate the help!

Richard
Back to Top View RichardL's Profile Search for other posts by RichardL
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: May 25 2009 at 13:31 | IP Logged Quote grif091

I ran the following datetime() function under the Formula Builder and got the datetime result that is listed on the next line. The result of the datetime function, which returns a dt value, does not appear to match the format you are using for a datetime value.


datetime(date("12-31-99"), now())

The formula evaluates to: 12/31/1999 13:16:46:791

Powerhome does not support a quoted string with like quotes inside the string.

Not supported: "abcd "efgh" ijkl"
It has to be:   'abcd "efgh" ijkl'
or: "abcd 'efgh' ijkl"    

__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
RichardL
Senior Member
Senior Member


Joined: December 29 2008
Location: United States
Online Status: Offline
Posts: 165
Posted: May 25 2009 at 14:34 | IP Logged Quote RichardL

I will check this all out late tonight when I return and post an update.

Thank you!

Richard
Back to Top View RichardL's Profile Search for other posts by RichardL
 
dhoward
Admin Group
Admin Group
Avatar

Joined: June 29 2001
Location: United States
Online Status: Offline
Posts: 4447
Posted: May 25 2009 at 15:58 | IP Logged Quote dhoward

Richard,

This would be another method of invoking a "wait" from within a VBS script. The problem is, Ive been trying to get this to work and it appears to be a problem with the PH ph.createtimedevent function successfully interpreting the datetime value that VBScript is providing. I'll be reworking a number of the VBS functions for PH and this is apparently one that I'll have to work on.

In the meantime, I was successful in working around the problem by using the ph.formula function instead. Below is a sample line from my script that was successful.

Code:
i_ret = ph.formula("ph_createtimedevent(2,'ph_runscript_0(5,""c:\dow nload\test\test1.vbs"",""script1"")',2009-05-25 13:45:00)")


As you can see, I used the ph.formula function to execute the PowerHome ph_createtimedevent function. VBScript uses different escape characters than PH so the embedded double quotes are double, double quotes. Also VBS strings must be enclosed in double quotes while PH strings can be enclosed in either single or double quotes.

The only trick part for you is the representation of the datetime for the timed event to fire. You'll see that I used a literal datetime and it is not enclosed in any kind of quotes. PowerHome literal datetimes are in the format of yyyy-mm-dd hh:mm:ss and use no quotes. Obviously, you should be able to build a literal string of the proper format using VBS but you can also use any of the standard PH datetime functions such as ph_relativedatetime to have the timed event create a specific number of minutes in the future from when the script is run. Below is a working sample line showing this:

Code:
i_ret = ph.formula("ph_createtimedevent(2,'ph_runscript_0(5,""c:\dow nload\test\test1.vbs"",""script1"")',ph_relativedatetime(tod ay(),0.1))")


This will create the timed event to run 6 seconds in the future.

Hope this helps,

Dave.
Back to Top View dhoward's Profile Search for other posts by dhoward Visit dhoward's Homepage
 
grif091
Super User
Super User


Joined: March 26 2008
Location: United States
Online Status: Offline
Posts: 1357
Posted: May 25 2009 at 16:00 | IP Logged Quote grif091

You might try making the command as simple as you can make it, even if it does not provide the function that you want to start with. The following command (run from a macro rather than a VBS) does successfully create a timed event. I put a date so far off in the future that the event will never run before I can delete it but the timed event is listed as pending. Once you get a simple example that creates a timed event working, then change the dt (datetime) value to reflect what you want in your application. When that is working go back to the RunScript area. In my working example I invoke a Macro which does require quotes around the Macro ID so I started string parameter 2 with a single quote, using double quotes around the macro id. I could have started string parameter 2 with a double quote and put single quotes around the macro id. Powerhome works with either format. Depending on who is ultimately going to look at the string inside it may be necessary to start with a single quote so the values inside that may be parsed by other than Powerhome can be in double quotes.

ph_createtimedevent(2, 'ph_macro("MTODAY")', datetime(date("12/31/2009"), time("10:25 am")))

If you are trying something that makes the datetime value dynamic, you can invoke the Formula Builder and use the datatime() function to test the dynamic aspects of creating a datetime value. Only when it works in the Formula Builder, move it to the ph.createtimedevent statement.

EDIT: Dave's post got here first. Obviously follow his double double quote example.

Edited by grif091 - May 25 2009 at 16:10


__________________
Lee G
Back to Top View grif091's Profile Search for other posts by grif091
 
RichardL
Senior Member
Senior Member


Joined: December 29 2008
Location: United States
Online Status: Offline
Posts: 165
Posted: May 26 2009 at 00:19 | IP Logged Quote RichardL

Dave, Lee - thanks for the info.

I used the PH.Formula command and all is well! The RelativeDateTime also allowed me to remove all the date/time commands which is great. I tried many, many combos and approaches before posting here, so I will look forward to the function version update. Dave thanks for the great feedback, I never would have been able to do this without this info! The PH.Formula is also new to me and opens up all the PH_ commands to VBS code - very nice.

This is a dynamic setup of the timed events, so I stuck with Dave's method - Lee, again, thank you for your valuable help.

This project is:
* Driveway mounted Optex motion sensor triggers motion and relays to a PowerFlash unit which sends out an X10 address (I will update to the new Insteon motion sensors at some point),
* PH trigger calls TR_DWY-Tree_On.vbs when the X10 address is sensed,
* If it is nighttime, this routine turns on tree lights along the driveway, and creates a timed event (TE_DWY-Tree_Off.vbs) 5 minutes out to turn them off. It also increments, by one, a global variable "ExeInc_DWY-Tree".
* When TE_DWY-Tree_Off.vbs runs, it decrements, by one, the global variable ExeInc_DWY-Tree. Only if he variable is zero, will it turn off the lights. If it is not zero, the routine exits. This means that during the 5 minute period, the Optex sensor picked up new motion, and we want the lights to stay on for 5 minutes from that point, so the lights will get turned off by the timed event that was created at that point.

I am converting dozens of programs and methods from my X10/Homeseer setup to Insteon/PH, one more down!

Thank you,

Richard

Back to Top View RichardL's Profile Search for other posts by RichardL
 
device
Newbie
Newbie


Joined: May 26 2009
Online Status: Offline
Posts: 33
Posted: May 26 2009 at 23:46 | IP Logged Quote device

Try using CDate() to explicitly cast the datetime on the ph.createtimedevent call. In my immense experience (a couple of weeks of poking around) I've found explicit casts on ph. calls seem to make life seem so more enjoyable.

A short example from my code

Sub setcheck(location)
     Dim action, ulocation
     ulocation = UCase(location)
     action = "ph_runscript_1(-1, #C:\Program Files\powerhome\devicechg.vbs#, #checkpresence#, #" & location & "#)"
     Call ph.createtimedevent(2, Replace(action, "#", Chr(34)), CDate(DateAdd("n", ph.getglobal_n(ulocation & "_O"), ph.getglobal_dt(ulocation & "_L"))))
End Sub

D
Back to Top View device's Profile Search for other posts by device
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum