Getting Information from the Internet for Your Home Automation System

Giving your home automation system access to the internet is one of the most useful things you can do with it. Once you know how to write the requisite code, your system can have access to pretty much anything out there, from local weather data to stock quotes. It can then act on that information, sounding alerts and performing actions in your home in response to that data.

Finding a Source

Before you can grab data from a website or anything else on the internet, you need to find a site with data in the right format. What you’re looking for is something simple–plain text is ideal. Also, since your system will find the data by referencing things located around it, you want something which has an easily identifiable text label.

A good example of such a site is Weather Underground’s Mobile page. These weather pages are designed to be displayed on mobile phones, so the layout is very simple, and most of the data is text based:

Weather Underground Mobile Page
Another benefit of this site is that there are clear textual labels (temperature, humidity, etc.) in front of each piece of data.After you have found a suitable source of data, you’ll need to add some code to Powerhome to grab it.

Using Powerhome to Load Data

First, before reading any further, load Powerhome, go to the Multi Editor, set it to SQL, and paste in the contents of this file. Then, create a Global Variable called CURTEMP

This will set up the basic structure that you need to grab data. It should create a macro called Test. Go into Powerhome Explorer and load this macro.

Using Regular Expressions to Get Weather Info in Powerhome
The first line of the macro directs the program to the page where it will get the data from, and stores that page in a local variable. For the weather example, all you have to do is change the URL to reflect your ZIP code: ZIP HERE. Lines 2-3 in the macro write a local file–you shouldn’t have to bother editing this.

The next line is where the actual grabbing of data occurs. In order to do this, Powerhome uses a regular expression, which tells the program to grab anything located between two defined chunks of code within an external file. In this case, the external file is the Weather Underground mobile page. On the actual page, the code for the temperature begins with the label “Temperature”, then some random code (represented in the regular expression by~255), then an html bold tag.

This is where Powerhome starts grabbing data (the data to grab is represented in the regular expression by \(.+\). This is then followed by an HTML unbold tag, and a random bit of HTML. This is where Powerhome stops grabbing data. Once the data has been grabbed, it is placed into the Global Variable “CURTEMP”. When you run the macro, CURTEMP should change to the current outside temperature.

Going Beyond the Example

Once you have this basic macro set up, you can simply modify the regular expression and the initial URL in order to grab data from pretty much any page. For some information about using regular expressions in Powerhome, check out the Powerhome help. For more info on regular expressions in general, check out this link.

Some Ideas

Once you have the ability to grab internet data, there are lots of things you can do with it. You could get data about weather watches and warnings, and then flash lights or sound some other kind of alert if a particular watch or warning was issued. If your system includes devices like garage door openers or window shades, you could have your system close these if a storm was about to arrive.

There are also all sorts of others kinds of data you could grab. You could get your system to grab news headlines and then read them to you via TTS. You could also get stock data every 15 minutes, and sound some kind of an alarm if the stock dropped below a certain level. You could even set up a system to grab data from a friend’s blog and have it read to you. There are all sorts of options.

Attribution: The code for grabbing weather data is based on the excellent Get Weathermacro written by TonyNo of the Power Home forums.

Scroll To Top