Fuzzy Weather Indicator

This is actually a reworking of something I made years ago that uses a servo to show the weather forecast for my area. Previously I used an Arduino with Ethernet and had to have it constantly plugged in to the mains. Now with Electric Imp it’s all wifi, much smaller and all batteries, going into a deep sleep and waking up every hour to get the forecast.

Once the beta is over I’ll post the code and laser cut parts but in the meantime here’s a link to a quick Vine of it in action. (Making a slight iteration so I’ll have a laser etched arrow on the front).

https://vine.co/v/bF6xxOUjbQd

That’s just fantastic being in the North West assume video is real time as you do have WEATHER up thier :slight_smile:

Yeah very much so! Weather data comes from a php script which polls Yahoo Weather for the forecast of where I live.

Beats my dull LCD weather display by a huge country mile.
How would you show barometric pressure?
I’ve found some local, as in down the road, weather stns on weatherunderground API quite easy to work with.

My window is black. Let’s see what you made?

@controlCloud - not sure as I don’t really understand barometric pressure! Must look into weather underground…

Or Yahoo Weather if you choose.

PHP can parse any of the dozens of XML tags that they offer and feed their values to the imp.

In my usage, the imp makes a request every 2 minutes to find out if it’s daytime or nighttime, or how close it is to those times … if I decide to alter lighting conditions 30 minutes before sunrise (for example).

My example uses beta Agents, so I don’t think I can post code until the beta testing is over.

If you view the Yahoo Weather XML (complete result), you’ll see all of the tags available.

But Weather Underground is great too! They might offer things that Yahoo does not.

I can post the PHP code … You need to give it your WOEID (where on earth am I ID)

// Use PHP CURL to get XML data for defined WOEID …
// This is my woe ID, go to Yahoo Weather and find the ID for your location.
$woeid=“12781675”;
$feed_url = “http://weather.yahooapis.com/forecastrss?w=”.$woeid;
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL,"$feed_url");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 0);
$xml = curl_exec($curl);
curl_close($curl);
$weather = simplexml_load_string($xml);
if(!$weather) die(‘weather failed’);
$copyright = $weather->channel->copyright;
$channel_yweather = $weather->channel->children(“http://xml.weather.yahoo.com/ns/rss/1.0”);
foreach($channel_yweather as $x => $channel_item) {
foreach($channel_item->attributes() as $k => $attr){
$yw_channel[$x][$k] = $attr;
if($x==“astronomy” && $y=“sunrise”){$sr=$yw_channel[$x][$y];}
if($x==“astronomy” && $y=“sunset”){$ss=$yw_channel[$x][$y];}
}
}
echo "Sunrise: ".$sr;

I’m only looking for ‘astronomy/sunrise’ tags, but you can look at any of them.

I’m using SimplePie as they have a specific Yahoo! Weather add-on. Here’s my code for my little machine.

`<?php
require_once(’…/includes/simplepie.inc’);
require_once(’…/includes/simplepie_yahoo_weather.inc’);

// Initialize a new SimplePie object.
$feed = new SimplePie();

// Parse a Yahoo! Weather feed
$feed->set_feed_url(‘http://weather.yahooapis.com/forecastrss?w=26539208&u=c’);

// We’re going to override the built-in SimplePie_Item class with the SimplePie_Item_YWeather class.
$feed->set_item_class(‘SimplePie_Item_YWeather’);

// Initialize the feed
$feed->init();

// Since Y! Weather feeds only have one item, we’ll base everything around that.
$weather = $feed->get_item(0);

// simplify the output - e.g. showers gets turned into rain.

$json ="{";
foreach ($weather->get_forecasts() as $forecast):

$condition = strtolower($forecast->get_label());

$current = $condition;

switch ($condition) {

case "light snow showers":
    $current = "snow";
    break;
case "light snow":
    $current = "snow";
    break;
case "freezing rain":
    $current = "rain";
    break;
    case "showers late":
    $current = "rain";
    break;
case "windy":
    $current = "cloudy";
    break;
case "cloudy/wind":
    $current = "cloudy";
    break;
case "showers":
    $current = "rain";
    break;
case "pm light rain":
    $current = "rain";
    break;
case "am light rain":
    $current = "rain";
    break;
case "am showers/wind":
    $current = "rain";
    break;
case "few showers":
    $current = "rain";
    break;
case "light rain":
    $current = "rain";
    break;
case "fair":
    $current = "sunny";
    break;
case "drizzle":
    $current = "rain";
    break;
case "drizzle":
    $current = "sunny";
    break;
case "mostly clear":
    $current = "sunny";
    break;
case "mostly sunny":
    $current = "sunny";
    break;
case "mostly cloudy":
    $current = "cloudy";
    break;

}

	$json .="\"text\": \"".$current."\", \"code\": \"".$forecast->get_code()."\", \"high\": \"".$forecast->get_high()."\"}";
	echo($json);
	break;

endforeach;`

It’s great to see alternate methods … as many different scripts as we can get would be good. I see these “snippets” of code being important for someone in the future. Hopefully we’ll have a central place to put all of them eventually.

Here’s a little film I made of the weather indicator: