CyntechUK / WeatherHAT

10 stars 3 forks source link

Added a getWeather Example #5

Closed kd8bxp closed 4 years ago

kd8bxp commented 6 years ago

Hi - This is my attempt to make something useful for the weatherHAT. it uses weather-api wrapper to get weather conditions from Yahoo and then displays on the weatherHAT https://pypi.python.org/pypi/weather-api/0.0.5 I'm pretty new to python coding, and this was quite a learning experience for me.

The script can be run in the background (sudo python getWeather.py &)

I am running the weatherHAT on a Raspberry PI Zero W, headless.

Boeeerb commented 4 years ago

Thank you for your example, I've given it a try out here and works flawlessly - Shame the weather doesn't change that often to see it cycle through everything!

As for haze and fog, I'll add in some this in, it'll just be the white clouds on a dull solid brightness. As well as better manage the multithreading and script escaping of the currently running threads (making ctrl + C difficult).

The setup guide will need updating for anyone new to OpenWeather, just to take the confusion of creating an API key

kd8bxp commented 4 years ago

Thank you! I look forward to your updates - one thing that I noticed was openweathermaps consider "clear" and "sunny" to be the same - which is fine - but at night time it's not "sunny" They have a different icon to use for devices that can display pictures.
For this I guess we need to check what time it is? I'm still pretty new to python and not real sure how to do that, google will be my friend I'm sure. I was thinking of using the RGB (rainbow) to display some of the other conditions, not sure if that is a good idea or not. I agree about needing a guide to openweather api setup, better than what I did, there are many on the net, so maybe just point folks to one of those would work? What do you think?

Trotter73 commented 4 years ago

Its great to see some activity on this great HAT, cheers for the efforts guys.

Just for kicks and to get some use out of it I added wh.rainbow("start") to "Showers" , rainbows after shows, not beyond possibility :-)

Like Boeeerb, just need something other than clouds and rain to try it out....

It would be great to be able to control the brightness if thats possible, I can read a book by the brightness of the clouds :-D

All the best !

kd8bxp commented 4 years ago

Like maybe "rainbow" after the storm is over - for an hour or so, or something like that - seems like that is a bit beyond what I know to do right now. Honestly, I've been trying to learn python, this was a start for me, but I don't really know much. I'm very excited however with the interest now, and hopeful for new better things to happen with the script. I am in the states (Ohio), and so far almost everyone I've meet online is somewhere in the UK or Europe - I think I'm the odd man out LOL I can confirm for you that "sunny" works - works too well, it's not "sunny" at night :-) But otherwise, I've only seen cloudy, rain, and sunny.

Boeeerb commented 4 years ago

All the LED's' brightnesses can be individually controlled, and the OpenWeather API has sunrise and sunset, so would make sun/moon easily doable, moon can just be one of the RGB's displaying a white colour. I have many plans to update it - My problem is just missing the time to get the ideas in to code.

Other things could be added such as the ISS, displaying an approx location as it flies across the sky with the RGB rainbow

kd8bxp commented 4 years ago

OH, wow, that is a great idea for the ISS, I have some ESP32/ESP8266 code that calculates how far the ISS is, I wonder if that could be a good base for it (?) https://github.com/kd8bxp/Simple-ISS-Notification-System I think we all understand the time limits - :-) But I look forward to the updates. And if there is anything I can work on, time permitting, I'd be happy.

Trotter73 commented 4 years ago

My python non existent however I can work with examples... Just looking at how the script works does it take the "Main" value from the API data ? If so "showers" is probably never going to be displayed, as that is a sub-set of RAIN, if we were to use the ID value or a combination of MAIN and ID we could probably pick up more weather styles..

I'm not sure I could combine values but I'll have a stab at changing the script to use the ID value....

Would this work:-

if "201,202,203" in test:

or would I have to use

if "201" in test

if "202" in test:

kd8bxp commented 4 years ago

A little bit about this - originally 2018 or so it was using the Yahoo Weather API, and another python library that made phrasing "easy" -that api changed, and this stopped working. I wasn't aware, someone asked about it on the instructable, and like everyone I was pretty busy at the time. But thought that openweathermaps could probably replace yahoo. Someone else asked about it, and that was really enough to renew my interest in this, while I'm still busy on other projects - I figured I could find a few minutes to look into it - Open Weather is a much better API, and has a lot of information that can be used - but for the sake of time, and because of other things - I made a quick fix to get it back working.
Now that it's working, yes - it needs to be better - but this really was a quick fix and something to get at least something useful again. I'm still very much learning myself, so I'll leave the specific question - But I think it would be more of a "if this or this or this" condition if "201" or "202" or "203" in test: or maybe an "if this and this and this" if "201" and "202" and "203" in test: I end up reading the docs quite a bit on w2schools.com https://www.w3schools.com/python/python_conditions.asp

Trotter73 commented 4 years ago

@kd8bxp Totally understand my friend, I was by no means having a dig, sorry if it sounded that way, it was not my intention :-)

Ive started having a read up on conditional statements and arrays, I think that may be the way to go, the link you provided as a good source as well..

Trotter73 commented 4 years ago

Gents, attached is my first pass at using the operweathermap ID numbers, it runs but guess what, more clouds here so cant really check lol

getWeather-mec.zip

kd8bxp commented 4 years ago

@Trotter73 I didn't take it as a dig, I just wasn't sure if you were aware of where this started, and how it got to this point. :-) I totally know it's not perfect, and very excited that someone who knows more (like @Boeerb) is going to work on it - it will help all of us learn some more. I think it's a ok start, but I also know it could be improved (more so now, since there is so much more that can be done) I really like w3schools.com, they explain stuff pretty good, and show little examples which help.

Just grabbed, your update - I'll give it a try when I'm actually awake - it's 5am here, and I'm not really here lol. Honestly not sure why I'm awake.... Have a good morning,and I'm going back to sleep.

Trotter73 commented 4 years ago

Cool beans, noted, as long as we are good :-D

Yea looks a good resource, it gave me enough to do what I've done here, there is probably a tidier way of doing this but to me it was a simple approach that could be easily changed if the the API is updated..

Attached is a revised version, I realized I needed >= <= rather than just < > , also I've differentiated between clouds and scattered clouds.. Oh and tidied up the startup when it cycles through all the weathers....

5am ouch !! Happy Friday, have a good one, I'm supposed to be working so I suppose I had better get back to it and actually do something .....

getWeather-mec-iss2.zip

kd8bxp commented 4 years ago

@Trotter73 don't have much time today, got to get to work, and I'm tired never did really get back to sleep, and worked on an ISS display. Anyway, I can confirm your code works, I got "sunny" when I tried it, but I haven't looked much more into it. Have a great weekend.