sip_plugins icon indicating copy to clipboard operation
sip_plugins copied to clipboard

Weather level adjustment not working

Open Dalmapalma opened this issue 5 years ago • 17 comments

Hi,

I just installed the plugin for the weather level adjustment. I entered all the details like Openweather API, City etc...

I get everytime the following message:

Weather-base water level encountered error: Traceback (most recent call last): File "/home/pi/SIP/plugins/weather_level_adj.py", line 97, in run today = today_info(self, options) File "/home/pi/SIP/plugins/weather_level_adj.py", line 316, in today_info data = get_data(name, request, 'weather', options) File "/home/pi/SIP/plugins/weather_level_adj.py", line 234, in get_data req = urllib2.urlopen(url + "&appid=" + options['apikey']) File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 435, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 548, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 473, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 404: Not Found

Any ideas?

Dalmapalma avatar Jul 06 '19 08:07 Dalmapalma

I had some errors like this when I setup this module. One thing my install was missing the weather_decipher.json file. Another thing is how are you entering your city into the location?

stevejbauer avatar Jul 17 '19 22:07 stevejbauer

I tried to create a pull request with my solution to this problem since I encountered it tonight while finally getting around to updating my system. That default file was not automatically provided when downloading the weatheradjust plugin. THANKS very much to Grant OConnor for updating this plugin to work again

The below code just creates that config file if it can't be read. The code is far from perfect as it does not handle corruptions to that file all that well but it should get the job done.

Let me know if I should create a pull request for this but my attempts were all met with 403 errors.

plugins/weather_level_adj.py
201c201,218
<         'status': checker.status
---
>         'status': checker.status,
>         'weather_decipher' :    {
> 	  'Description': 'WeatherCodes and Weights',
> 	  'PrecipCodes': {
> 		"HeavyRain": [210, 211, 212, 502, 503, 504, 522, 531],
> 		"Rain": [200, 201, 230, 231, 232, 313, 314, 500, 501],
> 		"Drizzle": [300, 301, 302, 310, 311, 312, 321, 520, 804],
> 		"Clear": [800, 801],
> 		"Overcast": [802, 803],
>           },
> 	  'PrecipWeights': {
> 		"HeavyRain": 0,
> 		"Rain": 10,
> 		"Drizzle": 30,
> 		"Clear": 100,
> 		"Overcast": 80
> 	  }
>         }
213,214c230,236
<         with open('./data/weather_decipher.json', 'r') as f:  # Read the settings from file
<             result['weather_decipher'] = json.load(f)
---
>         try:
>             with open('./data/weather_decipher.json', 'r') as f:  # Read the settings from file
>               result['weather_decipher'] = json.load(f)
>         except:
>             print "Building default file: ./data/weather_decipher.json"
>             with open('./data/weather_decipher.json', 'w') as w:  # write the settings to file
>               json.dump(result['weather_decipher'], w)

mihugo avatar Sep 03 '19 07:09 mihugo

Sorry for the delay in getting back to you. I had a disk crash and am just getting thing back together. Fortunately I had a fairly recent backup.

I had not taken a close look at the updates on the weather plugins. The plugin should have included all the necessary files but there is a separate folder on the plugins repo named "data_example" which contains the "weather_decipher.json" file among many other things. There is no indication on the plugins repo that the "data_example" files are related to the weather plugins.

The plugin system SIP uses includes a file named "[plugin_name].manifest" that tells SIP which files to download and where to put them. I will work on adding the "weather_decipher.json" file and any other necessary files to the manifest and the plugins folders on the repo so that they will be installed with the rest of the plugin.

Dan-in-CA avatar Sep 05 '19 20:09 Dan-in-CA

Glad you were not down for long. Can be such a pain to loose a drive.

Just installing the file directly seams like a straightforward solution vs mine of creating the file if it doesn't exist. I went with the creating of the file since the plugin already is creating weather_adj.json and weather_level_adj.json files with default values and it seams a bit more robust to when the data directory gets clobbered.

Either way it great to see this working again and will be nice to make it work for others without fiddling.

mihugo avatar Sep 05 '19 21:09 mihugo

I think it would be good add your code. I will have more time to work on it in the next couple of days.

Dan-in-CA avatar Sep 06 '19 03:09 Dan-in-CA

