Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Weather level adjustment not working #35

Open
Dalmapalma opened this issue Jul 6, 2019 · 17 comments
Open

Weather level adjustment not working #35

Dalmapalma opened this issue Jul 6, 2019 · 17 comments

Comments

@Dalmapalma
Copy link

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?

@stevejbauer
Copy link
Contributor

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?

@mihugo
Copy link

mihugo commented Sep 3, 2019

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)

@Dan-in-CA
Copy link
Owner

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.

@mihugo
Copy link

mihugo commented Sep 5, 2019

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.

@Dan-in-CA
Copy link
Owner

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
Copy link
Owner

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:
#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.

@mihugo
Copy link

mihugo commented Sep 8, 2019

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.

@Dan-in-CA
Copy link
Owner

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.

@stevejbauer
Copy link
Contributor

stevejbauer commented Sep 8, 2019 via email

@Dan-in-CA
Copy link
Owner

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
Copy link
Owner

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.

@mihugo
Copy link

mihugo commented Sep 15, 2019 via email

@Dan-in-CA
Copy link
Owner

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.

@mihugo
Copy link

mihugo commented Sep 21, 2019

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.

@Dan-in-CA
Copy link
Owner

Dan-in-CA commented Sep 21, 2019

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 +.

@nortonjco1
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants