Designer for Android smart home applications. Google Home application - control center for smart home devices

Not long ago, a Z-Wave module for Raspberry Pi was introduced - RaZBerry, which turns a mini-computer into a full-fledged controller smart home. Z-Wave network management is carried out using a web interface using HTTP/JavaScript API. Using JavaScript, you can create a set of functions for automation (turning on/off lights, checking temperature, polling a motion sensor, etc.), which can then be executed by sending an HTTP request.

The OpenRemote company's product of the same name allows you to create mobile applications for a smart home without programming, while one application can use different technologies: Z-Wave, KNX, X10, ZigBee, computer control via ssh, etc.

OpenRemote is a server that executes any commands and an interface designer in which you create buttons, switches, labels, etc. and assign commands to these elements, in our case these are HTTP requests to execute JavaScript functions on the Z-Wave server.

Next, I will tell you point by point how to create a smart home remote control for iPhone and Android! And this is what our application will look like when we're done:

There are a lot of pictures under the cut.

1. Creating a Z-Wave network using a Raspberry Pi + RaZberry controller

  • Installing RaZberry software on Raspberry Pi
  • Adding Z-Wave devices
  • Checking the device operation
2. Installation of OpenRemote controller and mobile application

3. Creating the application design and logic of its operation

  • Design development
  • Association of buttons with commands
4. Summary

Creating a Z-Wave network using a Raspberry+RaZberry controller

RaZberry is a board connected to the Raspberry Pi via GPIO, allowing you to create and manage a Z-Wave network. For a better understanding please read the FAQ. The board comes with software that needs to be installed.

Installing RaZberry software on Raspberry

The installer only supports Debian-based distributions (Raspbian, Xbian, etc.). However, you can manually install the software on OpenElec and other OSes.
Run the command to install Z-Way software:
wget -q -O - http://razberry.z-wave.me/install | sudo bash
After installation, you must reboot the Raspberry Pi to apply the changes to the Serial port.

To get to the smart home control panel, go to http://IP_OF_YOUR_RASPBERRY:8083. The program interface is very simple, it will not be difficult to understand it, there is documentation. The following browsers have maximum compatibility with the interface: Chrome, Safari, Firefox; other browsers: IE, Opera may not work correctly.

Adding Z-Wave devices

Let's determine the list of equipment used:
- Relay Fibaro Single Switch 3kW 2 pcs.
- Door/window opening and temperature sensor Fibaro Door/Window Sensor 1 pc.

From the bottom menu select Expert Mode. Using the top menu, go to the tab Network → Network Management and press Turn on (re)device, this will start the process of waiting for the device to be connected to the network, now press the service button on the device three times so that the controller sees it and adds it.

Checking the device operation

Let's make sure the device is working. Go to the tab Setting up devices, click on the only added device in the left column and check Interview stage must be The interview was successful and there should be no dots or Ø between the pluses.

