Active TopicsActive Topics  Display List of Forum MembersMemberlist  Search The ForumSearch  HelpHelp
  RegisterRegister  LoginLogin
PowerHome Macros, Scripts, and Formulas Repository
 PowerHome Messageboard : PowerHome Macros, Scripts, and Formulas Repository
Subject Topic: GetWeather Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: May 27 2009 at 18:13 | IP Logged Quote TonyNo

Just to be sure, you changed LOCALx to your LOCAL variable, correct?

If so, we need to try and determine what that character is if it's not a <CR> or <LF>.
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
veropierre
Groupie
Groupie
Avatar

Joined: May 06 2009
Location: United States
Online Status: Offline
Posts: 47
Posted: May 28 2009 at 08:45 | IP Logged Quote veropierre

I did changed from LOCALx to a LOCAL one no success but when I number(text) it the darn weirdo was gone

Now, and thanks to your help and detailed explanations everything work. I was able to prepare macros for my sprinkler system:

- I get daily Total rain store it in 7 global variables (SUN --> SAT), add them and if the total is over 1" = no watering
- I get the current wind, if it's over 10mph, I wait 5 minutes after waiting 5 times, I cancel watering
- To be finished: I get the actual condition (Overcast, Light Rain, Partially Cloudy, Clear, Rain...) If there is the word "Rain" it then no watering.

By the way, I store the current condition stored in a Variable. How can I 'search' if there is the word Rain in that variable?

Again thank you for your help.
Back to Top View veropierre's Profile Search for other posts by veropierre Visit veropierre's Homepage
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: May 28 2009 at 10:05 | IP Logged Quote TonyNo

Good to hear! I didn't know number() was so tolerant!

"Searching" a string would be done with lastpos(), match(), ph_pos(), or pos().
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
veropierre
Groupie
Groupie
Avatar

Joined: May 06 2009
Location: United States
Online Status: Offline
Posts: 47
Posted: May 28 2009 at 10:10 | IP Logged Quote veropierre

I love the match() idea, I'll try it tonight. Thanks
Back to Top View veropierre's Profile Search for other posts by veropierre Visit veropierre's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: November 17 2010 at 09:50 | IP Logged Quote GadgetGuy

Tony -

Just ran across your Get Weather, which I'm planning to use to turn on the electric blanket if the outside temp is low and the wind chill is above a (yet to be determined) value.

ALl seems to work fine except I get a execution error on the first line of your Macro
Code:
if( {INTERNET FLAG}=0, 999, 1)


I don't have that Global defined, but even if I did when does it get managed?

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
BeachBum
Super User
Super User
Avatar

Joined: April 11 2007
Location: United States
Online Status: Offline
Posts: 1880
Posted: November 17 2010 at 09:55 | IP Logged Quote BeachBum

Ken, that line should be checked (commented out). I believe Tony used that for debugging.

__________________
Pete - X10 Oldie
Back to Top View BeachBum's Profile Search for other posts by BeachBum
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: November 17 2010 at 16:17 | IP Logged Quote GadgetGuy

Thanks kind of what I figured, so just deleted it a while ago.

All works wonderfully!!   

I now grab the WIND SPEED, and HUMIDITY and use my 1-wire read outside TEMP. Then compute the windchill factor from all that and use it all to control the home heating and the bed electric blankets on/off during the night as appropriate.

Hey! Life just hardly ever gets any better than this (especially in Michigan).   

__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
TonyNo
Moderator Group
Moderator Group
Avatar

Joined: December 05 2001
Location: United States
Online Status: Offline
Posts: 2889
Posted: November 17 2010 at 21:39 | IP Logged Quote TonyNo

Good to hear!
Back to Top View TonyNo's Profile Search for other posts by TonyNo Visit TonyNo's Homepage
 
GadgetGuy
Super User
Super User
Avatar

Joined: June 01 2008
Location: United States
Online Status: Offline
Posts: 942
Posted: November 18 2010 at 10:58 | IP Logged Quote GadgetGuy

Tony - thanks to all your insight and help I now have a terrific addition to my home automation arsonal!

Since this thread seems to have a number of efforts that struggled to get this going I thought it might be useful to post my working effort as of 11/18/10 (reflecting the current state of the WeatherUnderground web site).

Since I was only interested in getting the windspeed and humidity (I already have an outside temp probe) and computing the windchill factor, my approach is simplier than your more general effort, but since this provides some current functionality with the web site, I thought it might be useful to others, and provide some further examples.

Also I "enhanced" things a bit since the ph_regexsnap() function is "greedy" in that it does not search for the first, but rather the last string match it can find, I thought it might use less PH compute time to Trim the weather data string to the minimum length as searches were done.

Thus I started by looking for the last data element first (nearest the end of the data file) and then worked toward the beginning, trimming the file length as I went along.

