Wednesday, December 14, 2016

The Raspberry Pi 2 is the ideal starting point to control a smart home

The Raspberry Pi 2 is the ideal starting point to control a smart home. Earlier we showed how you operate the software Domoticz lighting. In this article we build upon and link your computers, a security panel, text messages, IFTTT and NFC tags to your home.

Domoticz
We assume in this article that you Domoticz already installed on your Raspberry Pi and that you have connected various sensors and other components. In this article you read how that works out. You probably have already gotten the message on the web interface Domoticz that an update is available. If not, click in the menu settings to check for updates .

Make sure Domoticz is up-to-date.
Domoticz update
If the update does not work through the web interface (Internet Explorer or Edge does not seem to work this), please login with the PuTTY program on your Raspberry Pi (standard with username pi and password raspberry ) and go to the directory Domoticz with the cd command domoticz. Update to the latest stable version of the command ./updaterelease or the latest beta version ./updatebeta. It's also a good idea to periodically upgrade other software on your Raspberry Pi. You can with the commands sudo apt-get update and sudo apt-get upgrade.

Wake-on-LAN hardware
Domoticz can the computers in your home network awaken with Wake-On-LAN. Just click first in the menu Settings on hardware . Now, add virtual hardware. Choose down by type for Wake-on-LAN and enter a name for your virtual hardware. At Remote address you enter in your network mask (eg 192.168.0.255 and port fill 9 in. Click Add . Then select your Wake on LAN hardware from the list and click Settings .

Wake-On-LAN lets you wake computers on your home network.
add MAC addresses
You will now see a provisionally empty list of computers and associated MAC addresses. Add a computer is simple: fill down the name and MAC address (what something looks like 01-23-45-67-89-ab ) and click Add . Then click in the menu settings on devices . The list now contains you just added devices. Click the green button next to it, enter a name and click Add device to a switch in the tab Switches to add. Click on the button (the icon with a power button) then Pi sends you a Wake-on-LAN network packet to the computer, which is created thereby.

wake computer
This wake of your computers is to automate now, not only at fixed times, but also as a response to sensor events. Suppose you work at home and want on weekdays automatically start your work computer when morning comes into your office. Then go in the menu settings for more options and Events . Trail classes left all kinds of pieces together until you've defined a computer program that generates the desired manner. For example, something in the nature and If Day <= Friday and Time> 8:00 and Time <17:00 and Movement office = On Th = On Set Desktop .

Automate the wake of your computers.
Add User Variables
For more complex automation of your smart home is convenient as you can use in your program variables that have a certain value. For example, a variable Season whose content has the current season. Open instead in the menu settings under More Options section User Variables . We first make a number of variables: Year , Month , Day , Hour , Minute , Weekday , Season , Weekend , Dark . Always enter the name and click Add . The type of love you Integer (but Season , Weekend and Dark puts it at String ), and if you always give value 0 in (which we set later after all good).

installing Luascript
Before we can use all these variables, they need meaningful values. We will of course not do, but let's get a script. On the wiki page User variables on Domoticz website contains a script that does this. Copy the entire script entitled Lua with Ctrl + C . Sign in with PuTTY on your Raspberry Pi and navigate to the correct directory with cd domoticz / scripts / lua. Create a new file using the command nano script_time_update_variables.lua and paste the copied text into it. Save the file with Ctrl + D and close nano with Ctrl + X .

We do the work through a script.
blinds
If you're in Domoticz on the page User Variables look, you see that all variables have been given a correct value, which is updated every minute. We go this now use a new program in the summer we let the blinds on the south side of the house down when the temperature in the house exceeds 24 degrees and we are not at home, so we were near the back not in a hot house fall. Open the page Events and click the appropriate blocks together into something like If Season = "Summer" and Security status ≠ "Disarmed" Temperature and living room temp. > 24 Do Set Shutter sash = On Set Shutter kitchen window = On . The variable Season are links in the category User variables .
security Panel
Domoticz has a protection panel, which you can make an alarm system in principle. Enter in the Domoticz settings as a numerical password for the security panel and a delay in seconds. Then, the security panel is displayed in the tab Switches . Click it, then you will see a virtual screen with status (default is Disarmed ) and number keys and other buttons. Enter the passcode and select Arm home or Arm Away . After the delay will change the status of the protection panel. As with other switches, you can associate a timer or purchase and uitacties the protection panel, you can use the status of scripts, like we did in step 8.

Connecting phone
In the previous article about Domoticz we set notifications via online services such as Prowl and Push Bullet or via email. But what if your internet connection goes out at home? Fortunately, we can also have text messages sent our Raspberry Pi when something happens. Connect via USB before an old phone with a SIM card that has the ability to send SMS messages. First, look at the Gammu Phone Database check whether your phone is supported. Then log in using PuTTY on your Pi and install Gammu with sudo apt-get install gammu.

In Gammu Phone Database you can see if your phone is supported.
configure Gammu
Then start the configuration program with gammu-config and enter the information that you found in your model in the Phone Database. Save the configuration to the arrow Save to go and press Enter. Then try with gammu identify whether Gammu recognize your phone. If you get an error, then restart the configuration program and try a different port number from. Once Gammu has identified your phone, your connection is ready to send in text messages.

Send a text
We now make a Luascript that an SMS message sent when you opens door while your security panel not Disarmed state. Create a new file using the command nano domoticz / scripts / lua / script_device_alarm_voordeur.lua. Type contains the rules if (device changed [ 'door contact door'] == 'Open' and not globalvariables [ "Security"] == "Disarmed") then, os.execute ( '/ usr / bin / gammu --config / home /pi/.gammurc --sendsms TEXT + 31TELEFOONNUMMER -text "ALARM:. The door is open") and end. Obviously change the name of the contact sensor of your front door and your mobile number. It is also possible to send a message to multiple mobile numbers. Just repeat the line from os.execute with another phone.

This allows Luascript send an SMS and opens the door.
Notifications with IFTTT
Since mid-2015 offers IFTTT a Maker channel to make arbitrary HTTP requests and respond to them. That way, you can link your Domoticz system to all kinds of online services. Visit the Maker channel, log in (or create an account) and click Connect . You will now see a key and explain how you can trigger an event. Now go into the web interface Domoticz to the switch that you want to trigger IFTTT. Click on Customize and fill in the on-or-uitactie https://maker.ifttt.com/trigger/EVENT/with/key/SLEUTEL in which you have a name for the event, select and the key ( key ) you assigned fill. Click Save .

IFTTT recipe
Then, make a IFTTT recipe that responds to the triggering of Domoticz. In the if-part of the Maker channel Receive a Web request over and fill it entered into Domoticz event, such voordeur_open . Click Create Trigger . Then choose that-the portion of your prescription, such as the sending of an e-mail. Click Create Action and then Create Recipe . Now, when the switch is turned on in Domoticz, the IFTTT-action is performed. The possibilities are endless. IFTTT also supports a lot of IoT devices, you can integrate that with Domoticz, such as thermostats, Honeywell and Netatmo the Smappee energy monitor and WEMO devices from Belkin.


The great thing about IFTTT is that a lot of internet-of-things supports devices.
Activate scene with IFTTT
Also in the other direction is interaction. We show how to activate a scene in response to a Domoticz IFTTT trigger. Domoticz need for doing so are accessible via the internet. You must have set port forwarding in your router and also the best DynDNS. Search the scene in your list of devices and record the value in the column Idx . Then create a recipe in IFTTT. For the action you choose the Make-channel and then Make a web request . Enter the URL http: // USER: PASSWORD @ DOMOTICZURL: DOMOTICZPORT / json.htm type = command¶m = Switch scene & idx = ID & switchcmd = On? In which you of course your data enter in the URL and the IDX of the scene instead of ID. If Method choose GET , as ContentType choose text / plain and body leaves you empty.

NFC
Finally, we show how something similar with NFC realizes tags. You stick around then tag on your nightstand or elsewhere in the house and activates a scene in Domoticz if you keep your phone on it. Under Android can with the app Trigger. While in the app Create a task . Press the plus sign to add a trigger and select NFC . Press Next , select possibly triggered the task on which days and times, and press Finish . Then press Next to add actions.

Add action
Press the plus sign to add an action. Choose the category of Applications and Shortcuts to open a URL / URI and press Next . Enter the URL of the JSON URL of your Domoticz-scene, as in step 14. You can if your phone wifi do use use local url and if you have authentication disabled on the local network, you do not have a username and password to give in in the url. After completing the url Add to task . Give your task a name and click Next . With a push Completed make up the task.

Domoticz API
Now hold the NFC tag under your smartphone to describe the tag. If that's right, the JSON URL of your Domoticz scene opens on your phone if you are moving along the NFC tag. Check out the wiki page Domoticz API / JSON URLs for other options, such as turning on or off a switch or dim a light to a certain percentage. You can also create multiple tags with the app Trigger, so for example you with a tag on your nightstand the shutter closes at night and opens in the morning and turn on your mood lighting with a tag on your television.

No comments:

Post a Comment