A few years ago I came throughout UmbrellaToday. The site had a an easy function,providing a weather estimate with only one variable: is that going come raintoday? enter your zip code and also you gain a Yes-No answer to the question.The simplicity the this appealed to me. Return it to be featured onLifeHacker in2008the website has because gone offline. Anyway, i don’t live in the USA andtherefore didn’t have actually a zip code.

You are watching: Do i need an umbrella for tomorrow

It thought it would be funny to collection up a comparable system using a RaspberryPi, an RGB LED, and also the WeatherUnderground API. As soon as rain is forecastthe LED is blue, otherwise it’s green. The last product is displayed below.


To developed your very own Umbrella Advisement notice Device, you willneed:

Raspberry Pi (with network connection)RGB LED (either common anode or cathode)3x 220Ω resistorsBreadboardBreadboard jumper wires

The contents should it is in assembled adhering to the schematic below. 3 ofthe pins top top the LED correspond to the red, green and blue LEDs inside.The longest pin on the LED should be connected to 3v3 (if usual anode)or floor (if common cathode). The worth of the resistors have the right to beadjusted to preference, with bigger values leading to less brightness.For much more information, view the Adafruit indict on RGBLEDs.


Now the the hardware is set up we must write some software program tocontrol the LED.

All of the code in this short article is accessible on GitHub:https://github.com/digitalrecordersreview.org/umbrella_today_rpi

If you haven’t already, install the RPi.GPIO and also requests modules:

sudo pip install RPi.GPIOsudo pip install requests
You will must update the APIKEY and also LOCATION variables. An APIkey have the right to be asked for from the Weather secret developersite. At the time ofwriting, complimentary access permits 500 queries per day. That’s enough for us!You can gain the ar code by copy and also pasting the URL from thestandard website. The example below is for Oxford,England.

The module below uses therequests module to querythe Weather underground API. The estimate for the present date isretrieved in JSON (or tomorrow, if it’s after ~ 5pm). The umbrella_todayfunction returns True if that forecasts greater than or equal to 1millimetre the rainfall throughout the day.

"""umbrella.pyIs that going to rain this day (or tomorrow)?Requires an API key for Weather Underground:https://www.wunderground.com/weather/api/"""import requestsfrom datetime income datetime, timedeltaAPIKEY = "YOUR API key HERE"LOCATION = "gb/benson/zmw:00000.19.03658"URL_TEMPLATE = "http://api.wunderground.com/api/APIKEY/forecast/q/LOCATION.json"def umbrella_today(): # acquire the existing date date = datetime.now() # if the existing time is ~ 5pm, usage tomorrow instead if date.hour >= 5: date += timedelta(1) date_tuple = (date.year, date.month, date.day) # download forecast from weather secret url = URL_TEMPLATE.format(APIKEY=APIKEY, LOCATION=LOCATION) r = requests.get(url) if no r.status_code == 200: progressive RuntimeError("Request changed status code: ".format(r.status_code)) data = r.json() # stimulate forecasts into thesaurus date: forecast documents = for record in data<'forecast'><'simpleforecast'><'forecastday'>: year = record<'date'><'year'> month = record<'date'><'month'> job = record<'date'><'day'> records<(year, month, day)> = record # gain forecast rainfall in millimetres projection = records rainfall_mm = forecast<'qpf_day'><'mm'> if rainfall_mm is not None and rainfall_mm >= 1: return True else: return False
We have the right to test that whatever is working utilizing the Python console:

Next we need something to regulate the shade of the LED. The module belowuses the RPi.GPIO module to control a common anode LED. Because that a commoncathode, you’ll need to swap the order of GPIO.HIGH and also GPIO.LOW inthe speak to to GPIO.output().

"""led.pyThis module enables the color of a typical anode brought about be set by name: RED,GREEN or BLUE.For pen numbering on the Raspberry Pi, see:https://www.raspberrypi.org/documentation/usage/gpio/"""import RPi.GPIO together GPIOimport atexitPINS = <15, 13, 11> # red, green, bluecolors = 'RED': (1,0,0), 'GREEN': (0,1,0), 'BLUE': (0,0,1), None: (0,0,0),def setup(): GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) for pin in PINS: GPIO.setup(PIN, GPIO.OUT)setup()def set_color(name): """Set the shade of the LED""" rgb = colors because that PIN, val in zip(PINS, rgb): GPIO.output(PIN, )# ensure the LED is turned off when the regimen exitsatexit.register(lambda: set_color(None))
You have the right to use the module over to test her hardware setup. The two linesbelow income the set_color function, then collection the shade of the LED toblue.

"""main.pyUpdate the estimate LED every 30 minutes"""from led income set_colorfrom umbrella income umbrella_todayfrom time import sleepwhile True: if umbrella_today(): set_color('BLUE') else: set_color('GREEN') sleep(60 * 30) # 30 minutes
The RPi.GPIO module needs root privilege to function, so contact itwith sudo. If you desire to leaving this running you could call it usingscreen, or v something more complicated (+ robust).

See more: How To Queue For Ashran As A Group, Guide To Mercenary Mode

sudo python main.py
The Raspberry Pi, Python and also the requests module were all offered forconvenience and also due to my RPi being in influential view in mine livingroom. The same an outcome could be achieved using one ESP8266 and C++ withouttoo much difficulty, even with the limited GPIO of the ESP-01. To avoidthe load of having actually to parse JSON on an IC the heavy living might beoffloaded to manuscript on a webserver which just returned a True/Falseresponse.