Control Your Smart Home with Mails

A smart home offers a lot of possibilities. If you want to access via the Internet, there are still some risks.

 hackster_title_iycifBPxje

Story

A smarthome offers a lot of possibilities. Today, almost everything can be interconnected in this context, providing more convenience, quality of living, cost savings and security. If you want to access via the Internet, there are still some risks.

Starting from lighting to heating or camera surveillance to your washing machine – almost everything can now be connected to a smarthome. This is convenient and once you get used to it, you usually want to be able to have some functions not only in the local LAN.

But then it is necessary to make your system accessible via the Internet. With this step you are much more vulnerable from outside. You need to keep your system always up to date. A residual risk remains, even if you work with a Raspberry Pi under Debian with a very secure system.

Because of this I am currently not ready to open my system for the Internet. Nevertheless, I would like to use the advantages.

But the smarthome computer is usually still connected to the Internet via your network and a router. Why not use this existing connection? This may not be the most beautiful solution possible, but a safe one.

A Mail Control

I would like to show you an example of this solution for such a possible intermediate stage: an e-mail control.

shm_konzept_mail_en

On your computer with the smarthome software, another software checks regularly your mailbox. When a message meets certain criteria, the software starts actions.

In my case the smarthome computer is a Raspberry Pi. A cron job regularly – every 5 minutes – checks my special smarthome mailbox for new messages. Which minimum interval is possible depends on the mail provider. Some providers do not allow small intervals.

To ensure a high level of security here, several conditions must be met before an action is triggered. What are these steps? You’ll find mine in the following figure.

shm_pruefungen_en

An example of an e-mail for a query might look like this:

From:name@provider.de
To:smarthome@provider.de
Subject: SH
Message:
**STATE
**LIGHT_G_OFF

Only if the subject is SH and the sender adress [email protected] has permission and valid commands are included ( **STATE, **LIGHT.. ), the actions are performed by the software.

Examples of commands:

** STATE Could send back an email with interesting states in the message body, e. g. doors are open, which lights are on, etc.

** REBOOT Reboots the Raspberry Pi. This is not often necessary, but sometimes useful.

But you can also set actuators as a light. By the time offset of mail retrieval, which is obviously not useful for a direct control. But a forgotten light could be turned off. In my case it works with this command:

** LIGHT_G_OFF Turns off the lights in the garage.

** …

Realization with Lazarus and Free Pascal

For the coding of this application I use Pascal as programming language. This may be not so common for Raspberry programs, but is quite interesting, if you want to compile to real binary code and use it on other platforms too. You'll find Lazarus under http://www.lazarus-ide.org/.

You fetch messages from the mailbox via the IMAP protocol. To do this there are several settingsnecessary – depending on your mail provider. In the source code, the values ​​are stored as constants.

IMAP_HOST = ‘imap.1und1.com';
IMAP_PORT = ‘993'; //or 143
MAIL_USER = [email protected]';
MAIL_PASSWORD = ‘secret';

Lazarus does not provide functions working with mails by default. But there is a very good library Synapse from Ararat. You can find the download link at the end of this article. Unpack the archive to any folder and add the folder to the project. Alternatively, you click ADD FILES FROM THE FILE SYSTEM in the project inspector and select imapsend.pas in Synapse folder.

shm_lib_hinzufuegen

Programming the library is very simple. In the sample application all steps to check the mailbox for new mails is stored in the procedure CheckMailbox.

Read More Information…

Control Your Smart Home with Mails


About The Author

Muhammad Bilal

I am highly skilled and motivated individual with a Master's degree in Computer Science. I have extensive experience in technical writing and a deep understanding of SEO practices.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top