Author |
|
veropierre Groupie
Joined: May 06 2009 Location: United States
Online Status: Offline Posts: 47
|
Posted: June 02 2009 at 11:41 | IP Logged
|
|
|
Is there a way to have matrix variables like DAILY_RAIN(x,y).
For example DAILY_RAIN(1 , x.xx) would be the volume of Rain for Sunday.
I've 7 variables, one per day and I use cases to store the amount of rain. Having Global_Variable(x,y) would simplify my macros considerably.
Any thoughts?
__________________ 37 Insteon Switches + 14 Lamp Modules + 7 ControLinc + 2 RemoteLinc + 3 Insteon Thermostats + 8 Zones Sprinklers + several X10 + Power Home 2.1.4 = Happy Camper
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: June 02 2009 at 22:50 | IP Logged
|
|
|
Pierre,
Currently no array or matrix variables within PowerHome. You can come close with the global system variables though. PowerHome has a set of global variables (100 of them) that are not stored within the database (IOW, its fast) that can be accessed using the ph_setvar_? and ph_getvar_? functions. They would be in the range of ph_setvar_n(3,1,1) (set [GLOBAL1] to 1) thru ph_setvar_n(3,100,1) (set [GLOBAL100] to 1). So very similar to your array variables. They are like the LOCAL and TEMP variables except they are truly global and accessible (changeable too) from anywhere. Only thing that may be a problem is they are in RAM and not stored in the database.
You can also get close to array variables with some programing. Say you wanted an array of 7 global variables, you could create the 7 global vars with names DAILYRAIN1 thru DAILYRAIN7. You could then access these variables like this: ph_setglobal_n("DAILYRAIN[LOCAL1]",5). If LOCAL1 contains a number from 1 to 7, then this function will update the appropriate global variable with the value of 5.
Another technique that arrays are often used for is to have a sliding set of variables where you want to discard the first value and move the second value in 1, the third value into the second, the fourth value into the third, etc. until you newest value goes into the last variable. You could do this with individual variables but its expensive processor-wise. Its far easier to structure the data in a fixed format and then store all the values in a single global. Say you want to store the daily rain amount in the format of x.xx. You could always force this format by using the string function. Say you have a value of .8 inches. You could use: string(.8,"0.00") and the actual value would be output as 0.80...a total of 4 characters. So if you wanted a rotating set of 7 numbers, the resulting global variable may look like this:
0.80|2.10|0.00|1.12|2.23|0.45|1.29
Each of the 7 values are 4 bytes with an extra byte for a vertical bar for readability. If you want to drop the oldest value (0.80 in this case) and add a new value of 4.55, all you need is the following formula:
ph_setglobal_s("YOURGLOBALID",mid(ph_getglobal_s("YOURGLOBAL ID"),6) + "|" + string(4.55,"0.00"))
The resulting global will now look like this:
2.10|0.00|1.12|2.23|0.45|1.29|4.55
Hope this provides some new ideas.
Dave.
|
Back to Top |
|
|
veropierre Groupie
Joined: May 06 2009 Location: United States
Online Status: Offline Posts: 47
|
Posted: June 03 2009 at 09:01 | IP Logged
|
|
|
Thanks Dave... great ideas and I'll have fun playing with.
Is there a way to 'save' the Ram globlal variables to a file?
__________________ 37 Insteon Switches + 14 Lamp Modules + 7 ControLinc + 2 RemoteLinc + 3 Insteon Thermostats + 8 Zones Sprinklers + several X10 + Power Home 2.1.4 = Happy Camper
|
Back to Top |
|
|
device Newbie
Joined: May 26 2009
Online Status: Offline Posts: 33
|
Posted: June 03 2009 at 12:03 | IP Logged
|
|
|
If you don't need the speed you can use globals stored in the database or copy them from the RAM instance to a database instance once you want to save them. (See ph_createglobal, ph_setglobal_n, etc.) Thus far in my limited experience speed has not been a real problem because I am writing in VBScript and create a VBScript variable to hold data that I manipulate and use the database globals as persistent storage. In another thread Dave and I are discussing the possibility creating a set of new format USERDATA tables which could be applicable to applications such as this one if you are comfortable with SQL. Using SQL you can perform the equivalent of your array lookup across potentially a large set of weather data. Of course, you may only care about the last week of weather data so a SQL implementation would probably be overkill.
D
|
Back to Top |
|
|
veropierre Groupie
Joined: May 06 2009 Location: United States
Online Status: Offline Posts: 47
|
Posted: June 03 2009 at 13:15 | IP Logged
|
|
|
I think the VBs path seems a good idea. I'm working a VBs script for my Stats and will use those global variables as well.
I've no problem using SQL but still have to 'perform' with VBs.
__________________ 37 Insteon Switches + 14 Lamp Modules + 7 ControLinc + 2 RemoteLinc + 3 Insteon Thermostats + 8 Zones Sprinklers + several X10 + Power Home 2.1.4 = Happy Camper
|
Back to Top |
|
|