Author |
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 15 2009 at 22:09 | IP Logged
|
|
|
I'm getting stuck while trying to use [TEMP1] within a macro. Instead of setting to a value that I compute, the Temp value is forced to be the ID of the Trigger macro line that calls my routine.
I thought that TEMPs were useable within a macro, as needed. If the TEMP arrived with a preset value I would expect it to be replaced by my new computed value,but this does not seem to be the case.
I have a Trigger db entry with an ID of "CC-D-ROOM" that when it senses an Insteon Device change, calls a handler with "ph_macroparm("CC-LEV","DWN ROOM","DRMT",0,0,0)" where CC-LEV is the handler, DWN ROOM is the Insteon Device ID, and DRMT is a static text label ID in the Control Center.
Inside the CC-LEV macro one of the first lines is "ph_setvar_a(2,1,ph_getinsteonlevelrt("[LOCAL1]")". From this I expect TEMP1 [set by setvar(2,1,..)]to be set to the current ON level of the lighting device.
Instead it is set to "CC-D-ROOM" Nothing I have tried results in TEMP1 being anything other than the ID of the calling Trigger.
Am I wrong in using a TEMP? Are some TEMPS reserved for system use, and if so how do I discover which ones?
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: January 15 2009 at 23:02 | IP Logged
|
|
|
I think you should be using LOCAL's in your situation.
|
Back to Top |
|
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 16 2009 at 08:08 | IP Logged
|
|
|
TonyNo -
Thanks. I'll try that.
Can you provide a quick tutorial on the care and feeding of LOCALS and TEMPS?
When and where is each best used? I understand that each macro has it's own variable space, but what is the persistence of this space. For instance if a macro calls a Windows Script and control is returned to the macro, the vars are preserved. What happens if a macro executes another macro and control is returned? I assume that in both cases, the vars are preserved.
I believe that if a macro calls a macro that displays var values (via ph_msgbox), the called macro has no knowledge of the calling macro var values.
So I guess the mystery to me is what is best to use within a macro? It sounds from your suggestion that it is the LOCAL variable. Does that mean that TEMPS are pretty much preserved for system level parameter passing amongst "system friends and family?"
This may explain why I sometimes get "funky" results with some of my macros, as I have used the TEMP within macros most of the time!
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 16 2009 at 09:13 | IP Logged
|
|
|
Question.
Without the ability to single step thru a macro yet (but rumor has it that Dave is working on debugging enhancements ) it is difficult to trap the value of TEMPs and LOCALs since they are gone once the macro executes.
Is there any way to embed a halt in a macro (I haven't found one) so one can examine vars at that moment? It gets laboreous inserting ph_msgbox commands all over the place!
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 16 2009 at 09:23 | IP Logged
|
|
|
Ken, I use this in the macro:
ph_usermessage(ph_getvar_s(1,0) + "|" + ph_getvar_s(1,1) + "|" + ph_getvar_s(1,2) + "|" + ph_getvar_s(1,3) + "|" + ph_getvar_s(1,4) + "|" + ph_getvar_s(1,5) + "|" + ph_getvar_s(1,6) + "|" + ph_getvar_s(1,7) + "|" + ph_getvar_s(1,8) + "|" + ph_getvar_s(1,9) + "|" + ph_getvar_s(1,10)) + ph_usermessage(ph_getvar_s(2,0) + "|" + ph_getvar_s(2,1) + "|" + ph_getvar_s(2,2) + "|" + ph_getvar_s(2,3) + "|" + ph_getvar_s(2,4) + "|" + ph_getvar_s(2,5) + "|" + ph_getvar_s(2,6) + "|" + ph_getvar_s(2,7) + "|" + ph_getvar_s(2,8) + "|" + ph_getvar_s(2,9) + "|" + ph_getvar_s(2,10))
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
smarty Super User
Joined: May 21 2006 Location: United States
Online Status: Offline Posts: 728
|
Posted: January 16 2009 at 09:26 | IP Logged
|
|
|
From the (old) PH User Manual, P28. Hope this helps, I needed to re-read it myself just the other day.
********************************************************
There are a total of 35 special system variables. 10 of these only have scope within the macro, PSP, or formula from
which they were called. These system variables are [LOCAL1] through [LOCAL10]. These system variables can be
used as temporary variables to store characters or numbers. This will save you from using global variables as
temporary storage and incurring the database read and write. Another 10 special system variables are [TEMP1]
through [TEMP10]. These variables serve two purposes. The first is that they can be referenced and set from within
macros, PSP, or formulas. When a macro or formula calls another macro or formula, any values within these system
variables are passed continuously down through subsequent calls. These are not global in the sense that the values
are the same for all macros, PSP, and formulas. For example, if a timed event launches a macro called TEST1, this
macro may set the [TEMP1] through [TEMP10] variables to certain values. If this TEST1 macro calls another macro
called TEST2, then the TEST2 macro will be able to reference the values that the TEST1 macro placed in the [TEMP1]
through [TEMP10] system variables. TEST2 can in turn call a Send Keys formula that can also reference the values in
the variables. When the original macro TEST1 completes, the values in the [TEMP1] through [TEMP10] variables are
lost. The second use of these variables is to pass parameters from triggers and voice commands. When certain
triggers and / or voice commands are processed, some of the [TEMP1] through [TEMP10] system variables will be prepopulated
with relevant information that the resulting macro or Send Keys formula can reference. These pre-populated
values will be detailed in their relevant sections. The last 20 special variables are [GLOBAL1] through [GLOBAL20].
These variables are truly global and can be seen from within any formula or macro. They are not stored in the database
however and will be lost when PowerHome is shut down.
__________________ Elk - Insteon - BlueIris - DMC1 - PowerHome - XLobby - HA_Bridge w/Dots - Brultech
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: January 16 2009 at 10:02 | IP Logged
|
|
|
The devil is in the details...
ph_setvar_a(2,1,ph_getinsteonlevelrt("[LOCAL1]")
You're missing a close paren at the end. The above function will result in a syntax error and consequently will not overwrite the Trigger ID value currently contained in [TEMP1]. Once you add the closing paren, it should work.
HTH,
Dave.
|
Back to Top |
|
|
GadgetGuy Super User
Joined: June 01 2008 Location: United States
Online Status: Offline Posts: 942
|
Posted: January 16 2009 at 15:31 | IP Logged
|
|
|
Ah guys. As always y'all are such a help.
Dave - how right you are. I have written a pretty massive amount of code over the last week, the vast majority of which was "logically" correct but didn't work because of typos,
parens, or quotes that were unbalanced. Sure makes me wish I'd taken that typing class back in high school instead of developing my own style of hunt and peck!
BeachBum - I have what I think is the same functionality in:
Code:
ph_msgbox("Variables","Temp 1: [TEMP1]~r~n+
Temp 2: [TEMP2]~r~n+
Temp 3: [TEMP3]~r~n+
Temp 4: [TEMP4]~r~n+
Temp 5: [TEMP5]~r~n+
Temp 6: [TEMP6]~r~n+
Temp 7: [TEMP7]~r~n+
Temp 8: [TEMP8]~r~n+
Temp 9: [TEMP9]~r~n+
Temp 10: [TEMP10]~r~n+
Local 1: [LOCAL1]~r~n+
Local 2: [LOCAL2]~r~n+
Local 3: [LOCAL3]~r~n+
Local 4: [LOCAL4]~r~n+
Local 5: [LOCAL5]~r~n+
Local 6: [LOCAL6]~r~n+
Local 7: [LOCAL7]~r~n+
Local 8: [LOCAL8]~r~n+
Local 9: [LOCAL9]~r~n+
Local 10: [LOCAL10]~r~n",90) |
|
|
But it always comes up with empty values, so I quit using it. Is the difference that you used "ph_getvar_s(1,0)" instead of the variable directly that makes yours work?
Edited by GadgetGuy - January 16 2009 at 15:31
__________________ Ken B - Live every day like it's your last. Eventually, you'll get it right!
|
Back to Top |
|
|
BeachBum Super User
Joined: April 11 2007 Location: United States
Online Status: Offline Posts: 1880
|
Posted: January 16 2009 at 16:26 | IP Logged
|
|
|
I get mixed results using direct but always get result using ph_ getvar. I found “hunt & peck” plus old age results in typing everything in Word. My fingers don’t go were my thoughts are anymore… Or I’ve got too much sand between the toes.
__________________ Pete - X10 Oldie
|
Back to Top |
|
|
|
|