RV Lighting Alexa Control

One of the lessons I learned from automating the lighting of my last RV is that I need to have a plan for what to do when it comes time to sell it. I didn’t have a plan, because I thought we were going to live in it until I died. Then it would be someone else’s problem. But now I know that I might have to replace the RV every ten years or so, so I’m going to be a bit smarter about it this time.

For the lighting for this RV, I am going to install my gadgets in a manner that doesn’t interfere with the operation of the existing switches. That way I can choose to simply disable the IoT automation, and everything will continue to work as it did the day I bought the RV. Also, I want to make it easy to remove the automation controllers without having the splice or repair any wiring going to the switches or lights.

Sainsmart Relay boards

To allow the switches to continue to work without automation, I’m going use relays connected in parallel with the switches. When using automation, the switches will be left off and the automated relays will open and close the circuit. When the relays are off or have been removed, the switches will continue to work as before. Since most of the lights are located in one of two control panels, that means I can probably handle most the lights with a pair of Photon controllers, each with a Sainsmart 16 relay board.

Piggyback Terminals

Piggyback Blade Terminals

To allow connection without modifying the wiring, I’m going to use piggyback blade connectors.

And of course, the Photon will be running the Patriot library to allow both iOS and Alexa voice control. Time to warm up the soldering iron.

Converting the RV Garage to an Office

One of the reasons why we chose a toy hauler for our new RV is the “garage” provides an additional room that can be fixed up to serve as a home office. We did that with our previous RV, and it worked out quite nicely. I think we’re going to be even more pleased with the one in our new RV.

Installing carpet

Carpeting the garage

So the first thing we needed to do to make the garage more livable was to install carpet. My wife Shelley had found a good deal on a used rug that was 9′ x 14′, so we trimmed it back to custom fit the 8′ x 13′ garage floor.

Carpeted Garage

Finished garage carpet

We had additional trimming to do around the corner bathroom and side door, but it worked out great!The 13′ garage is a bit larger on the 10′ garage on the last RV, and there is a small bathroom. So in addition to allowing us haul our motorcycle along with us, in can double as both an office and a guest bedroom.

It sports motorized queen size bunk beds that can be raised entirely up to the ceiling to make room for hauling multiple motorcycles, or lowered individually or together for sleeping. The bottom bed folds back to form a pair of benches, with a removable table between.

Picnic with Mom

On our last trip we took my mother-in-law with us up to Kansas for my son’s wedding. We made half the lower bunk into a bed for her, and left the other bench setup to use with the table for eating lunch, etc.

Another change that was needed was to provide power to the table that I’m using as a desk.

 

With an iMac, charging cords, and Amazon Echo, at at times a soldering station, I need several power outlets. I initially just ran extension cords, but quickly got tangled up in them. So I searched around and found some circular outlet boxes that provide both 120 vac outlets and USB ports. These mount through a hole I drilled into the table surface, and mount fairly flush.

Outlet in table

This allows using the table to eat, play games, etc. when not using the table as a computer desk. And of course the office balcone is awesome, especially when I can hang it over the edge of a lake.

Ron sitting in office by a lake

My office by the lake

A New RV Means New IoT Opportunities

The RV park where we stay most of the time will be enforcing a 10-year policy. This means that in order to stay here, my RV has to be 10 years old or newer. Unfortunately, the RV that I’ve been automating for the past few years is 10 years old. So the options are move, or replace it. Since we really like staying at this park, we’re choosing to upgrade the RV.

We looked at replacing it with another used RV. When I did the math though, it actually came out reasonable to purchase a new one that we can keep for 10 years as opposed to buying a used 5-year old unit then replacing it again in 5 year.

So after much shopping, searching, praying, and looking, we finally decided on a new Heartland Cyclone 4005. This is a huge 45′ toy hauler with most of the amenities included. Shopping around locally, it was a bit out of our budget. But searching nationwide for it, I found that it could be had for about $15,000 less if I drive north a couple states to pick it up.

Ron with new RV

Picking up the RV in Troy, Ohio.

So we ended up working with the Dave Arbogast RV dealership in Troy, Ohio to purchase it. Their price was as low as we could find, and the folks we easy to work with. We could have had the RV delivered to Texas for about $2,500, but we opted to drive up there and pick it up ourselves.

En route to picking it up, we swung a little bit out of the way to go by the Heartland factory in Elkhart, Indiana to take the tour of their toy hauler plant.

RV tour

Dustin giving us the tour of the Heartland Cyclone plant.