My code is:
Code:
insert into macroheader values ('GET-WTHR STATS','GET WEATHER',0,0,1);
insert into macrodetail values ('GET-WTHR STATS',1,37,'',NULL,'Get key weather stats from the Weather Underground web site.
The data is presented in the following order . . .
TEMP; HUMIDITY; WIND',0,'');
insert into macrodetail values ('GET-WTHR STATS',2,15,'[LOCAL1]',NULL,'ph_geturl( "mobile.wunderground.com/cgi-bin/findweather/getForecast?bra nd=mobile&query=48118")',0,'');
insert into macrodetail values ('GET-WTHR STATS',3,27,'',NULL,'if( left( "[LOCAL1]", 12 ) = "HTTP/1.1 404", "ERROR", "Nextline")',0,'');
insert into macrodetail values ('GET-WTHR STATS',4,37,'',NULL,'Since the string scan functions are ''greedy" and search until they find the last (not the first) match, lets trim the weather file to only a need length. The PRESSURE lable follows the WIND so finding pressure will assure we are past our needed data.',0,'');
insert into macrodetail values ('GET-WTHR STATS',5,15,'[LOCAL2]',NULL,'posw("[LOCAL1]","<tr><td>Pressure</td>")
/* Returns the location of the first char of the sought string */',0,'');
insert into macrodetail values ('GET-WTHR STATS',6,15,'[LOCAL1]',NULL,'left("[LOCAL1]",[LOCAL2]) /* Trim data to just after WIND speed */',0,'');
insert into macrodetail values ('GET-WTHR STATS',7,37,'',NULL,'Web data trimmed to min needed. Now extract variables.',1,'');
insert into macrodetail values ('GET-WTHR STATS',8,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<tr><td>Wind</td>")',0,'');
insert into macrodetail values ('GET-WTHR STATS',9,16,'',NULL,'if( [LOCAL2] = 0, 2, 1)
/* If no match POSW returns a "0", so skip extraction; ELSE Local2 points to start of string */',0,'');
insert into macrodetail values ('GET-WTHR STATS',10,10,'CURWINDSPEED',NULL,'ph_regexsnap(''<td>W ind</td>~255class="nowrap"><b>\(.+\)</b> ; ;'',"[LOCAL1]",[LOCAL2],0)',0,'');
insert into macrodetail values ('GET-WTHR STATS',11,15,'[LOCAL1]',NULL,'left("[LOCAL1]",[LOCAL2]) /* Trim data to eliiminate WIND speed */',0,'');
insert into macrodetail values ('GET-WTHR STATS',12,15,'[LOCAL2]',NULL,'posw( "[LOCAL1]", "<tr><td>Humidity</td>")',0,'');
insert into macrodetail values ('GET-WTHR STATS',13,16,'',NULL,'if( [LOCAL2] = 0, 2, 1)
/* If no match POSW returns a "0", so skip extraction */',0,'');
insert into macrodetail values ('GET-WTHR STATS',14,10,'CURHUMIDITY',NULL,'ph_regexdiff("Humidity</ td>~255<td><b>","</b></td></tr >","[LOCAL1]",[LOCAL2],0)',0,'');
insert into macrodetail values ('GET-WTHR STATS',15,37,'',NULL,'Done getting web data. Now compute Windchill.
*/CURTEMP = TEMP_OUTSIDE-N fetched by READ1WIRE
With these three Vars we can compute the wind chill.',1,'');
insert into macrodetail values ('GET-WTHR STATS',16,10,'CURWINDCHILL',NULL,'round(35.74 + (.6215 * {CURTEMP}) - (35.75 * ({CURWINDSPEED} ^ .16)) + (.4275 * ({CURTEMP} * ({CURWINDSPEED} ^ .16))),1)',0,'');
insert into macrodetail values ('GET-WTHR STATS',17,10,'CURTEMP',NULL,'{TEMP_OUTSIDE-N} /* Copy 1-wire reading over to weather globals */',0,'');
insert into macrodetail values ('GET-WTHR STATS',18,10,'CURWINDCHILL',NULL,'if({CURWINDCHILL}>{CURT EMP},{CURTEMP},{CURWINDCHILL})',0,'');
insert into macrodetail values ('GET-WTHR STATS',19,39,'',NULL,'',0,'');
insert into macrodetail values ('GET-WTHR STATS',20,26,'',NULL,'ERROR',0,'');
insert into macrodetail values ('GET-WTHR STATS',21,36,'',NULL,'"Unable to access Weather Underground web site"',0,'');


In a more human readable form, this looks like . . .


To correlate the code with the target web page, here is a snapshot of the weather page . . .


And here is the HTML Source Code for that image . . .


Hopefully this might help others trying to do something similar.

PS - Just to be complete, the above macro requires that you predefine several Global Variables for the macro to work with. These are:
{CURWINDCHILL}; {CURWINDSPEED}; {CURHUMIDITY}; {CURTEMP}

The {TEMP-OUTSIDE-N} is an unrelated global used by my 1-wire network to store the Outside Temperature (now). For neatness, I just copy that value into the CURxxx weather Globals. Thus you can eliminate my Line 170 BUT you will then need to grab the Current Temp from the web site, using the examples set in the macro above.

ALSO, in posting this PS I see that my Lines 160 and 170 should be interchanged. As is the CURTEMP global is being updated after it is used in the windchill formula, rather than before as it should be!

Edited by GadgetGuy - November 18 2010 at 12:47


__________________
Ken B - Live every day like it's your last. Eventually, you'll get it right!
Back to Top View GadgetGuy's Profile Search for other posts by GadgetGuy
 
krommetje
Super User
Super User
Avatar

Joined: December 29 2004
Location: Netherlands
Online Status: Offline
Posts: 695
Posted: October 07 2012 at 23:44 | IP Logged Quote krommetje

Is there a rewrite for 2.14 coming in the future?


Edited by krommetje - October 07 2012 at 23:46
Back to Top View krommetje's Profile Search for other posts by krommetje Visit krommetje's Homepage
 

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

<< Prev Page of 3
  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