If the interview is not completed (there are dots and Ø signs), then you can repeat it, to do this, click at the bottom of the screen Additional actions → Force interview repeat(Expert mode must be enabled to see this menu).
After a successfully completed interview, on the same tab Setting up devices you can configure some device parameters (don't forget to apply the settings using the Apply settings to this device at the bottom of the screen, and also wake up the device if it runs on batteries):

To manage the device, go to the tab Device management → Switches

About the provided automation API

Having made sure that all devices are working correctly, let's now try to control them remotely. There are several ways:

1. Using HTTP/JSON API
2. Using JavaScript API

HTTP/JSON API uses a simple syntax to manage devices.
You can turn on the light from the browser:
http://192.168.1.113:8083/ZWaveAPI/Run/devices.instances.SwitchBinary.Set(255)
Or request temperature:
http://192.168.1.113:8083/ZWaveAPI/Run/devices.instances.commandClasses.data.val.value
JavaScript API allows you to write various automation scripts, for example: turn on/off the light, poll the sensor, get the temperature, turn off the light 2 minutes after turning it on. These scripts can work either independently (for example: at night the light turns on only 15%, so as not to blind the eyes), or can be called remotely using HTTP/JSON API.

Script for turning on the light:
SwitchOn = function(N,I) ( zway.devices[N].instances[I].SwitchBinary.Set(255); )
Calling the light switch script:
Unfortunately, directly accessing devices using the HTTP/JSON API from OpenRemote is problematic for several reasons:

1. Characters must be recoded to UTF-8 in the OpenRemote Constructor
2. When polling sensors, OpenRemote expects “on” or “off”, and Z-Wave sensors can send 255 or 0.
3. For each device you will have to write your own request, and using JS you can use only one function to enable various devices, changing only the function parameter in the request - the device number.

When using the JavaScript API, all these problems disappear - several “helper” functions will help transform Z-Wave terms into concepts convenient for OpenRemote.
You can read more about the syntax of the HTTP/JSON API and JavaScript API in the recent one.

Creating JS scripts for remote control

JS scripts are in /opt/z-way-server/automation/, let's create a file in which our automation functions will be stored openremote.js so that it is automatically loaded when Z-Way is turned on, at the end of the main automation file main.js add:
// ==================================================== ====== executeFile(automationRoot + "/" + "tags.js"); executeFile(automationRoot + "/" + "openremote.js"); startAutomation();
/opt/z-way-server/automation/openremote.js
// Turning on the device SwitchOn = function(N,I) ( zway.devices[N].instances[I].SwitchBinary.Set(255); ) // Turning off the device SwitchOff = function(N,I) ( zway.devices[ N].instances[I].SwitchBinary.Set(0); ) // Request for sensor status (triggered/failed) SensorStatus = function(N,I) ( return zway.devices[N].instances[I]. SensorBinary.data.level.value; ) // Request for device status (on/off) SwitchStatus = function(N,I) ( return zway.devices[N].instances[I].SwitchBinary.data.level.value; ) // Temperature query rounded to the nearest integer Temperature = function(N,I) ( return Math.round(zway.devices[N].instances[I].commandClasses.data.val.value); )

Parameter N is the device number on the network.
Parameter I - within one device there can be physically several devices (channels), for example 2 relays or a temperature sensor, a motion sensor, a light sensor. Parameter I is the channel number inside the devices. If the device contains only one physical device, then this parameter is 0.

After creating the file, you need to either restart Z-Way with the command:
/etc/init.d/Z-Way restart
or load the script manually by sending a request from the browser:
http://192.168.1.113:8083/JS/Run/executeFile("automation/openremote.js")
You can check the functionality of the functions from the browser.
To turn on the light:
http://192.168.1.113:8083/JS/Run/SwitchOn(6,0)
Request temperature:
http://192.168.1.113:8083/JS/Run/Temperature(8,2)
The Z-Way server log is very helpful in debugging:
tail -f /var/log/z-way-server.log
If everything works, move on to the next point!

Installing an OpenRemote controller

The OpenRemote controller is a server that receives commands from a mobile or web application and then transmits them to another controller or server. In our case, this is a Z-Way server.

The OpenRemote website has very detailed instructions according to the installation, which I propose to use:
Official installation instructions for OpenRemote in English

Let me just note that OpenRemote is written in Java and we need the version virtual machine with hardware floating point support:
JAVA for ARM processors with floating point support

Install mobile app for your phone:
Mobile application OpenRemote

Before you start developing an application, for a better understanding, look at how it will work:

Creating the application design and logic of its operation

All previous steps were just preparation for the main thing - creating a mobile application!
Open the cloud Designer http://designer.openremote.org. It won't be difficult to figure it out!

Design development

Let's move on to design development right away.

1. Go to the tab UI Designer and create a new panel, calling it, for example, iPhone4.

2. Drag buttons and images from the right panel onto iPhone screen.

3. In the image properties (right panel), upload your pictures and use the Left, Right, Width, Height fields to arrange them on the screen as you need. I uploaded images of a square and a light bulb, and also added an inscription.

Creating control commands and sensors

Now you need to assign commands to the buttons, and the picture of the light bulb should change depending on the state of the light (on/off).

1. Go to the tab and create a new device, calling it, for example, Raspberry.

2. Select the newly created Raspberry device and create a new command for it New → New command. Selecting a protocol HTTP, enter URL JS commands and method are installed POST.
This command turns on device #6. Similarly, we create commands to turn on other devices and commands to turn them off.
http://192.168.1.113:8083/JS/Run/SwitchOn(6,0)

3. Now you need to create a command to poll the state of the light. This command will be called every 2 seconds, so if you manually turn off the light, it will immediately become noticeable in our application. As usual New → New command, but additionally you need to indicate how often the survey should be conducted Polling, install 2s, letter s required.

4. Let's create a Sensor that will process the received values ​​from this command and transmit them to the image or caption. New → New Sensor, select the command that the sensor will execute, set the type custom, add two states on And off, we associate them with Z-Wave return values.

Association of buttons with commands

1. The last stage of application development, association of buttons with commands. Return to the Application Designer UI Designer, select your button and in its properties set the command that it should execute.

2. Associate an image with a sensor so that when the state of the device changes, the image in the application also changes. Select an image and set the sensor in its properties.

3. In the image properties, select which picture will be shown if the sensor sent on and what if the sensor sent off.

Synchronization with mobile application

1. Our application is ready, all that remains is to upload it to your phone. Go to the OpenRemote controller address

Hello, dear readers! Another story about how a very middle-level manager, blowing dust from stale pieces of hardware on a shelf, does something that makes professionals of all stripes hurt their eyes. ¡But it works, amigo!

I admit, this time I wanted to do everything right. I took the Raspbery Pi off the shelf. The pie is the same one that I already used in my robotic lawnmower: link to post and link to another post. I took mosquitto, everything should have worked on mqtt, but you can’t run away from yourself. Under the cut there is a sea of ​​rakes, bicycles, bad soldering, complete hell for a perfectionist.


It all started with the desire to complement my project Noorik, which I put on my gate. In short, this is a DIY solution for a GSM gate opener.
To open the gate, it is enough to close certain contacts on the board.

I replaced the arduino with an esp8266 and made a web interface with an open button. This turned out to be interesting, but then I wanted a single interface for opening sliding gates, sectional garage doors and gates.

When I started writing down all my Wishlist, it turned out that I needed the same thing:

  1. boiler room control system
  2. security system
  3. mobile interface to CCTV cameras
  4. data on temperature in the house and outside

Backend

Raspberry worked fine, but the next time it was turned on it simply stopped turning on. The power LED first lights up, then goes out smoothly in 3-5 seconds, the element (polyfuse T075) near the power socket gets very hot. And now my hands were itching to use mqtt, blackger, invite courtesans and other delights.

It doesn’t matter, fortunately another patient awaited his fate. Orange pi zero to the studio. No matter how much I suffered with this miracle of Chinese thought, breathing life into such a small pie turned out to be beyond my strength. I downloaded the firmware on the official and left-wing sites, I bought the firmware from my own hands and exchanged it for cryptocurrency. I think I just got a defective sample.

I realized that fate itself was pushing me into the arms of bicycle building, and why hide my joy, I plunged into this activity headlong.

First of all, I decided to use a well-worn smartphone as the head unit (broker, server). You know, these old things don't just go away. I, my wife, my daughter used it, then I controlled my robot snow blower from this smartphone, I tried to drown it in the river (I never got to the Moscow River, but in my native Pakhra this pipe made a rustle). And here it is - a new life for Samsung Galaxy S3.

I installed Palapa Web Server and Ftp server on my smartphone. The idea is simple: the MySQL database has only three tables: values, logs, rules.

  • The values ​​table contains key/value pairs.
  • The logs table contains a history of value changes.
  • In the rules table, there are rules for changing some cells depending on the value in others.
This entire farm is served by one php script, which according to http request writes or outputs data from the database, and also serves rules according to a schedule.
I don’t even understand what level of programming should be for a person to want to see this, but I’m ready to show you the code - write to me in a PM.

Frontend

Don't throw stones at me, I admit it myself. I used Bootstrap. Yes, I am a sinner.
The initial thought was to wrap it all through Phonegap and get full application. I will say more that I did just that, but in the end the online version turned out to be more efficient. I just made a shortcut on my phone for myself and my wife on the desktop to open the desired page using the internal IP.

Each element reacts to a click event + the state is checked by ajax requests to the server and changed if necessary. It’s very convenient because you can see all the changes that took effect according to the rule or were made by another user.
Actually, the code on request is no problem.

ESP-8266


I tried different modules and pure ESP-8266. As a result, the LOLIN V3 module turned out to be the most convenient option.

Power supply using switching power supplies.

The gate modules required a relay and I had concerns that the contact relays would trip. As a result, both solid-state and contact ones work. The problem is that a large number of modules, even without marking about it, are low-triggered.

When the module is turned on, a short-term opening occurs, which leads to involuntary opening when the power is turned on. It is solved by pulling it to zero and declaring the state before declaring the output type.

DigitalWrite(rele, 1); digitalWrite(rele2, 1); pinMode(rele, OUTPUT); pinMode(rele2, OUTPUT);
As a result, the assembled garage module looks like this. The PIR sensor for detecting movement is carefully gnawed into the original skin.

In my boiler room, the boiler is very simple and there is no talk of any complex automation.

In this case, each circuit is served by a separate pump.

Relays were connected in series with the machines to control the pumps and boiler.

Carefully pushes everything into the shield.

Firmware

I decided to use the Arduino IDE for firmware so as not to mess with nodemcu and lua. On the Internet and on GT in particular great amount information for beginners.
The interesting thing, it seems to me, is the function of connecting to wifi. The fact is that there are 4 in my house wifi networks and may be added. In order not to strictly specify the name of the network, we first scan the available networks.

setupWiFi() code

void setupWiFi() ( WiFi.mode(WIFI_STA); WiFi.disconnect(); delay(100); while(WiFi.status() != WL_CONNECTED) ( int n = WiFi.scanNetworks(); Serial.println("scan done"); if (n == 0) Serial.println("no networks found"); else ( Serial.print(n); Serial.println(" networks found"); for (int i = 0; i< n; ++i) { Serial.println(""); Serial.print(i + 1); Serial.print(": "); Serial.print(WiFi.SSID(i)); Serial.print(" ("); Serial.print(WiFi.RSSI(i)); Serial.print(")"); Serial.println((WiFi.encryptionType(i) == ENC_TYPE_NONE)?" ":"*"); j=0; ssid=WiFi.SSID(i); Serial.print("Connecting"); ssid.toCharArray(charBuf, 50); WiFi.begin(charBuf,WIFI_PASS); while(WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); j++; if(j>20)( break; ) ) if((WiFi.status() == WL_CONNECTED))( break; ) ) ) ) Serial.println("Connected"); Serial.println(WiFi.localIP()); )


