Smart

Air

Powered by a Raspberry Pi, SmartAir is a custom-made accessory designed to transform a box air conditioner into an iOT (Internet of Things) controllable system. The box AC unit has a knob that needs to be physically turned in order for the air conditioner to be switched on or off. Once connected, the AC automatically turns on and off on a schedule and can be toggled from anywhere with an internet connection.

Hardware

The hardware used in this project includes the following:

  • 6 3D printed parts
  • Raspberry Pi
  • Servo Bonnet
  • Servo
  • Button
  • 2 LEDs 
  • Jumper wires
  • Screws, and bolts
  • Opaque paper, tape 
Software

I broke this program up into three modules that run on the Pi, all of which are written in Python and use the zerorpc, Adafruit_PCA9685, GPIO, RPi.GPIO and time packages. Server.py handles the backend functionality, Client.py interprets requests sent over the internet to pass to the Server, and Scheduler.py acts as a client bot that sends requests to the server based on a preprogramed schedule. The fourth component of the software lets the user interface with the AC from a menu on their phone or with voice commands.

My Process

01

02

03

Concept 

Part 1: Design

Before I started, I needed to take precise measurements of my box air conditioner. Measure twice, print once. The more accurate my measurements, the less material cost and time to print.

Part 2: 3D Modeling

To create a model based on my design, I used a free 3D modeling website called Tinkercad. This let me export my model into individual 3D object files for each of the parts. The model pictured on the right displays how its parts fit together; it is comprised of four sides and a mount for the Raspberry Pi.

Part 3: Printing

Using a MakerBot, the object files can be loaded onto the printer via its software and printed. Each part took varying amounts of time to print, ranging from twelve minutes to three hours.

Part 4: Proof of Concept

To start, I printed one side with the servo mount and the part that covers the knob that attaches to the servo. To test if the servo had enough torque, I ran a simple program to turn it on and off again. Seeing that everything worked smoothly, I could then print out the rest of the parts and write the software to automate it.

Creation 

Hardware

In addition to the list of parts, I also needed a few tools to complete this project. I had access to a 3D Printer through my university, along with the ABS plastic to print the parts. Already having a soldering iron and solder from previous projects, I could start assembling right away.

Hardware: Extra Features

Instead of just having the servo communicate solely with the Pi via a smartphone, I decided to add a button to the front of the device. This way, the AC could still be turned on and off manually, even though the 3D printed enclosure completely covers the knob. I also added both a red and blue LED that not only makes the device 10x cooler, but also can be turned on and off to signify switching the AC on and off.

Software

For this project I decided to work in Python, as it has many packages that make it easy to work with on a Raspberry Pi. The program is separated into three different modules, the first of which is Server.py which continually runs on the Pi and controls the servo, button, and LEDs. Client.py sends commands to the Server whenever a network request comes in that turns on/off or changes the mode to home/away. Scheduler.py also is running in the background to automatically call the client to turn on/off the AC based on the time.

Server.py

The Server module controls all hardware components such as the button, LEDs, servo bonnet and servo. To accomplish this it defines several functions to change its behavior.

Turning On & Off

Two of the simpler functions are called by the client to turn on and off the AC by turning the servo to predefined angles. In addition to its core functionality, these functions will also animate the LEDs corresponding to getting cooler or not.

Feedback

