Weather Underground Plugin

Posted on
Sun Jul 02, 2017 12:49 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

loafbread wrote:
That's it. Thanks. Its works on all three stations I track.

Good deal. Glad it's working for you.

Cheers!

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Mon Jul 03, 2017 3:51 pm
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

The Polly daily weather forecast is working very nicely in my Good Morning announcement. I have combined it with the current temp/humidity from the MS6 on my house and other information about date, time, day of week, etc. The only variable from the WU plugin I use presently is foreText1. Will there be a way to modify that variable to remove F, speak verbose wind direction, and remove decimal places. Is there an interim workaround?

John R Patrick
Author of
Home Attitude

Posted on
Mon Jul 03, 2017 8:41 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

Hi John - the forecast text comes directly from Weather Underground and I report it as I receive it; I don't do anything to modify the text. To scrub it the way you suggest would require a series of substitutions to be run on each forecast text state--first to remove the F (or C) and then to convert the wind abbreviation to its verbose value. This would need to be done to 8 strings and I'm hesitant to put this kind of load on the plugin. But I can help with this script which you could modify to save into a variable and then speak that.

Code: Select all
import re

string = "Partly cloudy skies. A stray shower or thunderstorm is possible. Low 62F. Winds ENE at 5 to 10 mph."  # This will come from the device state foreText1

def fixTemp(match):
    return match.group(1)

def fixWind(match):
    wind_dict = {'N': 'north', 'NNE': 'north northeast', 'NE': 'northeast', 'ENE': 'east northeast', 'E': 'east', 'ESE': 'east southeast', 'SE': 'southeast',
                 'SSE': 'south southeast', 'S': 'south', 'SSW': 'south southwest', 'SW': 'southwest', 'WSW': 'west southwest', 'W': 'west',
                 'WNW': 'west northwest', 'NW': 'northwest', 'NNW': 'north northwest'}

    match = match.group(1).replace(' ', '')
    return u" {0} ".format(wind_dict[match])
   
string_1 = re.sub(r'([0-9]+)([F|C])', fixTemp, string)
string_2 = re.sub(r'( [NESW]+ )', fixWind, string_1)

print(string_2)  # This will become a save to variable statement.

Which yields the output: "Partly cloudy skies. A stray shower or thunderstorm is possible. Low 62. Winds east northeast at 5 to 10 mph."

The regular expressions could probably be tightened up, but it gets the job done. If you have any questions, please let me know.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jul 04, 2017 12:25 pm
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

I modified the script to my environment, but getting some errors. Also, question, is it possible to add something to round up the temp?

import re # provides regular expressions

# string = "Partly cloudy skies. A stray shower or thunderstorm is possible. Low 62F. Winds ENE at 5 to 10 mph."
# This will come from # the device state foreText1
# get the WU plugin device
dev = indigo.devices[54780111] # WU plugin device
# access the state through the states property on the main window
string = dev.states["foreText1"]

def fixTemp(match):
return match.group(1)

def fixWind(match):
wind_dict = {'N': 'north', 'NNE': 'north northeast', 'NE': 'northeast', 'ENE': 'east northeast', 'E': 'east', 'ESE': 'east southeast', 'SE': 'southeast', 'SSE': 'south southeast', 'S': 'south', 'SSW': 'south southwest', 'SW': 'southwest', 'WSW': 'west southwest', 'W': 'west', 'WNW': 'west northwest', 'NW': 'northwest', 'NNW': 'north northwest'}

match = match.group(1).replace(' ', '')
return u" {0} ".format(wind_dict[match])

string_1 = re.sub(r'([0-9]+)([F|C])', fixTemp, string)
string_2 = re.sub(r'( [NESW]+ )', fixWind, string_1)

# print(string_2) # This will become a save to variable statement.
new_forecast = indigo.variable.create("string_2")
Attachments
Screenshot 2017-07-04 14.24.41.png
Screenshot 2017-07-04 14.24.41.png (47.68 KiB) Viewed 1999 times

John R Patrick
Author of
Home Attitude

Posted on
Tue Jul 04, 2017 1:35 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

You are so close! What I would recommend is to use an embedded script window instead of using the Python shell. The script window allows you to make changes much more easily. The script below is using my device and variable numbers; you'll have to change those to match your IDs.

Code: Select all
import re

dev = indigo.devices[1149686816]
string = dev.states["foreText1"]

def fixTemp(match):
    temp = float(match.group(1))  # Note this new bit covers the request to round the temperature.
    temp = round(temp, 0)
    temp = int(temp)
    return str(temp)

def fixWind(match):
    wind_dict = {'N': 'north', 'NNE': 'north northeast', 'NE': 'northeast', 'ENE': 'east northeast', 'E': 'east', 'ESE': 'east southeast', 'SE': 'southeast',
                 'SSE': 'south southeast', 'S': 'south', 'SSW': 'south southwest', 'SW': 'southwest', 'WSW': 'west southwest', 'W': 'west',
                 'WNW': 'west northwest', 'NW': 'northwest', 'NNW': 'north northwest'}

    match = match.group(1).replace(' ', '')
    return u" {0} ".format(wind_dict[match])
   
string_1 = re.sub(r'([0-9]+)([F|C])', fixTemp, string)
string_2 = re.sub(r'( [NESW]+ )', fixWind, string_1)

indigo.variable.updateValue(1308289177, string_2)

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jul 04, 2017 2:54 pm
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