Serendipitously, the models being built were the exact same Cyclone 4005 model that we had purchased. Some were a different color with different options selected, but it was like watching our unit being built in various stages of completion. They must have about 12 units in the assembly line at one time working their way toward completion. This was a terrific tour and we enjoyed it very much. Dustin is the manager that gave us the tour, and he was great about explaining how and why they build them the way that they do. For not being a marketing guy, he sure made us feel very good about having chosen a Heartland RV, and the unit that we had picked. I took of course a thousand pictures, so I now have a pretty good idea of what’s behind the various walls, floor, and ceiling for when I go to customize or repair it in the future.

Since the Cyclone 4005 is a high end toy hauler, there really weren’t many options to choose from. The options that we got to choose were:

  • Upholstery color: we chose the dark brown over the medium brown color.
  • Optional ramp patio package and 3-season wall for the rear ramp. This allows the ramp to be folded down to become an outside deck. Since I’ll convert the garage into my office when not hauling a motorcycle, I think of this as my office balcony.
  • Full size residential refrigerator (with battery sine converters for staying cool on the road). Since we live full time in our RV, we need a full refrigerator, not the compact units typically found in RVs.
Control panel

One of two main control panels.

In addition, we had them add slide toppers. It was surprising that these were not included standard. Here in Texas, every bit of shade helps, and the roof of the slides is pretty thin and let a lot of heat in otherwise. Unfortunately, when we picked up the unit the slide toppers weren’t installed. So the the good folks at Arbogast RV worked with us and the Heartland factory to arrange to have the toppers shipped to us, and reimburse us when we get them installed.

So now I’m planning out how to automate this beast. I’m super delighted that there are a lot of LED lights in this RV, and most of the lighting controls are contained in 2 large control panels. This should make adding Photon controlled relays much easier and less expensive.

I’ll be blogging my IoT and other projects as I go. Stay tuned…

 

Patriot Plugin Architecture

Having released Patriot iOS and Alexa Smart Home skills, it’s time to get back to improving and extending the Particle.io Photon code. One of the obvious deficiencies with the existing code is that it requires that device support be built into the library. This is fast and really convenient if you just happen to want to use the included devices, but sucks if you have other devices you want to use. It’s all open sourced, so anyone can modify it however they’d like, but that sort of misses the whole point of Patriot: to allow hobbyists to focus on solving problems and not on how to build all the components. And the code is getting fairly complex, so it’s not a trivial task.

I’ve been thinking for awhile now that I’d need to add some sort of plug-in capability to greatly simplify adding support for new devices. This would also have the benefit of only including the code that’s needed by each particular sketch. Recently, there have been a few folks having trouble compiling the 3rd party DHT module. It seems that there are some differences between compiling natively and compiling in the Particle.io web IDE. An the irony is that DHT support might not even be needed for the folks having these problems. So my lazy solution is remove the DHT code and put it into a plugin.

So that’s what I’ll be working on for the next couple weeks. I’ll update this post with details as I work them out.

Patriot iOS App

Patriot iOS appThis weekend I posted to GitHub the source code for a Patriot iOS app. This is a cleaned-up version of an app that I wrote awhile back to control Photon devices in my RV. The intent is to allow mounting old iPhone devices to the wall to use as control panels for my Photon controllers. Refer to my previous article about Patriot for information about the Particle.io code and Alexa skill.

In the image here you can see 3 different ways of controlling a Photon controller. There is an Alexa sitting next to an iPhone 4s mounted to the wall next to several wall switches.

The Problem with Switches

The switches are connected to a Photon mounted in the wall behind them and actually broadcast particle.io events instead of directly controlling power to lights. They can control multiple lights, or even things that aren’t lights. I had intended to put a bunch of switches like these around my home, but there’s a problem with mechanical switches like these. They suggest a ‘state’ of on or off. So for example, typically a switch would be “on” if one way, and “off” if the other. However, if I turn a a light on by flipping a switch up, then I turn the light off by telling Alexa to turn it off, then the switch continues to indicate “on” but the light is actually off.

Alexa Smart Home Skill

The Alexa is running the Patriot Alexa smart home skill to dynamically determine the events that my IoT Photons are listening for, so I can tell Alexa to turn activities on or off. But as described above, this leaves normal switches indicating the wrong state. So I decided that I need some sort of switch that can change to reflect the state even when changed by other devices or switches.

Old iPhone Devices to the Rescue