Every function that can be directly called by the Client will return a string back to the user describing what happened.

 def turnOn(self):
     if not self.acOn:
        print "Running turnOn()..."
        #Moves servo to turn On
        pwm.set_pwm(servoPin, 0, (ON_POSITION + 20))
        self.acOn = True
        self.animateLEDs(blueLEDPin)
        return "The AC has been turned on at your apartment"        
     else:
        return "The AC at your apartment is already on"

        
 def turnOff(self):
    if self.acOn: 
        print "Running turnOff()..."
        #Moves servo to turn Off
        pwm.set_pwm(servoPin, 0, OFF_POSITION)
        self.acOn = False
        self.animateLEDs(redLEDPin)
        return "The AC has been turned off at your apartment"
    else:
        return "The AC at your apartment is already off"
 def away(self):
        if self.schedule:
            print "Running away()..."
            self.turnOff()
            self.schedule = False
            self.fadeLEDs("down", 75, 0)
            return "Have fun!  I'll stay here and make sure the AC stays off at your apartment"
        else:
            return "No worries, you already told me you were leaving. Your AC will stay off at your apartment"

 def home(self):
        if (self.schedule == False):
            print "Running home()..."
            self.schedule = True
            self.fadeLEDs("up", 0, 75)
            return "Welcome home. The AC will automatically turn on tonight."
        else:
            return "You never left ya silly goose! The AC will automatically turn on tonight."

Home & Away Modes

To put the smarts into SmartAir, the program has two modes: home and away. First, when the away function is called, the server turns the AC off if it is not already. It will also stop the schedule from running and turning the AC on when you aren't at home. The LEDs will also completely turn off to signify this mode is active.

On the other hand, home mode will reactivate the schedule to automate cooling the apartment. This will turn the LEDs back on to show that home mode is on.

The LEDs are used in various ways in the code above and throughout the module. They are faded up and down individually, together, alternating to create the startup and switched state/mode animations. The code for controlling the LEDs can be found here.

Client.py

The Client serves as a middle man between the user's device (such as a smart phone) and the device itself. It takes network requests and calls the appropriate functions on the Server module.

Zerorpc
Zerorpc allows for any device to call functions running on the Server module. This is all achieved through the Client module; when a connection is made to the server, its functions can be called directly from the client.
c = zerorpc.Client()
c.connect("tcp://127.0.0.1:4242")
    
if command == "turnOn":
    print c.turnOn()
elif command == "turnOff":
    print c.turnOff()
elif command == "home":
    print c.home()
elif command == "away":
    print c.away()
schedule.every().day.at("20:10").do(schedulingOn)
schedule.every().day.at("20:50").do(schedulingOff)
schedule.every().day.at("23:20").do(schedulingOn)
schedule.every().day.at("23:40").do(schedulingOff)
schedule.every().day.at("03:30").do(schedulingOn)
schedule.every().day.at("04:00").do(schedulingOff)
def schedulingOn():
   if c.getSchedule():
        c.turnOn()
        print 'The AC turned on at your apartment at ' + str(datetime.datetime.now().time())
            
def schedulingOff():
    if c.getSchedule():
        c.turnOff()
        print 'The AC turned off at your apartment at ' + str(datetime.datetime.now().time())

Scheduler.py

The Scheduler module is a type of client of its own, although instead of a user making requests, it acts as a bot, sending commands directly to the Server module.

Scheduler

When the device is in home mode, the Scheduler module will automatically call the on/off functions according to a schedule. When the device is set to away, the AC will turn off if it is currently on, and stay off.

In the future, I will add a temperature sensor to the raspberry pi; this way the Scheduler will be able to dynamically turn on/off the AC based on the current temperature of the apartment.

Testing

SmartAir Completed

Hardware Check

All of the separate 3D printed sides fit together seamlessly and securely fits on the AC unit without any adhesive. Similarly, the button, LEDs, servo, and Raspberry Pi all fit nicely into place, is wired correctly and powers on.

Shortcuts

On iOS, Shortcuts is an easy way to automate tasks. Here it is used to call the Client module and call one of the four functions.

Siri

Shortcuts also make it easy to set up voice commands with your workflows. Here saying, "Hey Siri, turn on my air conditioning." will run the Client to turn it on.

Notifications

In Server.py each of the functions return a message. This message tells the user the status of their request.

Software Check

In addition to the four options running as expected from a smart phone, the button works and LEDs all fade in and out turning on and off.

This project has been a lot of fun and I got to learn many new things in the process. In addition, since its creation, this devise has paid for itself several times over, saving me about 40% on my electric bill.