Author |
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: May 05 2005 at 02:13 | IP Logged
|
|
|
dhoward wrote:
Im couldnt quite get the gist of what you were saying . In any event, I checked the formula and some things didnt make sense (to me).1. When the "SODIFF" is in the range of - 1 to 1, then execute the "if" statement that checks the current status. In your "if" statement, you check if the current status is OFF, then set the status to "OFF", else set the status to "ON". |
|
|
yes that is right, The status remains the same...only the time is updated in PH's X10 devicepage....
Quote:
You're probably wanting to switch the setstat statements (turn it on if off and turn it off if on). |
|
|
No, I don't want that, if SODIFF is in the range between -1 to 1 then the temp-difference is too small for me to have an actual status change...
Quote:
If this is want you were trying for, I probably wouldnt fool with it. The ph_x10setstat statement directly updates the database and bypasses any triggers so you wouldnt really gain anything by only setting the stat if it's different. This is probably the part I don't understand...Im not sure why you would want to toggle the status if the difference (whether rising or falling) is the same or within 1 degree. |
|
|
If the Status remains the same, only the time of the status is updated and shown in PH X10 devicepage. By viewing the last time-change of the Statuschange I can see where PH is in his macros/formulas...
Quote:
Another important point is that in the "if" statement, the true and false actions should not "strings". The statement should look like:
if([X10STATV1] = 1,ph_x10setstat(2,"V",1,0,0),ph_x10setstat(3,"V",1,0,0))
|
|
|
Did I type ' ' ???? Oops where did I get this bright idea...
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: May 05 2005 at 15:39 | IP Logged
|
|
|
Ok, that makes more sense then. Doing the setstat like you originally had would only update the lastchange date then.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: May 06 2005 at 01:31 | IP Logged
|
|
|
dhoward wrote:
Ok, that makes more sense then. Doing the setstat like you originally had would only update the lastchange date then. |
|
|
yes that is right and more importantly the time as well.... I think I have the temps working now as I want them. I bought a HP IPAQ 1930 PDA just a few days ago and it turned out that the person who I bought the PDA from is the product manager of Marmitek Netherlands and he asked me what I wanted to do with it... I am going to ask as birthdaypresent a WiFi-SDIO card for my PDA and then I am able not only through my wap/i-mode phone but also through my PDA to manage my H.A. He gave (for free) me something that is called an Rl304 relaisboard for four 20a relaisoutputs, integrating this will be a new project but that doesn't belong in this thread (this is beside the point) He wants to visit me and view how I 've got my H.A. setup and more importantly he wants to see my Temperature readings working and how it is setup. It is small world isn't it.... (let's hope he doesn't steal our ideas and bring it to market)
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: May 09 2005 at 15:34 | IP Logged
|
|
|
Heh,
That is quite a coincidence. I think you'll really enjoy the IPAQ when you've gotten the wireless card. It makes for a quite handly wireless control. Now only if they could make a battery that would power the IPAQ (and it's wireless) for better than about 3 hours straight .
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: May 10 2005 at 01:00 | IP Logged
|
|
|
Off course I will post some pictures in here when I am coding for my Ipaq. For the batteryquuestion.... well when I am home I will put it in the cradle so that I always will have a full battery when I leave....
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 10 2005 at 01:10 | IP Logged
|
|
|
Here is another idea I had the last few days:
How about: converting the temperatures to dim-levels
Needed:
A virtual module which is Status Only with Dim and some code to extract a temperature and convert it to to a dim-level...
What is the use of this?
it shows up in the main PH-screen (local and web) and shows the temp....
I would have to get the temperature which is a GV, round it and then set a Dim-level on the Virtual Module...
could this be done?
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 10 2005 at 08:05 | IP Logged
|
|
|
Sure. I use a virtual device like that to track system volume.
Now, the normal temperature range here is not 0-100, and I see that the current temp where you are is -1°C...
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 10 2005 at 09:43 | IP Logged
|
|
|
Here we use Celcius, so the normal temperature range IS between 0-100 so in this case I am lucky.... and I already came to the conclusion that negative temperatures cannot be shown in this way so I'd have to leave the outside temperature out of this or at least make a formula which makes a negative temperature as status UNKNOWN...
I am going to boil-up some code this weekend and will publish it...
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 10 2005 at 10:13 | IP Logged
|
|
|
For my volume, I do this...
Code:
ph_x10btn ( "Q", 1, 100, {SYS VOL} ) |
|
|
Q1 is my virtual device and SYS VOL is my GV.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 11 2005 at 02:56 | IP Logged
|
|
|
I was thinking in the same direction, however since the temps are measured with 2 digits behind the dot I'd have to round it... I have some time left this afternoon.... will post later!
Peter
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 11 2005 at 09:26 | IP Logged
|
|
|
Testing I did shows that you can pass decimal values without issue.
Let us know what you find.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 14 2005 at 02:45 | IP Logged
|
|
|
Well, just to be on the safe side I made the following formula which is executed just right after PH polls for all the temperatures (4):
Code:
ph_x10btn ( "Q", 1, 100, round(ABS(case (len (mid("{SENSOR3}",1 ,4)) when 3 then {SENSOR3}/10 when 2 then {SENSOR3} when 1 then {SENSOR3} else {SENSOR3}/100)),0) )
|
|
|
The ABS(.. section is actually obsolete or unneccesary but I wanted to be sure that the GV is converted OK.... the Case(... section is added because sometimes the temperatures-webserver doesn't tell PH that there is and ending zero.... To catch this I made the case(... section
Sorry for my late post but familiybusiness kept me from posting this the same evening...
Peter
Edited by krommetje
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 15 2005 at 12:57 | IP Logged
|
|
|
I am having difficulty in writing the outside temp to a Virtual X10 mod... the temp is stored in a GV called TEMP STR as xx.°C....
since the outside temp will vary very much I would have to make a formula which eliminates the °C and determines how many digits are there and if the sign is minus plus or zero... So I thought: NO PROBLEM... just some typing and zap! .... But no Dice The statement case(len(mid .... etc causes PH to cause an error and exits completely...
any thoughts on this?
the code I have so far:
for storing the temp without the °C
Code:
ph_setglobal_s("TEMP STR", mid("{TEMP STR}",1,2))
|
|
|
but since the temp. can be 1 digit value.....
Code:
case(sign(dec("{TEMP STR}")) when - 1 then ph_x10setstat(3,"Q", 7, 0, 0) when 1 then ph_x10btn ( "Q", 8, 100, {TEMP STR} ) else 0)',0)
|
|
|
the combination of these formulas causes an error and PH to exit... I haven't got a clue why...
Peter
Edited by krommetje
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 15 2005 at 14:26 | IP Logged
|
|
|
Avoiding the crash issue , just do a
Code:
SET GLOBAL {YourGV} ph_replaceall( "{YourGV}", "°C", "") |
|
|
This will get rid of the "°C", if it is there, and delete it. You could also assign the result of the formula to another variable instead, to not change the actual GV.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 15 2005 at 18:16 | IP Logged
|
|
|
Peter,
As Tony showed, this is the best way to get rid of the "°C". I checked your code, and it looks OK, so I cant figure why PowerHome would exit. PH should never exit from just running a formula. If possible, could you send me the data that is in TEMP STR and the actual macro, etc. that causes this behavior? I'll track down what the problem is and fix it so it may still error, but won't exit.
Another possibility where it's easy to get confused is concerning variable substitution. When you enclose a global variable with braces, this is signifying "variable substitution". The way this works is that PRIOR to the formula being evaluated, the entire formula is searched for braces (GV's) and brackets (System Var's) and replaced with the then current value. If you're used to programming, this will be contrary to your typical understanding of variables. Consider the statement:
ph_setglobal_s("TEMP STR",ph_replaceall("{TEMP STR}","°C","")) + case(sign(dec("{TEMP STR}")) when - 1...
In the above statement, you've got the global variable "TEMP STR" enclosed with braces in the ph_replaceall function and the case statement. In normal programming, you would think that the output of the ph_replaceall would be assigned to the TEMP STR global (replacing it's previous contents) and this new value would then be used in the case statement. It doesnt. Prior to being evaluated, both GV occurrences will be "substituted" with the actual global variable value. After all substitutions have taken place, then the formula is evaluated. The global variable TEMP STR will have it's contents replaced with the new value, but the case statement will execute with the old value. If you're building formulas together in this manner, you'll need to forego variable substitution and use something like:
ph_setglobal_s("TEMP STR",ph_replaceall("{TEMP STR}","°C","")) + case(sign(dec(ph_getglobal_s("TEMP STR"))) when - 1...
or
ph_setglobal_s("TEMP STR",ph_replaceall(ph_getglobal_s("TEMP STR"),"°C","")) + case(sign(dec(ph_getglobal_s("TEMP STR"))) when - 1...
The main thing to remember is that variable substitution is performed 1 time only PRIOR to the formula being evaluated. The ph_getglobal and ph_setglobal, etc. functions operate at evaluation time.
Not saying that you have this problem, but it's easy to make this mistake (and hard to track down) and this looked like a good time to mention it for all .
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: December 20 2005 at 06:51 | IP Logged
|
|
|
Sorry for me being away a few days but at work things are really busy...
so in case of a formula first GV's are substituted and then evaluated....
the best way to program in future with GV's is to first subst. GV's when needed and then the rest? I haven't implemented the code supplied by you and tonyno since things are really busy right now but will this week.
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 20 2005 at 11:25 | IP Logged
|
|
|
Peter,
I know what you mean about being busy at work. Year end is hell .
The {} and [] symbols around GV's and System vars is from very early versions of PowerHome prior to the formula functions. At the time, it was the ONLY way to reference a variable from within a formula and they've remained for compatibility and as a shortcut since it's easier to read and write "{GLOBALVAR}" instead of ph_getglobal_s("GLOBALVAR").
As long as you don't change the value of the variable within a formula (either directly or indirectly through some action), then you're safe using the variable substitution. However, if the value of a variable is subject to change within the formula (and you're interested in the "changed" value vs. the "original" value), then the variable substitution will fail.
Consider the following standard VB style programming statement of adding 1 to a variable:
x = x + 1
PowerHome provides functions to make this easier (ph_addtoglobal), but in leui of this function, you could code something like below:
ph_setglobal_a("GV1",{GV1} + 1)
The above statement will work just fine. We are changing the GV1 global, but were not referencing it after the change. If prior to executing the formula, GV1 contains 5, GV1 will contain 6 after being evaluated. In PowerHome, what will occur first will be a variable substitution. After this step, the formula will look like:
ph_setglobal_a("GV1",5 + 1)
The next step will be the above formula being evaluated. The 5 and 1 are added together and the result will then be passed as a parameter to the ph_setglobal_a function. This function will then set the value 6 to the GV1 global.
Now, if you want to use your newly incremented GV1 variable right away in the same formula, you may be tempted to do something like:
ph_setglobal_a("GV1",{GV1} + 1) * 0 + {GV1}
Essentially, we've got the previous formula with a little more. The important thing to remember in the above sample is that every formula or function produces a result (either string, date, time, numeric, etc). So the result of our ph_setglobal_a function will return a numeric value indicating success or failure of the function. If everything works, the value 0 will be returned. Im not really concerned in the above formula whether I had success or failure, but I want to make sure that whatever value is returned does not interfere with the next part of my formula which is referencing the GV1 global. So, I multiply the result of the ph_setglobal_a function by 0, effectively making whatever the result returned by the function always a 0. A formula is basically just math so to continue on evaluation, I have a "+" sign and then I reference the GV1 global.
If we step through PowerHome's evaluation of the above formula, the first thing that happens is variable substitution:
ph_setglobal_a("GV1",5 + 1) * 0 + 5
Here we can already see what we've done wrong. We've substituted all instances of GV1 with it's current value (5). Now sometimes, this may be the desired effect, but in this case, I want to use the "new" value of GV1. At this point, PowerHome would then evaluate the formula:
ph_setglobal_a("GV1",6) * 0 + 5
The very next step of the evaluation executes the ph_setglobal_a function. The GV1 variable will now contain the value of 6 and the function returns a value of 0 indicating success.
0 * 0 + 5
We continue on and get 0 + 5 which results in 5 when in actuality, I wanted 6. In this situation, we would need to abandon the second substitution of the GV1 global and instead use a function:
ph_setglobal_a("GV1",{GV1} + 1) * 0 + ph_getglobal_n("GV1")
If we evaluate the above through PowerHome, after variable substitution, we'll have:
ph_setglobal_a("GV1",5 + 1) * 0 + ph_getglobal_n("GV1")
The result is now evaluated:
ph_setglobal_a("GV1",6) * 0 + ph_getglobal_n("GV1")
The ph_setglobal_a function is executed, setting the GV1 global to 6 and returning 0:
0 * 0 + ph_getglobal_n("GV1")
Evaluation continues right to left (paranthesis can change the evaluation order):
0 + ph_getglobal_n("GV1")
The ph_getglobal_n function is executed and will return the current value of GV1 (6):
0 + 6
And our final result will be 6.
Soooo, the variable substitution is a good thing and definately has it's uses. It just helps to be aware of what's going on behind the scenes so you know when to use it and when not to.
The PowerHome formula's is a complicated subject and easy to get confused with. If anyone has any further questions or misunderstandings, please let me know so I can try to clear it up. I tend to ramble when Im trying to explain things and sometimes my message gets lost .
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 20 2005 at 13:37 | IP Logged
|
|
|
In a related issue, I have a question on ph_addtovar and GV's. The Help file references an ID number...
Quote:
The number of the system variable. 1 thru 10 are valid for local and temp variables. 1 thru 20 are valid for global variables. |
|
|
What number does this refer to? Is this old?
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: December 22 2005 at 11:13 | IP Logged
|
|
|
Heh,
In addition to what we call "Global Variables" which are stored in the database and therefore persistant, PowerHome also has global system variables. System variables are stored within RAM. The global system variables have a substitution form of [GLOBAL1] thru [GLOBAL20]. These variables are accessible throughout PowerHome.
HTH,
Dave.
|
Back to Top |
|
|
TonyNo Moderator Group
Joined: December 05 2001 Location: United States
Online Status: Offline Posts: 2889
|
Posted: December 22 2005 at 12:41 | IP Logged
|
|
|
OK, so there is no "addtovar" function for normal GV's?
|
Back to Top |
|
|