Chris Rieger | Raspberry Pi Blind and AC Controller

Raspberry Pi Blind & AC Controller

The Raspberry Pi has been setup to connect wirelessly to the network, where a web interface can be accessed which sends commands to a 'controller' script. There are two aspects to the build, the blind opener and airconditioning control. The easystepper motor driver is interfaced to an old stepper motor which drives the blinds. The step pulses are sent using the GPIO library. The LIRC library was used to record and send infrared information to control the air conditioning. The information had to be recorded in RAW mode, as the information length was longer than normal.

Parts List:

Download Files

Useful/Important Links:

How to:
If you run into any problems below, feel free to drop me a email.

I'll start with first imaging the SD card:
sudo dd if=path_of_your_image.img of=/dev/diskn bs=1m
# Where n is the disk number as per disk utility. Ensure card is unmounted.
Now we need to prepare the software and wireless network configuration. This is done as follows:
sudo apt-get update
sudo apt-get install vim
sudo apt-get install wicd wicd-curses

sudo vim /etc/network/interfaces
	auto lo

	iface lo inet loopback
	iface eth0 inet dhcp

	allow-hotplug wlan0
	iface wlan0 inet static

	wpa-roam /etc/wpa_supplicant/wpa_supplicant.conf

	iface default inet dhcp

sudo vim /etc/wpa_supplicant/wpa_supplicant.conf
	ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev

	        pairwise=CCMP TKIP

	        pairwise=CCMP TKIP
Now the wiring lib must be installed to drive the GPIO and consequently the stepper motor. I found a great link that explains how to install this package, listed in the link list at the top of the page.
cd /tmp
sudo apt-get install libi2c-dev
tar xfz wiringPi.tgz
cd wiringPi/wiringPi
sudo make install
cd ../gpio
sudo make install
Nginx and PHP must be installed to allow for web access to the controller. I prefer Nginx over Apache as it is more lightweight and I am more familiar with it's configuration.
sudo apt-get install nginx
sudo apt-get install php5 php5-fpm php5-cgi php5-cli php5-common
sudo mkdir /var/www
sudo chmod 775 /var/www -R 
sudo chown www-data:www-data /var/www
sudo mkdir /var/www/local
sudo chown www-data:www-data /var/www/local

sudo nano /etc/nginx/sites-available/local
    access_log /var/log/nginx/local.access.log;
    error_log /var/log/nginx/local.error.log;

    #Error Redirect
    error_page 404 /404.html;

    ### Default location
    root /var/www/local;
    index index.php index.html index.htm;

    ### Static content passed through
    location ~* ^.+.(jpg|jpeg|gif|css|png|js|ico|xml)$ {
        expires 5d;
        access_log off;

    if (-f .php) {
        rewrite ^(.*)$ /.php;

    # use fastcgi for all php files
    location ~ \.php
        try_files  =404;
        include /etc/nginx/fastcgi_params;
        keepalive_timeout 0;
        fastcgi_param   SCRIPT_FILENAME  ;

    # deny access to apache .htaccess files
    location ~ /\.ht
        deny all;

sudo ln -s /etc/nginx/sites-available/local /etc/nginx/sites-enabled/local
sudo service nginx restart
The motor should be turned off by default using the enable pin on the stepper motor driver. This will ensure that the motor doesnt waste power when it's not needed. The controller script automatically turns the pin on and off when the blinds are used. In order to do this, add these lines to a startup script:
gpio -g mode 11 out
gpio -g write 11 11
Create a cron job file. This file will be used by the controller script.
sudo touch /etc/cron.d/blinds
sudo chmod a+w /etc/cron.d/blinds
Now, install copy the controller and php files to /var/www/local/ directory. Make the controller executable:
sudo chmod +x /var/www/local/ 
For the AC control, the LIRC library is used to control an infrared LED which replicates the signal sent by my Daikin AC unit. A great guide for getting LIRC setup can be found in the link list at the top of the page.
sudo apt-get install lirc
Add this to /etc/modules file
lirc_rpi gpio_in_pin=23 gpio_out_pin=22
Copy the attached lircd.conf and hardware.conf files included on this page to the /etc/lirc/ folder.
sudo service lirc restart
Normally, the IR signals can be recorded using 'irrecord', however, the Daikin system sends blocks of information seperated by larger gaps that causes the recorded signal to be truncated. This can be bypassed by using 'mode2' to record the raw IR information. Simply launch the command below and ctrl^c to stop escape / stop recording.
sudo service lirc stop
mode2 -d /dev/lirc0 >> ~/temp.conf
In order to get the data into to correct format, remove the first row in the temp.conf file you just created, which is just the 'space' between when the recording started and you started to press the button. Then use the following commands in VIM to format the codes correctly.
vim ~/temp.conf
:%s!^!    !
After this, you can insert the codes into the config file. You can refer to the attached lird.conf to compare how to lay out the data. Now, add the codes to the original file created by irrecord in raw mode. LIRC doesn’t seem to tolerate tabs in the lidcd.conf file, so remember to use spaces.
After this, restart the lirc process and check if your remote is recognised:
irsend LIST "" ""
irsend LIST DAIKIN ""
And finally, send the out the signal..
The included script automatically takes care of processing these commands when received from the webpage. Viewing the attached source files should make it clear what's going on.

© Copyright 2015 by Chris Rieger.
Raspberry Pi CPU: 0.8% , temp=42.8'C