You said, "an embedded script window instead of using the Python shell." I am catching on, but missing something really basic. I actually did use an embedded script window. The reason for the Python shell was so I could see the results of the code by printing variables. How do I do that in the embedded script window? I.E. I type print "Hello, world" in the window, where does the result get displayed? It does not appear in the log.

John R Patrick
Author of
Home Attitude

Posted on
Tue Jul 04, 2017 3:10 pm
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

Still getting indentation error...

>>> match = match.group(1).replace(' ', '')
File "<console>", line 1
match = match.group(1).replace(' ', '')
^
IndentationError: unexpected indent
>>> return u" {0} ".format(wind_dict[match])
File "<console>", line 1
return u" {0} ".format(wind_dict[match])
^
IndentationError: unexpected indent
>>>

John R Patrick
Author of
Home Attitude

Posted on
Tue Jul 04, 2017 3:19 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

wideglidejrp wrote:
You said, "an embedded script window instead of using the Python shell." I am catching on, but missing something really basic. I actually did use an embedded script window. The reason for the Python shell was so I could see the results of the code by printing variables. How do I do that in the embedded script window? I.E. I type print "Hello, world" in the window, where does the result get displayed? It does not appear in the log.

Yes, that's right. Indigo eats print statements. Instead, use indigo.server.log('Hello world.")

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jul 04, 2017 3:25 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

wideglidejrp wrote:
Still getting indentation error...

The indentation errors are likely coming from how you're inputting the script lines into the shell. If you paste the code into a script window, you should be okay.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jul 04, 2017 3:42 pm
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

I repasted the two indented statements and that fixed the error but now getting an error with the strings. Strange. I wonder if this has anything to do with me using vnc from another Mac on the LAN to the one running Indigo.

John R Patrick
Author of
Home Attitude

Posted on
Tue Jul 04, 2017 3:54 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

wideglidejrp wrote:
I repasted the two indented statements and that fixed the error but now getting an error with the strings. Strange. I wonder if this has anything to do with me using vnc from another Mac on the LAN to the one running Indigo.

I don't think that should make a difference. If you copy this entire code block:

Code: Select all
import re

dev = indigo.devices[1149686816]
string = dev.states["foreText1"]

def fixTemp(match):
    temp = float(match.group(1))  # Note this new bit covers the request to round the temperature.
    temp = round(temp, 0)
    temp = int(temp)
    return str(temp)

def fixWind(match):
    wind_dict = {'N': 'north', 'NNE': 'north northeast', 'NE': 'northeast', 'ENE': 'east northeast', 'E': 'east', 'ESE': 'east southeast', 'SE': 'southeast',
                 'SSE': 'south southeast', 'S': 'south', 'SSW': 'south southwest', 'SW': 'southwest', 'WSW': 'west southwest', 'W': 'west',
                 'WNW': 'west northwest', 'NW': 'northwest', 'NNW': 'north northwest'}

    match = match.group(1).replace(' ', '')
    return u" {0} ".format(wind_dict[match])
   
string_1 = re.sub(r'([0-9]+)([F|C])', fixTemp, string)
string_2 = re.sub(r'( [NESW]+ )', fixWind, string_1)

indigo.variable.updateValue(1308289177, string_2)


Change the third line to your weather device ID and change the last line to the ID of an existing variable, the script should work. I've tested it locally and remotely.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Thu Jul 06, 2017 8:41 am
wideglidejrp offline
User avatar
Posts: 494
Joined: Jan 15, 2012
Location: Danbury, CT

Re: Weather Underground Plugin

Thanks very much. That did the trick. Strange how sometimes copy/paste can cause problems. I have see it happen elsewhere. A stray character gets infused or corrupted. Anyway, thanks again. Works perfectly. I am starting to like Python, just enough to be dangerous.

John R Patrick
Author of
Home Attitude

Posted on
Thu Jul 06, 2017 6:55 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

Glad to hear that's working for you. It's a bit much for someone just getting started with Python, but I think it's a decent script for the job.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Posted on
Tue Jul 18, 2017 5:02 pm
roquej offline
User avatar
Posts: 342
Joined: Jan 04, 2015

Re: Weather Underground Plugin

Upgrade to the latest version as I am looking to lower the CPU load on the Indigo server. Keeping my fingers crossed. FYI, getting the follow error:

Started plugin "WUnderground 1.1.9"
WUnderground Error Problem parsing 10-day forecast data. Error: (Line 1798 ('key windUnits not found in dict')

JP

Posted on
Tue Jul 18, 2017 6:39 pm
DaveL17 offline
User avatar
Posts: 5356
Joined: Aug 20, 2013
Location: Chicago, IL, USA

Re: Weather Underground Plugin

roquej wrote:
Upgrade to the latest version as I am looking to lower the CPU load on the Indigo server. Keeping my fingers crossed. FYI, getting the follow error:

Started plugin "WUnderground 1.1.9"
WUnderground Error Problem parsing 10-day forecast data. Error: (Line 1798 ('key windUnits not found in dict')

JP

Not sure why you wouldn't have that setting -- but that doesn't mean I can't trap the error (which I have done for the next release). Please try opening up the device settings for your 10-day forecast device and select save. Hopefully, that will clear the error.

I came here to drink milk and kick ass....and I've just finished my milk.

[My Plugins] - [My Forums]

Who is online

Users browsing this forum: No registered users and 1 guest