Author |
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 22 2005 at 17:29 | IP Logged
|
|
|
That makes sense. Glad it's all worked out and doing what you expect now.
Good luck and keep us posted .
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 23 2005 at 09:45 | IP Logged
|
|
|
dhoward wrote:
That makes sense. Glad it's all worked out and doing what you expect now.Good luck and keep us posted . |
|
|
well, I could use some hints in regarding to using code on how to set limits.... When I type {SENSOR0} in the evaluator, the value is returned, when I want the length of the string I use len ("{SENSOR0}") the lengh is returned, but when I want to use CASE({SENSOR0} when > 3000 then ...
or when I use CASE ("{SENSOR0}"when >3000 then ...in both instances the formula evaluates to a ! I am still not sure when to use "{SENSOR0}" or {SENSOR0}... What I do at this point is recalculate the value of the readfile to a numeric value without a dot or comma... so 30 degrees celcius is 3000 in the GV It should be possible to use math functions with that. To recalculate the readfile GV's I use: ph_setglobal_a("NEWSENS1",ph_replaceall("{SENSOR0}",",",".") ) and this results into a nice value as described above...How do I go along into setting limits?
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 23 2005 at 11:30 | IP Logged
|
|
|
The difference between using "{SENSOR0}" and {SENSOR0} will usually be whether you want a string or a numeric. Strings must be enclosed in either single or double quotes.
I say "usually", because it also depends upon the data. When PowerHome encounters a formula, the first thing it does is Global and System variable substitution. It does this by searching for the { (Open Brace) and [ (Open Bracket) characters and matching them with their corresponding close brace and close bracket characters. It will then take the ID enclosed within these delimiters and look them up in the Global variable table and System variable list. Their corresponding values are substituted as is. This substitution process is repeated until the limit is reached or no more remain. At this point, the formula will be passed to the evaluator.
Now...a formula always evaluates to an end result. This result can be numeric, alpha, time, date, boolean, or datetime. So if you have "{SENSOR0}" as your formula, it will return a string...no matter what is the value contained within SENSOR0. If you have a formula that is: {SENSOR0}, the data type returned, will depend upon the value stored in SENSOR0. If SENSOR0 contains: 345 then the result is numeric. If SENSOR0 contains: 2005-02-22 then the result will be a date. If SENSOR0 contains: 'This is a test' then the result will be a string (ONLY if the single quotes are actually part of the value). In the last case, if SENSOR0 contained only the text "This is a test" without the quotes, you would get an error (the ! symbol). This is because a string MUST be enclosed in single or double quotes and at evaluation time (after substitution) the previous example has text without quotes.
Now, since you're wanting to evaluate limits, you would definately want to work with numerics. You can use ">" and "<" symbols with strings, but you will not get the results you want since strings are handled differently. A case in point is that "35" is greater than "3000" when comparing the two strings.
Now, in order to work with your values as numerics, then your GV's MUST actually evaluate out to a number. This means no commas or other non-numeric symbols. This leaves you just with the numerals 0 thru 9, the decimal point, and the - (minus sign). I should note here that the - character (minus sign) is a multipurpose symbol. This symbol can be part of an ID, part of a date, etc. as well as symbolize a negative number or subtraction. When using the minus sign in math operations, ALWAYS place a space before and after the minus sign otherwise the symbol will be interpreted to be something other than for math operations.
Since you're on the right track and are using a different GV (NEWSENS1) to hold a true numeric, you only have a slight problem with your case statement. You would structure is like this:
case({NEWSENS1} when is > 3000 then ... when is < 1000 then .... when 1500 to 1600 then ... when 1701,1702,1703 then ... else ...)
No quotes surround the {NEWSENS1} because we want this value to be a numeric. The above statement is probably not exactly what you're wanting for limit checking, but I wanted to illustrate the different possibilities for checking values. In your second example: CASE("{SENSOR0}" when > 3000 then ... failed for two reasons. First, you were comparing a string to a numeric which just doesnt work. The second reason it failed is because you're missing the "is" keyword (when is > 3000). Your first example would fail again because of the missing "is" but may also be failing if the value in {SENSOR0} is not truly a numeric (contains comma's, etc).
I hope this helps and didnt muddy the waters further. It's difficult to explain effectively but once it "clicks" it all makes sense.
Let me know,
Dave.
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 23 2005 at 17:08 | IP Logged
|
|
|
Peter,
I think I have come across something that may help you. While researching internationalization issues, Ive come across a function that should help those who use a comma as the decimal point and a period as the separator.
The "dec" function will take a string and convert it to a decimal number using the current locale settings. In your case: dec("123,45") will be converted internally into a decimal number equivalent to 123.45 over here in the states. I changed my locale settings over here and verified that it works.
Test this out and let me know if this helps with some of your problems.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 23 2005 at 17:22 | IP Logged
|
|
|
No this actually clears some up, the "IS" word was unknown to me. As far as the GV's go, I was on the right track as I realise now... Your example statement will be a big help...
I want to add some Case Statements to the macro which is responsible for inporting the readlcd.txt values. When c certain value has been reached I want to receive an e-mail. Perhaps even better would be to execute an hourly macro which checks less important values... Together with my smoke alarms which are connected to PH through an SM10 I think a reliable warning sustem can be made. Also the fact that my shutters open and emergency lighting light-up when an alarm has been given adds to the security. But I am wandering off... I was planning to use Case statements in the formula/Macro but since I detect some of your doubts into this, I'd gladly hear your insight in this as my Knowlegde of the PH language is by far not far enough...
wat works now:
the macro which opens the shutters, switches on the emergency lighting and sends an alarm through e-mail and blinks the porch-lights when a Fire/Smoke-alarm has been given. Siren-1 is activated....
the temperature measurement, Carbon Monoxide detection, Natural Gas detection ... if the CO of NG is present an instant alarm is given and an e-mail sent, shutters are opened, Central Ventilation is activated, and siren-2 is activated.....
What has to be done:
Warning of certain limits in temperature measurements through e-mail (temperature too high gives me a warning)
e.g. if the inside temp is above 30degr.C or when the solar boiler is above 90degr.C... stuff like that....
as you see, the project is nearly finished, just some code that will help me monitor the security status when I am away from home. After that I have to search for a new project that will be possible on PH...but that is yet to come...first thing is first...
Peter
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 23 2005 at 17:29 | IP Logged
|
|
|
dhoward wrote:
I think I have come across something that may help you. While researching internationalization issues, Ive come across a function that should help those who use a comma as the decimal point and a period as the separator. The "dec" function will take a string and convert it to a decimal number using the current locale settings. In your case: dec("123,45") will be converted internally into a decimal number equivalent to 123.45 over here in the states. I changed my locale settings over here and verified that it works. |
|
|
WOW, that would be helpfull, I will try something the comeing days and test it.. (I working late the next 5 days, I work as a subway/bus driver so there is some time to do this when my daughter sleeps between 12am and 4 pm)....... many thanks... I'll let you know how this turns out...
Peter
Peter
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 23 2005 at 17:32 | IP Logged
|
|
|
Peter,
No doubts on the CASE statement. This is exactly the statement you should use, just not exactly how I gave it in my previous post as I was just trying to depict the various ways you could make comparisons in the case.
With the newly found "dec" function, you should be able to get rid of the NEWSENS1 GV and the ph_replaceall function. Since most limit checking will just consist of min and max, my example case statement using what we've learned (and what I know of your system) would be:
case(dec("{SENSOR0}") when is > 3000 then ... when is < 1000 then ... else ...)
Let me know how this goes.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: February 27 2005 at 05:17 | IP Logged
|
|
|
dhoward wrote:
No doubts on the CASE statement. This is exactly the statement you should use, just not exactly how I gave it in my previous post as I was just trying to depict the various ways you could make comparisons in the case. |
|
|
Formulas are up and running, now when certain limits are reached I get an e-mailwarning... Urgent warnings are directly sent through my mailserver to my smartphone, less urgent mails are sent to my home-address.
Quote:
With the newly found "dec" function, you should be able to get rid of the NEWSENS1 GV and the ph_replaceall function. Since most limit checking will just consist of min and max, my example case statement using what we've learned (and what I know of your system) would be:
case(dec("{SENSOR0}") when is > 3000 then ... when is < 1000 then ... else ...) |
|
|
Works as a barnburner! In this way I can discard the ph_replaceallfunction which did not exactly meet my needs, however I am gratefull for TonyNo to point me to this function. Now for the next project!
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: February 28 2005 at 13:50 | IP Logged
|
|
|
Peter,
Glad to hear that this is a success so far. Good ol' Tony keeps me on my toes .
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: March 04 2005 at 07:16 | IP Logged
|
|
|
I stumbled on a new problem:
when a fire-alarm has been given, the global variables cannot be updated again, for the record, here is the macro and the trigger used for initiating a fire-alarm:
The Macro:
insert into macroheader values ('VEILIGHEIDSPROTOCOL','VEILIGHEIDSPROTOCOL',0,0,1);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',1,12,'K',4,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',2,12,'K',102,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',3,12,'K',5,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',4,12,'K',102,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',5,1,'SETUP EMAIL',0,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',6,20,'',NULL,'"{MAILFIRE}"',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',7,7,'',NULL,'5000',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',8,1,'SETUP EMAIL_1',0,'',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',9,20,'',NULL,'"{MAILFIRE}"',0);
insert into macrodetail values ('VEILIGHEIDSPROTOCOL',10,39,'',NULL,'',0);
and here is the trigger:
insert into triggers values ('BRANDALARM','BRANDALARM','VEILIGHEIDSPROTOCOL',4,'A',1,2,' 1',1,1,0);
When A fire alarm has been given, the next time, the temperatures have to be updated the screen says (copy&paste):
Global Variable Sensor0 Updated from 22.67 to
This is a mistery for me, can anyone help?
Peter
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: March 04 2005 at 11:27 | IP Logged
|
|
|
Peter,
I imported your macro and trigger and looked at them and could find nothing that would affect the SENSOR0 global variable. As a matter of fact, I couldnt even find the SENSOR0 GV reference anywhere within the trigger or macro. It's possible that something in the "SETUP EMAIL" or "SETUP EMAIL_1" macros may be corrupting something but I cant tell since you didnt post them.
If you can post a little more of your code, Im sure we can track it down and fix it.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: March 04 2005 at 19:51 | IP Logged
|
|
|
OK, here is SETUP_EMAIL:
insert into macroheader values ('SETUP EMAIL','SETUP EMAIL',0,0,1);
insert into macrodetail values ('SETUP EMAIL',1,15,'[EMAILNAME]',NULL,'"peter.krom@imail.nl"',0);
insert into macrodetail values ('SETUP EMAIL',2,15,'[EMAILSUBJECT]',NULL,'"PowerHome Update"',0);
insert into macrodetail values ('SETUP EMAIL',3,15,'[DIALUPUSER]',NULL,'"peter"',0);
insert into macrodetail values ('SETUP EMAIL',4,15,'[DIALUPPASSWORD]',NULL,'"xxxx"',0);
and here is SETUP_EMAIL_1
insert into macroheader values ('SETUP EMAIL_1','SETUP EMAIL',0,0,1);
insert into macrodetail values ('SETUP EMAIL_1',1,15,'[EMAILNAME]',NULL,'"ankie.krom@imail.nl"',0);
insert into macrodetail values ('SETUP EMAIL_1',2,15,'[EMAILSUBJECT]',NULL,'"PowerHome Update"',0);
insert into macrodetail values ('SETUP EMAIL_1',3,15,'[DIALUPUSER]',NULL,'"peter"',0);
insert into macrodetail values ('SETUP EMAIL_1',4,15,'[DIALUPPASSWORD]',NULL,'"xxxx"',0);
Could it have something to do with the fact that I retrieve te msgtext, for the mail being sent, from the GV-List as "{MAILFIRE}"
Is it better to replace the "{MAILFIRE}" GV with the actual msgtext inside the macro veiligheidsprotocol?
Peter
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: March 05 2005 at 19:44 | IP Logged
|
|
|
Peter,
I dont see how either of the Setup Email macros could be causing you problems.
You should also be able to retrieve the text from the GV as "{MAILFILE}" without a problem.
When you say the global variables cant be updated, you're talking about the SENSOR0 thru SENSOR4 GV's right?
If so, what is the macro or code that moves the values of SENSOR0 thru SENSOR4 to the MAILFILE GV? The problem could lie in there.
Also, since we've had so many iterations, could you post your latest code that updates the SENSOR0 thru SENSOR4 GV's?
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: March 06 2005 at 03:22 | IP Logged
|
|
|
dhoward wrote:
I dont see how either of the Setup Email macros could be causing you problems.
You should also be able to retrieve the text from the GV as "{MAILFILE}" without a problem. |
|
|
OK, that is good to know.
Quote:
When you say the global variables cant be updated, you're talking about the SENSOR0 thru SENSOR4 GV's right? |
|
|
Yes, all 4 sensors,
Quote:
If so, what is the macro or code that moves the values of SENSOR0 thru SENSOR4 to the MAILFILE GV? The problem could lie in there. |
|
|
I haven't implemented this code yet, the formula for transferring the values into the e-mailbody exists only in a textfile (projectstodo.txt) and is not run in powerhome....
Quote:
Also, since we've had so many iterations, could you post your latest code that updates the SENSOR0 thru SENSOR4 GV's? |
|
|
We thought of different ways to get the temps into PH, the first was by getting it from the gameporttemp internal webserver but the webserver also makes a temporary file called templcd.txt, the first 3 temperatures are collected from the TEMPLCD.TXT like this:
ph_setvar_s(1,1,ph_readfile("templcd.txt")) + ph_setglobal_s("SENSOR00",mid(ph_getvar_s(1,1),5, - 6 + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"C")) * 0 + ph_getvar_n(1,2))) +
ph_setglobal_s("SENSOR01",mid(ph_getvar_s(1,1),ph_getvar_n(1 , 2) + 8, - ph_getvar_n(1,2) - 9 + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"C",ph_getvar_n(1,2) + 8)) * 0 + ph_getvar_n(1,2))) + ph_setglobal_s("SENSOR02",mid(ph_getvar_s(1,1),ph_getvar_n(1 , 2) + 9, - ph_getvar_n(1,2) - 10 + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"C",ph_getvar_n(1,2) + 9)) * 0 + ph_getvar_n(1,2)))
SENSOR3-value is imported into PH the oldfashioned way because it isn't written in the templcd.txt:
ph_setglobal_a("SENSOR3",round(double(ph_rtne(ph_setvar_s(1, 1,ph_getwburl("http://127.0.0.1:81/sensor3.htm",10)) + ph_setvar_a(1,2,pos(ph_getvar_s(1,1),"<BODY>")) + ph_setvar_a(1,3,pos(ph_getvar_s(1,1),"</BODY>"))) + mid(ph_getvar_s(1,1),ph_getvar_n(1,2) + 6,ph_getvar_n(1,3) - ph_getvar_n(1,2) - 7)),2))
DO these formulas ring a bell again?
The hardware-setup for the firealarm consists of 2 smokedetectors which are connected and then connected to an SM10 universal X10 transmitter.... When an alarm is given, the SM10 sends a1-on and when the alarm is no longer valid, it sends s1-off, the formulas and macros for this you've already seen in previous posts...
Peter
---
You can read about my hardwaresetup on my website
---
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: March 07 2005 at 11:06 | IP Logged
|
|
|
Peter,
Ive been looking at this over and over trying to figure where the problem lies. The only thing that I can come up with is that PowerHome is not able to read the "templcd.txt" file. Thats why the GV's are set to null.
Perhaps after a fire alarm is triggered, the default directory of PowerHome is changed and the templcd.txt file cant be found. I would try changing the "ph_readfile("templcd.txt"))" part of the formula to include the path such as: ph_readfile("c:\program files\powerhome\templcd.txt")).
I cant think of anything else, but from what I know, it would appear that PowerHome is having problems with the templcd.txt file.
Let me know,
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: April 11 2005 at 05:55 | IP Logged
|
|
|
Hi Dave,
I did A test and still updating the tempatures after a firealarm is impossible. The temps are set to zero.... What this causes I don't know but now after a period of 37 days of flawlesly working, I got a ghost alarm on the address of the firealarm, Is there a formula that can be made when an A1-on and an A1-off are received within let's say 2 seconds, the firealarm is not tripped or a testmsg can be logged into the event log?
Peter
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: April 11 2005 at 15:11 | IP Logged
|
|
|
Peter,
Should be easily doable with a couple of triggers and a GV.
Just create a trigger that fires on A1 on with a formula that sets a GV to the current time.
Next create a trigger that fires on A1 off. In the boolean field, compare the difference between the current time and the value saved in the GV. If it's less than two seconds, then return a 1 else return a 0. If the boolean field returns a 1, then the action is performed. Just make the action whatever you would like (set another GV, post a usermessage to the log, etc.)
Let me know if the above is not clear and I'll put together the SQL for you.
BTW, after a fire alarm occurs and your GV's are no longer updated, does your templcd.txt still contain the correct temps?
HTH,
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: April 12 2005 at 02:43 | IP Logged
|
|
|
dhoward wrote:
Let me know if the above is not clear and I'll put together the SQL for you. |
|
|
Well I am already on it but I would like to see your SQL anyway so that I can compare your code with mine... The more I can learn... right?
for adding the time to a global variable I would add for trigger A1ON ph_setglobal_a("A1ON", Now())
and for calculating the difference between i would use
ph_secondsdiff({A1ON}, now()) and this formula I would place in the trigger A1OFF...
Am I on the right track????
Quote:
BTW, after a fire alarm occurs and your GV's are no longer updated, does your templcd.txt still contain the correct temps? |
|
|
Yes, the temps are correctly stored in the file templcd.txt after a firealarm. However if I Reinitialize and I poll for the temps the "oldfashioned way" by getting them directly at the gameporttemps webserver, all temps are stored correctly. The only thing I can do is Exit and Restart... The more info the server sends when there is a firelarm, the better it is to have an overview... I am working on Carbon Dioxide measurement but that is more difficult then I thought...
Peter
Edited by krommetje
|
Back to Top |
|
|
dhoward Admin Group
Joined: June 29 2001 Location: United States
Online Status: Offline Posts: 4447
|
Posted: April 12 2005 at 10:42 | IP Logged
|
|
|
Peter,
Yep, you're on the right track. Below is my SQL for the two triggers and the GV. If you were using the latest version 1.03.4.4, then I would use a couple of different functions which automatically catch if the A1 ON and A1 OFF span midnight.
insert into global_variables values ('A1TIME','00:00:00');
insert into triggers values ('A1ON','A1ON','ph_setglobal_a("A1TIME",now())',4,'A',1,2,'1 ',1,0,2);
insert into triggers values ('A1OFF','A1OFF','ph_usermessage("Perform your desired action here.")',4,'A',1,3,'if(secondsafter(ph_getglobal_t("A1TIME") ,now()) <= 2,1,0)',1,0,2);
Concerning the lcdtemp.txt...After a firealarm occurs, can you check what is returned from the following formula:
ph_fileexists("lcdtemp.txt")
Based on the info we have so far, it still appears that PowerHome either cannot find or cannot open the lcdtemp.txt file. The above formula will help us narrow it down.
Dave.
|
Back to Top |
|
|
krommetje Super User
Joined: December 29 2004 Location: Netherlands
Online Status: Offline Posts: 695
|
Posted: April 12 2005 at 19:28 | IP Logged
|
|
|
dhoward wrote:
insert into global_variables values ('A1TIME','00:00:00'); |
|
|
OK, understood....
Quote:
insert into triggers values ('A1ON','A1ON','ph_setglobal_a("A1TIME",now())',4,'A',1,2,'1 ',1,0,2); |
|
|
OK understood also...
Quote:
insert into triggers values ('A1OFF','A1OFF','ph_usermessage("Perform your desired action here.")',4,'A',1,3,'if(secondsafter(ph_getglobal_t("A1TIME") ,now()) <= 2,1,0)',1,0,2);
|
|
|
a question: Instead of ph_usermessage("... I would have to call the macro which is responsible for sending mails, opening the shutters and so forth?
Quote:
Concerning the lcdtemp.txt...After a firealarm occurs, can you check what is returned from the following formula:
ph_fileexists("lcdtemp.txt")
Based on the info we have so far, it still appears that PowerHome either cannot find or cannot open the lcdtemp.txt file. The above formula will help us narrow it down. |
|
|
OK I'll test this... If so.. what could a solution be?
Peter
Edited by krommetje
|
Back to Top |
|
|
|
|