Actually adding "weather_decipher.json" to the plugin directories and the manifest files did not work. SIP's plugin manager is designed to ignore data files when installing a plugin. it will remove them when uninstalling a plugin though.

There also needs to be at least one folder (weather_current) and perhaps a "weather_level_history" folder created in the data directory. That will need to be generated by the plugin code since attempting copy a folder from GitHub resulted in a blank text file instead of a folder.

I am working on updating the plugin but it may be a day or two before things are working properly. There have been several issues raised related to the plugin updates: https://github.com/Dan-in-CA/sip_plugins/pull/33 I will try to resolve the problems as the original contributor does not seem to be responding for what ever reason. I do thank him for his contribution to the SIP project.

Dan-in-CA avatar Sep 07 '19 20:09 Dan-in-CA

There might be some interactions between weather_level_adj and weather_adj as well that I didn't dive though. I deleted the plugins and re-installed them and the only file was not created was weather_decipher.json that my patch tries to takes care of, The data directory was created after the first lookup but then again the two plugins might help each others get all the files created and you might have found a bigger issue. Thanks for diving through this. I was thrilled to finally get the weather based plugin to work and am grateful to you and to Grant for getting it working again.

mihugo avatar Sep 08 '19 20:09 mihugo

Yes. I am using your code to generate the weather_decipher.json. I am in the early stages of testing the weather_level_adj plugin and have already found a number of things that needed fixing.

Dan-in-CA avatar Sep 08 '19 21:09 Dan-in-CA

I didn't get much chance to use it this year since I never had to run our sprinkler system, but when I monitored what the plugging might do it appears to not remember things from day to day. When I looked a little, it never wrote any of the historical data to the file system. Is that what you have seen?

Steve

Get Outlook for Androidhttps://aka.ms/ghei36


