I don’t have a quality window view in my office building and found myself checking the local news’ weather cams throughout the day so I thought it’d be cool to have a live outdoor view streaming to my desk. Using a Pi 3, Pi Display, a case, and camera, I built a digital picture frame which streams a live video feed from my apartment window to my desk at work. While going through the process, I hit a few hiccups and a ton of outdated resources online so I thought I’d share my learnings and provide documentation for anyone wishing to recreate.
The following will setup a Pi to run Chromium in Kiosk mode on startup while silencing errors and hiding your cursor. The assumptions made before beginning are that you’re able to SSH into both of the Pis and your Pis are connected to WiFi. The guide I followed to setup my cam stream is solid so no need to re-invent the wheel – use this guide to setup your first Pi to stream your cam image. The obvious callout is to make sure your stream resolution matches your display’s resolution. The steps below will be for your picture frame Pi and assume you’ve already got your stream up and running… Step 1
Run the update/upgrade and install Chromium (as explained here). sudo apt-get update sudo apt-get upgrade Step 2
Install x11 server utilities and unclutter. sudo apt-get install x11-xserver-utils unclutter Step 3
Since we want this to be as hands-off as possible and to silence any power-saving settings or error messages on power cycles, we’ll edit the LXDE startup to disable this stuff. sudo nano ~/.config/lxsession/LXDE-pi/autostart
and add the following lines (not the screensaver commented out): #@xscreensaver -no-splash @xset s off @xset -dpms @xset s noblank @sed -i ‘s/”exited_cleanly”: false/”exited_cleanly”: true/’ ~/.config/chromium/Default/Preferences
The last line we’ll add in this file will be the address we want to display. In the example below, we’ll sinply load Google.com. We use the incognito tag to prevent Chromium from showing an error in the event of a power cycle. @chromium-browser –noerrdialogs –kiosk http://www.google.com –incognito
Now, exit and write. Step 4
Let’s reboot and apply the changes to see the results sudo reboot
The original design wasn’t “clean” feeling and didn’t function too well on mobile or even tablet displays. I changed that up a bit and the new design has a lot of transparent divs, bokeh background images, and some jquery to make actions a bit smoother.
Wink Integration Improvements
The initial integration of the Wink API wasn’t that great. I was using PHP to trigger shell scripts which would then make the API call – quite messy and had several opportunities for failure. This method also made a new request for a bearer token each time an action was taken so if I turned on three lights, I requested three unique tokens from the API. I’ve since cleaned that up and now use a single token per session and the API calls are all made in a single PHP file. This still isn’t the cleanest or safest way to do this but it works for my usecase.
While doing this, I also added the ability to dim some lights (such as the kitchen light which we leave on during the night). The next step is to fetch the current state of the lights so that we can eliminate the on/off option and simply toggle it. The problem with that is that the Wink Hub struggles to maintain accurate states for its devices.
I integrated TheMovieDB.org‘s API to pull images of the movies or shows that are currently on. This currently works very well for movies but it often fails to find images for shows so I’ll loop back to fix that at some point in the future. I also added in a link to view the title on IMDB for easy access. An alarm was added to trigger a notification if the DVR is nearly full.
Mapping GPS Coordinates
Out of sheer curiosity, I decided to push my phone’s GPS coordinates to my server and plot them on a map. I’m using the SendLocation app to push the coordinates to a script I have setup to listen to the app. This may, perhaps, help me locate my phone one day if I ever lose it. For now, though, it’s merely something for me to play with. I’m also capturing things like speed so I can view when I’m in transit. Essentially, this traces my steps.
MQ2 Sensor (Gas/Smoke)
I added an MQ2 sensor to the PI and set it up to store the current state as well as send me a text message and email if it detects something. Overall, the setup is pretty simple and certainly isn’t life-saving but does serve the goal of being able to monitor home while away.
Here’s my Python file I use which I simply schedule a cron job to ensure it’s monitoring frequently enough to be useful (note the loop of 20 and sleep of 3 seconds so it runs for the entire minute before the cron fires again):
I’ve changed the interior camera to disable itself if anyone is home. There’s no need for it to run if during that time and it also ensures an additional layer of security/privacy.
The date formats were updated to provide “friendlier” outputs. I also added a time of day greeting for the active user – “Good morning/afternoon/evening/night”…
My favorite Google News RSS feeds were added to the left and a weather forecast link was added. I also included a calendar with the eventual goal of integrating the Google Calendar API (I use Google Calendar quite heavily). These are hidden by default in order to maintain the “clean” UI I’m going for.
Let’s just get it out of the way now — there’s no true practical purpose or value in doing this. I took this on as an experiment and opportunity to learn something new.
What is it?
Using a Raspberry Pi, some sensors, and a lot of Googling with trial and error, I took my first step into custom home automation (Wikipedia). I can control lights, DirecTv receivers, some appliances, measure indoor temperature and humidity, determine who is home, and view indoor/outdoor webcams through a single UI.
Each tailed light uses a GE Link bulb which is connected to a Wink hub. This allows for on/off control, dimming control, on/off scheduling, and dimming scheduling (such as gradual increases in brightness in the mornings). Wink comes with a nice app but I opted to use their API so I could incorporate it into the custom UI/dashboard along with everything else. Cameras
I’m using an old D-Link camera to gain outdoor views and the RPI camera for inside the apartment, I setup scripts to take snapshots once every minute and dump them into a MySQL db running on the Pi and also update the snapshot to include in the UI. Weather Reporting
Outdoor weather (temperature, “feels like” temperature, humidity, pressure, and windspeed) is pulled from Yahoo! XML weather feeds.
Indoor temperature and humidity is polled every minute using a DHT11 sensor attached to the RPi. Historicals for all of these are stored in a MySQL database with the intention of graphing these some time in the future. I’d like to incorporate a Nest-style thermostat for indoor climate control but, alas, I’m a renter and don’t want to deal with that. Who’s Home?
Using a Bluetooth dongle attached to the RPi, I poll for cell phones to determine who is home and who is away. Every minute, I log the status of all detected Bluetooth devices so we can see who’s around. This is also stored in a MySQL db so I can go back in time. DirecTV Control
Using the DirecTV SHEF API, I currently poll the current program title, the channel number, the station ID (ie NBC or HBO), the program rating, whether or not the DVR is recording. The API allows you to take full control of the receiver and do all actions you can with the remote but I don’t see much value in that as I can’t watch it while I’m away so why have the functionality… Appliance Control
Using WEMO plugs, I can power on/off appliances. This came in handy at Christmas when the outlet was located directly behind the Christmas tree. At this point, though, there aren’t many appliances I want to control with the Wemo so I have a few of these sitting idle.
Automation and Availability
Amazon Echo Integration
All of these devices have been integrated with the Amazon Echo device either via Echo skills or via IFTT integration. This allows all of the functionality above to be controlled via voice recognition. There’s some trial and error getting these setup correctly but I think that’s mostly with the Echo’s voice recognition quality. IFTT
With integration of IFFT, I can do any number of things if desired. One of the more useful IFFT setups I’ve found is simply turning on the bedroom lamp ~8 minutes after my alarm goes off and gradually increasing the bulb’s brightness every minute. Another possible option is to turn some lights on when the Pi’s bluetooth dongle detects that I’m nearby. Web Server
In order to make this valuable, I installed Apache on the Pi and used ngrok to tunnel to localhost so that I don’t have to worry about the vulnerabilities of port forwarding on my router. I have this forwarded over to a domain name I wasn’t using and added some .htaccess protection (among other things) to keep it private.
Living in a small apartment limits the value and the opportunities of home automation. Things like adding reed switches to windows and door don’t make sense in my scenario as I doubt anyone will be climbing through my 7th floor window or trying to break into my door. Some more practical things I’ll be doing, though, is adding a gas, CO2, and smoke sensor to the Pi so that I’m alerted via text message and push notification if the Pi detects any of those levels becoming elevated…better than waiting on the neighbors to call the fire department, no? I’d also like to add a PIR motion detector to trigger the Pi Cam to start capturing video instead of still snapshots if motion is detected during hours that I’m normally away from home. I’ve had some troubles getting the motion detector to work but I’ll loop back to that eventually.