When on automatic mode The boiler room checks the outside temperature and the coolant temperature according to a schedule.
  • At temperatures below 14*C, the warm floor on the first floor is turned on.
  • At temperatures below 4*C, all circuits are turned on.
The coolant temperature is selected according to the table depending on the cross-section of the pipes and the outside temperature. When the required room temperature is reached, the boiler turns off. A certain hysteresis is applied to everything to smooth out transition values.

The security system works even simpler. There is a rule in the table that when the security system is turned on, if movement is detected at one of the PIR sensors, sending SMS through the API of one of the services.

Plans

  • creating an online version on a remote server and synchronizing changes for remote control.
  • Displaying data from GSM/GPS beacons in the car;
  • Opening the gate when our cars appear in a certain area;
  • Connection to the remote control system;
Voting by photo. What project should I do next?

A program for managing all Smart Home systems. Installed on Tablet PC on Windows, Android, iOS. Connects to the controller via Wi-Fi or the Internet (ModBus TCP communication protocol).
Works with almost any industrial controllers, including Beckhoff and ARIES.

Interface ( appearance) programs are completely changeable. Icons, backgrounds, arrangement of elements, inscriptions - everything is changed by the user or the installer. It is possible to create different interfaces for different devices. The number of devices on which the program can be installed within one controller is not limited.

