Zack Scholl

zack.scholl@gmail.com

Raspberry Pi as an aurora alarm.

 / #raspberrypi 

I make a Raspberry Pi powered alarm clock for alerting about auroras.

Auroras (or northern lights) are amazing – a beautiful display of ionization of the disturbed magnetosphere. Auroras often happen in the dark of the night and their occurrence is random. The best predictions usually only provide an hour’s notice. To make sure I can get to see the latest Canadian auroras, I made a Raspberry Pi Aurora Alarm.

There is a simple way of determining if there is an Aurora in Canada, you just go to www.aurorawatch.ca. There you will see a graph like this:

When the bar is red, there may be an Aurora!

From that graph you can see that the Aurora on September 1st, 2017 did not occur until about 11pm. And, even though I was asleep at the time, I was awaken to see the aurora!

My setup is very simple. I have a Raspberry Pi that probes the Aurora with a simple Python function:

 1import requests
 2from bs4 import BeautifulSoup
 3
 4def percent_aurora_right_now():
 5    r = requests.get('http://www.aurorawatch.ca/')
 6    soup = BeautifulSoup(r.text, 'html.parser')
 7    percent_aurora = 0
 8    for span in soup.find_all('span'):
 9        if '%' == span.text[-1]:
10            try:
11                percent_aurora = float(span.text.replace('%', ''))
12            except:
13                pass
14    return percent_aurora

and then I have a for-loop that periodically checks if an Aurora has occurred:

1import time 
2
3while True:
4    if percent_aurora_right_now() > 70:
5        alarm()
6    time.sleep(60)

The alarm() function may have to be changed for yourself. You can do whatever alarm is best – push notifications, ringing buzzers, etc. Since I am a heavy sleeper, sound usually doesn’t wake me up so I made a light alarm. That is, my lights will periodically flash when the Aurora occurs:

My Aurora light alarm in action

I have two PIR sensors at the side of my bed so I can also turn on/off the lights manually. For light automation I’m using Philips Hue Lights.

Here’s another picture from the last aurora I saw:

An Aurora in the middle of the night in the middle of Alberta, CA

Here’s my full code: https://gist.github.com/schollz/a6922e7ba94afa9b183cc48715607230.js