So an obvious choice is to use motorized switches. Unfortunately I couldn’t find any in my parts locker. But I did come across several old iPhones and began to think about how extremely powerful these could be to control my IoT devices. So I wrote a simple control panel app that displays the state of a list of hard coded activities, and allows tapping on them to toggle their on/off state. I then purchased some cheap plastic iPhone covers for them that I mounted to the walls, and can just snap the iPhones into place to hold them on the wall. I ran a power wire over, and voila!

Nice, works ok, but my head nearly exploded when I started thinking about  all the ways these could be extended. Before I start going on about possible future enhancements, let me announce that I have cleaned this original code up, extended it to use the latest Patriot dynamic device discovery, and posted the Swift source to Github.

 

The Possibilities of Patriot iOS Control Panels

So now that we have a system that allows old iPhones to communicate with our IoT system, what are some of the things that we can do to leverage the incredible power of these cheap devices? Here’s just a short list of some things that I’ve come up with so far:

  • Utilize BLE to detect the presence of certain other iPhones to monitor my comings and goings. Turn on lights when I get home after dark, etc.
  • Put a BLE tag on my car and motorcycle to track when they are at home or away or being stolen. Combined with the above…
  • Coordinate with Alexa commands to dim or display the panels.
  • Provide other views such as video chat, monitoring outside, etc.
  • Mount one of these outside to use as a doorbell with camera and audio intercom.
  • Use the back facing camera to perform motion detection, face recognition, etc. This one really has my head spinning. I intend to start looking into OpenCV to see about replacing simple motion and proximity detectors with just the camera mounted on the iPhones.
  • Motion detection and GPS: since my home is an RV, these may prove handy for a lot of things.

And the list just goes on and on. So this iOS code is intended as just a starting point. I hope others will get involved and contribute also.

The Particle Libraries 2.0 works great!

I’ve built up quite a few Photon C++ files as part of my RV home automation projects, and have been noodling over how best to share these. I’d decided to release all the source on Github, but realized that just throwing a few dozen files out there probably wouldn’t benefit anybody. Well, when I saw Particle’s recent announcement for the libraries 2.0, it looked like exactly what I was looking for.

I’m delighted to say at this point that it appears to working great, and has simplified the process that I’ve been using to date. I currently use a combination of Git, shell scripts, shared C++ files, and the particle cloud compiler and flash to build the files for each of my controllers. It’s quick and works reliably, but it’s complicated and I dread trying to document and explain to someone else how to do the same thing.

So instead, it looks like Particle’s libraries 2.0 is going to make sharing quite easy.

First, I converted all my shared files into a single IoT library. This was fairly easy using the Particle CLI library functions.

Then I created several examples and included them in the IoT library’s examples directory. One of the cool things about these are that they can be built using the CLI, Particle Dev, or the cloud IDE. And since they’re a single file about a page long, any of those options work well.

Finally, I converted each of my controller’s source directories to use the Particle project format which creates a project.properties file. This allows then adding the IoT library to the project.