From: Dan [email protected] Sent: Sunday, September 8, 2019 3:42:59 PM To: Dan-in-CA/sip_plugins [email protected] Cc: Steve Bauer [email protected]; Comment [email protected] Subject: Re: [Dan-in-CA/sip_plugins] Weather level adjustment not working (#35)

Yes. I am using your code to generate the weather_decipher.json. I am in the early stages of testing the weather_level_adj plugin and have already found a number of things that needed fixing.

— You are receiving this because you commented. Reply to this email directly, view it on GitHubhttps://github.com/Dan-in-CA/sip_plugins/issues/35?email_source=notifications&email_token=ABW4IEYN37WFKCMWO6EBXPDQIVWWHA5CNFSM4H6S35G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6F2COY#issuecomment-529244475, or mute the threadhttps://github.com/notifications/unsubscribe-auth/ABW4IE63OTBZLS6XLBZ7F7DQIVWWHANCNFSM4H6S35GQ.

stevejbauer avatar Sep 08 '19 23:09 stevejbauer

There was a problem with the plugin code not creating a folder in the data directory where the weather data was supposed to be saved. That is one of the problems I found so far. It is fixed on my test system here.

Some users have eliminated the problem by manually creating a folder named weather_level_history in the SIP/data directory.

I still have some testing and clean up to do but I think it is getting close to a properly working plugin I will post a note here when I have updated the installation files.

Dan-in-CA avatar Sep 09 '19 01:09 Dan-in-CA

Just an update: I got a little carried away with the update on the weather_level_adj plugin.

So far I have added a feature to select between units of (inch, deg F) and (mm, deg C) on the plugin options page. I also have been testing the use of lat-lon geographic coordinates for the location field which gives more accurate weather data according to the OpenWeather docs. I have also added a documentation page which should make things a bit easier to get the plugin working.

I should be able to post the update by the end of next week if things seem to be working properly.

There is rain predicted here for tomorrow so that will provide a good test opportunity.

Dan-in-CA avatar Sep 15 '19 15:09 Dan-in-CA

Excellent work. Sounds like all nice additions.

On Sun, Sep 15, 2019, 8:25 AM Dan [email protected] wrote:

Just an update: I got a little carried away with the update on the weather_level_adj plugin.

So far I have added a feature to select between units of (inch, deg F) and (mm, deg C) on the plugin options page. I also have been testing the use of lat-lon geographic coordinates for the location field which gives more accurate weather data according to the OpenWeather docs. I have also added a documentation page which should make things a bit easier to get the plugin working.

I should be able to post the update by the end of next week if things seem to be working properly.

There is rain predicted here for tomorrow so that will provide a good test opportunity.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/Dan-in-CA/sip_plugins/issues/35?email_source=notifications&email_token=AASW5UCE54PYUOINZBDLYQ3QJZHVHA5CNFSM4H6S35G2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6XS7SI#issuecomment-531574729, or mute the thread https://github.com/notifications/unsubscribe-auth/AASW5UFQZI4YTA6ZLC5KAITQJZHVHANCNFSM4H6S35GQ .

mihugo avatar Sep 15 '19 16:09 mihugo

OK. The weather_level_adj plugin update Is now available. Click the "help" button on the plugin page to open the documentation page. It contains information about using geographic coordinates for your location.

It still needs work but it seems to be fully functional. One problem is that it stores a lot of redundant data that is not used by the plugin. This can cause wear on the Pi's SD card.

I need to focus on getting SIP Python3 compatible by the end of the year when support for Python2 will end. During that process I will be working through all the plugins and will make updates as appropriate.

For a long time I have thought abut making a weather based plugin that uses an estimate of evapotranspiration (ET) for the calculations. That should be much better at saving water and is what "smart" irrigation controllers are based on. One major problem has been that most weather services including OpenWeatherMap don't provide solar radiation data which is central to the calculations. It is possible to estimate solar radiation from other weather data but it is not very accurate. I just discovered that NASA now has an online source of world wide solar radiation data that is in the public domain and has an easy to use API. Combining that resource with OpenWeather looks like it will provide the necessary data.

Dan-in-CA avatar Sep 20 '19 20:09 Dan-in-CA

Thanks for your hard work. I just tried to install it and ran into several issues. The first was: NameError: global name 'round' is not defined That seams to be due to NameError: global name 'round' is not defined caused by templates/weather_level_adj.html tCutoff = round((float(m_vals["temp_cutoff"]) * 1.8) + 32, 1) Removing round gets past that error. I ran out of time to figure out the right spot to fix it or perhaps I didn't update something right.

I also had problems with the location configuration but it might have been another late night hickup.

mihugo avatar Sep 21 '19 07:09 mihugo

That round error is strange. Python seems to think it is an undefined variable but it is a built in function.

I tested the update with a fresh install of SIP and the plugin worked as expected. I'll have a look. Thanks for reporting this. Let me know if you find any other problems.

You might try updating the OS on your pi with sudo apt-get update sudo apt-get upgrade This will ensure that python it up to date. Also check the Python version with python --version it should be 2.7 +.

Dan-in-CA avatar Sep 21 '19 14:09 Dan-in-CA

Hi, I installed the weather_level_adj plugin and am getting the following upon restart of SIP (entering the info in the plugin settings seemed ok as the "status" was just blank):

Weather-based water level encountered error: Traceback (most recent call last): File "/home/pi/SIP/plugins/weather_level_adj.py", line 123, in run today = today_info(self, options) File "/home/pi/SIP/plugins/weather_level_adj.py", line 602, in today_info data = get_data(name, request, u"weather", options) File "/home/pi/SIP/plugins/weather_level_adj.py", line 490, in get_data req = urlopen(url + u"&appid=" + options[u"apikey"]) File "/usr/lib/python2.7/urllib2.py", line 154, in urlopen return opener.open(url, data, timeout) File "/usr/lib/python2.7/urllib2.py", line 435, in open response = meth(req, response) File "/usr/lib/python2.7/urllib2.py", line 548, in http_response 'http', request, response, code, msg, hdrs) File "/usr/lib/python2.7/urllib2.py", line 473, in error return self._call_chain(*args) File "/usr/lib/python2.7/urllib2.py", line 407, in _call_chain result = func(*args) File "/usr/lib/python2.7/urllib2.py", line 556, in http_error_default raise HTTPError(req.get_full_url(), code, msg, hdrs, fp) HTTPError: HTTP Error 400: Bad Request

nortonjco1 avatar Apr 08 '20 22:04 nortonjco1

Hi,

I figured it out. The document "how to" Weather_level_adj Plugin Documentation mentions entering the coordinates as: lat=XXX.XXX_lonXXX.XXX, so I did it exactly so. It actually needs to be: lat=XXX.XXX_lon=XXX.XXX (missing the "=" for lon. Simple goof on my part. Document probably just needs updated for noobs! API was returning "nothing to geocode" before.

nortonjco1 avatar Apr 09 '20 06:04 nortonjco1