EasyHome program functions:

  • control of lighting systems (including multi-colored LED strips and lamps with variable brightness)
  • climate control for each room
  • connection with security and fire alarm systems
  • connection with ventilation and air conditioning systems
  • control of power consumption in several phases with automatic shutdown of non-priority loads
  • control of sockets and other electrical appliances
  • installation on any number of devices, control via Wi-Fi or Internet
  • control and prevention of accidents: water leakage, gas leakage, electrical accidents
  • collection of information from water, gas and electricity meters
  • control by scenarios and presets
  • access to the controller via local network or via an external IP address (autoselect when starting the program)
  • displaying images from IP video cameras (in the Windows version, MJPEG and H264 video streams are supported, not all camera models)
  • ability to launch different interfaces (request when starting the program)

And much more!

Download EasyHome for iOS (iPhone and iPad):

To download the DEMO version of the application interface, enter the address in the add configuration window:

http://site/downloads/EH_DEMO.ehpa

New in EasyHome 7.9.5 for iOS:

  • Added convenient control of RGB LED strip with color selection
  • Improved element auto-scaling feature
  • Improved alarm message panel
  • Many minor improvements and fixes in the program

New in EasyHome 7.9.1 for iOS:

  • Loading configuration files through the program interface itself
  • Selecting a configuration at startup and quickly changing the interface
  • New RGB strip control
  • Auto-rotate screen function (convenient for iPhone)
  • Other minor improvements and fixes