So now to build a project I need only run ‘particle compile photon’ in the project’s directory. To flash the project to the device, I use a shortcut where I name the project’s directory the exact same thing as the controller’s name. Then I can run the command ‘particle flash ${PWD##*/}’ and it compiles and flashes the code to the device with the same name as the directory.

And of course I created aliases in my .bash_profile so I can run them using just ‘b’ or ‘f’ from within any project directory.

The library code is probably still quite buggy, but I’ll be actively updating as issues are found. I’d love to hear your experiences with it, and reports of any problems. The source code is on GitHub at https://github.com/rlisle/ParticleIoT.git, and the ready-to-use library uploaded and published on particle.io under the name “IoT”.

Self Discovering IoT System

I’ve been working for a couple years now to automate my RV using a combination of Particle.io Photon micro-controllers, an iOS app, and an Alexa skill. This has been fairly easy to do, due mostly to the ease of using the Particle.io API. Over the next year, in addition to adding additional functionality and more Photons, I hope to add Apple TV and Watch apps. This got me to thinking about how to make the system easier to configure and extend.

Since I’ve written all the software pieces myself (iOS app, Alexa skill, Particle sketches), up until now I’ve taken the expedient route of just hard coding the names of each controller into both of the apps. With only a single iOS app and Alexa smart home skill, this meant updating those two programs every time I added a new Photon, or extended one of the existing Photons. Not a big deal, albeit somewhat inconvenient.

However, recently I created an additional iOS app to allow using older iPhones to be mounted to the wall and used as control panels. Hard coding the names of the controllers into the apps means that I have to manually update each device whenever there is a micro-controller change. Now this is becoming a much bigger inconvenience.

So I’ve converted each micro-controller to be self registering with the system:

  1. Each Photon publishes several variables that list the device names it implements, in addition to what ‘events’ it listens for. These variables are exposed by the particle.io API and used by both the Alexa and iOS app to dynamically configure themselves.
  2. All applications use this information, instead of having to hardcode a list of commands.
  3. This functionality is built into a published IoT particle library, so copy/paste is minimized.

So now instead of needing to reprogram the Alexa skill and iOS control panel apps whenever I add a new controller, I just need to expose the data about that controller as described above, and all the applications pick it up.

I’ve posting the Photon and iOS code to Github, so please take a look and let me know what you think.

Alexa Smart Home Skill

I’ve now replaced my previously created Alexa Custom Skill with an Alexa Smart Home Skill. I’ve been holding off doing this because of the difficulty of setting up an OAuth2 server. Recently I came across an article describing how to use Login With Amazon to do this though, and I have gotten that working now.

So now I don’t have to say the name of the custom skill when invoking Alexa. Using the custom skill, I would have to say something like “Alexa, tell My RV to turn on the computer”. Sheesh. Quite a mouthful. And easy to get wrong. But using an Alexa Smart Home skill, I now only need to say something like “Alexa, computer on”. This seems like a small change, but it has made a big difference.

I’m working on providing some instructions, and then I’ll post all this code to Github.

Update: I’ve now converted the skill from using the Login with Amazon to using the particle.io oauth directly, and I’ve published the skill. What this means is that it can now be used by anyone, and it will prompt you during installation of the skill to provide your Particle.io login to access your devices. Refer to my other posts and Hackster.io project for more details. I had initially call this ParticleIoT, but that was hard to say and spell so I renamed it Patriot which uses many of the same letters.

Friends that Think Differently are a Blessing

I consider it a real blessing to have friends that I know, like, and trust, that happen to also have very different opinions about things. I’m not talking about whether it feels warm or chilly outside. I’m talking about big, controversial items like what to do about immigration, the national debt, and who would make the best president. Unfortunately, there appears to be a strong trend within our country to demonize those that disagree with us. Really? Do we really want to live in a country where everyone agrees completely about everything? I suggest watching the movie “The Stepford Wives” for an idea of what that might look like.

I say “no thanks”. Let’s disagree.

But please, let’s not fall into the trap of thinking that anyone that disagrees is evil, stupid, or uninformed. As an engineer, I know that there are always multiple answers to any problem. Thinking that there can only be one solution is a sign of an inexperienced or immature engineer. The best engineering solutions always result from lively discussions of opposing or different opinions. The worst solutions happen when one person forces their solution on everyone else.

Using Old iPhones for IoT Control Panels

I’ve been thinking for awhile now about using my old iPhones in my IoT projects. They have touch displays, wifi, cameras, audio, accelerometers, and maybe GPS depending on how old they are. Plus they have almost no value once they get a few years old. The only real downside to using them is the fact that they’re a bit hard to program, but hey, that’s what I do for a living.

So this past weekend, I scrummaged through my old Apple parts boxes, and came up with (2) iPhone G, an iPhone GS, iPhone 4s, and iPhone 5.
Doing some research, I decided that the iPhone G is not really worth messing with for a couple reasons:

  1. The newest iOS support available is SDK4, so writing code to run on it would be difficult, and could not support the advanced features released over the past five years or so.
  2. The iPhone G does not have a rear facing camera. One of the features I want to eventually support is using the camera for a room monitor. But since the phone will be mounted to a wall, the normal front facing camera will be pointed into the wall.

That said, the support for iPhone 3GS is not bad, but it is limited.

  1. iOS 6 is supported
  2. Xcode 7.3.1 is supported, currently the latest Xcode.
  3. Swift is NOT supported. Swift requires iOS 7.
    Image of iPhone 3GS

    Using an iPhone 3GS for simple control panel

So just for fun, I created a version of the control panel in Objective-C for iOS 6 to run on the iPhone 3GS. This app simply displays images in a collection view, and calls the Particle.io API when one is pressed. I probably won’t add much more to this app, but instead develop a Swift version for use on the newer phones. I’ll add new features to that version, and leave the Objective-C version for just simple control operations.

Update: I’ve now posted a cleaned-up version of the app code to Github, and and article on Hackster.io.