Anth's Computer Cave

AAIMI Home Automation Tutorial Hub

Use the buttons below to read all of the AAIMI Home Automation tutorials.

Run AAIMI Home Control

13th February 2018

We've installed AAIMI Home Automation and configured our rooms and devices. Now we can start the main program, aaimi_home_control.py.

This program monitors your home on a one-second loop, checking sensors and listening for commands. It needs to run 24/7, so we will run this in Screen.

Screen

Screen is a session-management tool that can run programs in the background on Linux even if nobody is logged on. One of AAIMI's programs need to run 24/7, so we will run this in Screen.

Log onto the Raspberry Pi via SSH and navigate to the aaimihome/aaimi folder. Open a screen session by typing:

sudo screen

Starting Screen on a Raspberry Pi.

Screen will display a page full of details about the program. Press space to proceed.

You should now see a new terminal prompt.

The Screen prompt on a Raspberry Pi.

Notice the terminal prompt is now white, instead of the previous green and blue, and the $ symbol at the end of the prompt has changed to a # symbol. These are the only visual indicators that you are inside a Screen session.

Notice also that instead of your user account you are now running as root. This is good, because aaimi_room_control.py needs to run as root to perform system-level tasks.

Now we have our Screen session running we can start the AAIMI program.

AAIMI Room Control

To start the main program type:

sudo python aaimi_room_control.py and press Enter.

You will be asked for the admin password you set during the setup wizard. Enter the password and press Enter.

The passkey prompt from AAIMI administrator.

The AAIMI system should now begin loading. If outgoing email is enabled it will send you a welcome email with the URL link for the server.

It will load any encrypted user and access files, as well as the GPS perimeter for your home.

After it sets the GPIO pins for your devices it will create a serial connection to the Arduino, then switch off all relays that default to low.

The AAIMI system starting up.

Next it configures initial password access for any remote systems, and generates a new random password for itself.

Finally, it starts the main listening socket that routes incoming commands from PHP.

AAIMI will begin its first loop, checking any sensors that are due for reading. In each loop that means all the movement sensors. You want your lights to switch instantly when you enter a room, so these sensors need to poll each loop.

The system checks light, temperature or air sensors only after it has performed the number of loops to match their defined frequency.

If it senses movement in a room it will check the current light-level of the room.

The AAIMI system starting up.

If the room is darker (higher) than it's switching level AAIMI will switch on the light.

At the end of the loop it will write any new readings or occupancy changes to file for live display in the browser-based GUI. All of these light, temperature and air changes are also added to AAIMI's main data file, which is there to collect data for long-term uses.

If AAIMI senses no movement for the amount of seconds specified as the room's timeout, it will declare the room vacant and switch the light off.

Exiting Screen

You can exit the Screen session now. If you do not exit Screen correctly, the AAIMI Room Control program may shut off.

To detach from the session, head back to the terminal and hold CONTROL and press "a" once. Keep holding CONTROL and press "d". You'll see your normal terminal prompt and a message that you have detached from screen.

To access the session again later, type sudo screen -r. The session will resume with the window you had active when you detached.

During each save, AAIMI moves the previous save to a file called switch_back.txt. This file acts as a running backup you can restore if something goes wrong. Note that this only gives you one restore point. I recommend regularly copying the save file to another location as a manual backup regime.

Next

In the next tutorial I'll show you how to add your housemates into the system, and configure your smart phones to tell AAIMI who is home.

I'll show you how to use all the various features in the browser-based GUI. We'll also add some custom theme images, and some clipart and mp3 files for visual and audio alerts.

Cheers

Anth


Previous: Configure rooms

Next: Control AAIMI Home Automation


_____________________________________________


Comments

Leave a comment on this article