Home Automation with openHABian and IFTTT

Home Automation with openHABian and IFTTT

In our last how-to guide, we showed you how to create a central smart home system using Raspberry Pi. Now, we’ll show you how to create simple home automation projects that make everyday tasks easier.

Many smart home functions are dependent on someone being in the house, but we will show you how to turn certain functions on and off using the GPS in your smartphone. Find out how you can turn off your alarm system or automatically feed your pets with a push of a button below:

The project

Suitable for: Beginners with basic Rpi knowledge/advanced
Time required: 1-2 hours
Budget: Approximately £70
What you need: 1x Raspberry Pi3 set, network cable (optional)
Can be extended with: Any smart home systems
You’ll also need: Screen, PC keyboard, internet connection

Ensure openHABian is already set up

In this guide, we will show you how to automate your smart home devices. To do this, you need a Raspberry Pi that already has openHABian installed and a smart home device you want to control. All the information you need on how to install openHABian can be found in our last how-to here.

IFTTT: What does “If this, then that” mean?

IFTTT (If this, then that) is a useful app that allows you to install small automated solutions in your everyday life. It works on the simple principle: “If A happens, then action B”.

Here’s an example: “If I like a song on Soundcloud, then add it to my Dropbox”. In the context of smart home automation, the instructions could be: if I enter the house with my smartphone, then get openHAB to <perform the desired action e.g. switch on the lights>.

Connect your smartphone to the smart home

To connect your smartphone to your openHABian, you need to make sure you have set up your smartphone and your RPi correctly. Let‘s start with the necessary settings in openHABian. If you followed our recent how-to, you should already have a connection to your account at myopenhab.org.

Now you need a variable that stores your presence status. To do this, save the following line as Presence.items in the items folder on your RPi (use the Samba connection again):

Switch presence “I’m home” <house>

Next, tell openHABian which items you want to share with openHAB Cloud Services. One way to do this is in the interface under PaperUI -> Services -> openHABCloud -> Configure and under ‘Items to expose to apps,’ search for IFTTT and add your presence item. To be on the safe side, add ‘presence’ to the list in services/openhabcloud.cfg.

Share your item with OpenHab Cloud Services
Share your item with OpenHab Cloud Services

The ‘presence’ state must be changed at least once. Simply add a button to the HABPanel that controls the presence item and press it once. If you go to myopenhab.org you will see your item with the current status.

Also add your item in the config file
Also add your item in the config file
Finally add a button and press it
Finally add a button and press it
If you are successful, you will see your item online at myopenhab.org
If you are successful, you will see your item online at myopenhab.org

Install IFTTT

Now you need to install the IFTTT app on your smartphone (NB there isn’t a version currently available for Windows Phone). Simply create an account or log in with your Google or Facebook account.

Setting up your smartphone: Link IFTTT to your openHABian
Setting up your smartphone: Link IFTTT to your openHABian

Once logged in, select the magnifying glass, search for openHAB and select ‘Connect‘. You’ll need to use your login credentials from myopenhab.org. Once complete, your smartphone will be connected to your smart home and you can then choose the settings.

Choosing your settings

First, you will need to change the state of the ‘presence’ variable when you get home. Go to the openHAB service in your IFTTT app and select: ‘Turn presence on when entering your home area’.

Choose the first setting: the ON command will be sent to your item when you enter your home area
Choose the first setting: the ON command will be sent to your item when you enter your home area

Here you can define your home area and which command should be sent to which item. In our case, this is the ON command. Now do the same for the OFF command: ‘Turn presence off when leaving your home area’.

To activate a device for these commands, you have to define rules. For this, we can adapt the example from the last how-to, where a Python script was executed. Save the following script as Presence.rules in the corresponding folder:

rule “Presence @ Home”

  when

    Item Presence received command

  then

      while(Remote_Send.state == ON){

      Thread::sleep(500)

    }

    if(receivedCommand == ON){

      Remote_Send_Args.sendCommand(“1 ON”)

    }else{

      Remote_Send_Args.sendCommand(“1 OFF”)

    }

    while(Remote_Send.state != OFF){

      Thread::sleep(500)

    }

    logInfo(“Relay_Switch_1.rules”, “Result:” + Remote_Send_Out.state )

end

Here you can define your own rules. In the example shown, a relay is switched as soon as you get home or leave home. This could be to disable or reset an alarm.

Further automation possibilities

The smart home automation possibilities with openHABian are endless. For example, you can define rules based on time of day or season, the weather or even events in your Minecraft account.

Of course, your options are dependent on your connected devices. If you want to delve further into the topic, we recommend that you read the documentation on rules at docs.openhab.org.

Images: reichelt/manufacturer, Adobe Stock

Leave a Reply

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