How to use the DEMO version:

1. Download the archive

2. Unpack the archive to any location (for example, on your desktop)

3. Run the file EasyHomeEditor.exe

In the DEMO version you can do the following: change the interface, move elements, move between windows, etc. But since there is no connection with the controller, the icons will not change when pressed, and all values ​​(temperatures, currents, states) will be zero. To be able to connect to the controller, you must purchase a license (price information is at the bottom of this page).

New in EasyHome 7.8:

  • The ability for the controller to send arbitrary SMS messages in Russian for ARIES controllers (previously available only for Beckhoff)
  • Free functions have appeared. You can set any logic for the operation of inputs and outputs via the EasyHome interface. Previously, this was only available through a change in the controller code by our engineer.
  • Multi-scenes appeared
  • Added a convenient driver for working with infrared transmitters via the RS485 interface. 4 modes of controlling any air conditioners via IR commands.
  • Possibility of connecting an electrical network parameters meter to the OWEN controller for one or three phases.
  • You can connect up to 10 ARIES expansion modules in any combination, the total number of discrete inputs and outputs can now be up to 255.
  • An astronomical light sensor based on the height of the sun has appeared.
  • All sorts of minor improvements.

New in EasyHome 7.7 (December 2016):

  • Numerous interface improvements
  • Increased work speed by Windows systems 10 and iOS 9
  • It is now possible to shut off different water supply risers when different water leakage sensors are triggered
  • It is now possible to arm an arbitrary set of motion sensors
  • There is a function multi-interface- pre-boot graphical menu in which you can choose which interface to launch

What is the concept of a “smart” home? In any store household appliances You can see TVs with Smart TV, vacuum cleaners, split systems, etc. For convenient use of smart devices, developers offer special remote controls. These devices have both their advantages and disadvantages. Therefore, gadgets have recently appeared to convert Bluetooth signals from mobile devices on Android into a format understandable for household devices - IR decoders.

Following such gadgets in Google Play Android applications for home management began to appear. Here are the most popular Android applications that replace remote controls:

Remote Control for TV

Convenient virtual remote control for controlling your TV. There are no extra buttons; the basic set includes volume control and channel selection. Works in 3 modes: regular IR port, IR Blaster and general Wi-Fi network.

Pros of the program: three options for connecting to a TV; simple interface; support for many models of smart TV systems.

Smartphone Remote Control

This is a universal TV remote control with Smart TV function. The operating principle is similar to Remote Control for TV. There are basic keys for controlling volume and selecting TV channels. There is a set basic functions(switch to 3D mode, call the channel list and add to favorites). There is support for infrared or Wi-Fi network. Among the big advantages is the lack of payment for the application.

Pros: very clear interface; Wi-Fi and IR connection support, free application.

Universal Remote TV

Very similar to previous apps in terms of functionality. The only difference is a more convenient location on the virtual remote control, like on a regular remote control, so you get used to the interface faster. There is also support for infrared, Wi-Fi, and direct connection when entering an IP address.

Minuses: there are no obvious advantages.

Remote Control Pro

Universal remote remote control for a smartphone or tablet on Android. Again, there is support for control via a Wi-Fi network and an infrared port. Very simple operation, you can also directly establish contact via a local Wi-Fi network. The difference is the most convenient interface design, discreet colors and convenient button placement.

Pros of the application: Wi-Fi, infrared port for connection; convenient interface design.

Galaxy universal remote control

A universal remote control for all kinds of household appliances, but only with an infrared port. This application Works only with devices that support control via infrared rays. Knows the protocols of most TV models, DVD players, air conditioners, this is a huge advantage compared to other programs.

Setting up does not require any special skills. The only thing you need is to select the type and brand of gadget from the proposed list.

Pros: the ability to create presets; support not only for TV, but also for various home appliances; large list of supported brands.

Minuses: There is no demo version, the application is paid.

Here is a video that continues the topic of remote control and other programs for controlling a smart home:

Smart Home Control Using Android Smartphones

The concept of “Smart Home” has prepared a special place for mobile technologies. Until recently, this promising direction was not widely used; it was more considered exclusive. But now the situation has changed radically; it has become possible to control a Smart Home using smartphones or tablets that use the Android platform. This makes it possible to constantly have a mobile control device with you, which is designed to organize communication with the Internet, business records, calls and other functions. The open wireless protocol made it possible to control the house using a tablet with the Android operating system, as it has access to appliances and devices located in the house and connected to the power grid.

Separate attempts made earlier to equip Appliances automation, could not endow a house or apartment with intelligence. Now an ordinary smartphone or tablet can become universal remote control remote control, thanks to which you can both turn off and turn on the TV or coffee maker in the rooms. But the listed functions are not all the capabilities of the system. The presence of a mobile console is considered a ready-made platform for any applications that can not only keep correct records of the products in your refrigerator, but also effectively manage the consumption of electrical energy and heating, which will certainly affect the savings of the family budget. The smartphone itself with the Android platform is a link of communication between the owner and the “smart home”. Thanks to the level of mobile communications coverage, staying in touch with your apartment, even while at a great distance from it, will not be difficult.

Currently, special devices are being produced that allow the integration of various “smart” elements of the home. The control process itself occurs through an easy-to-understand interface using a smartphone or tablet. For this purpose, you can use not only a smartphone, but also the Android operating system console. A smart network can combine completely different groups of devices: ventilation, heating, water supply systems, as well as a control system for curtains, doors, electric lighting, etc. An application installed on the phone can reflect how much electricity is consumed in the house, the state of the security system, and the climate conditions in the house. It can recognize specific emergency situations in the house (gas or water leaks, fires, unauthorized persons entering the house) and send a signal in time - to the rescue service, police or email. Subject to precautions, communications can be carried out using an encrypted connection (the same as for financial transactions). This is done for the sole purpose of preventing unauthorized persons from connecting to the control of the house.

Quite recently, the new Android Home platform was released, the main purpose of which is to unite all devices of the smart home system. This operating system is being developed very intensively and already today provides great opportunities for decentralizing control of the smart home system using mobile devices based on Android OS.

Now it is possible to control the TV, satellite receiver, washing machine, dimmers in the house and lamps using any device based on the Android platform. These devices and subsystems are controlled via an Internet connection, which makes the mobile device a universal remote control that allows you to control processes in the house from anywhere in the world. In addition to managing systems in the home, the Android OS developer, the world-famous Google company, offers the integration of a multiroom system with entertainment services from Google. This makes it possible to distribute entertainment media content at a very high speed; users have the opportunity to enjoy their favorite music or watch a legendary movie directly from the Internet. Integration of these capabilities into a multiroom system makes it possible to use these services almost anywhere in the home.

The concept of building a “smart home” system based on the Android platform is designed to make it easier to manage the system by using any mobile device on an identical operating system. Speaking about analogues, Z-Wave or ZigBee, I would like to note that they are suitable for controlling a security system or climate control, but with decentralized control of entertainment systems of the operating system Android system There are no worthy competitors yet.

Publications on the topic