📜 ⬆️ ⬇️

Smart home software

Good day everyone. As a hobby, I wrote a program that can be used as part of the “smart home” system. In order to immediately interest the reader, I will demonstrate some small part of software use scenarios:

image

image
Turning on and off ZWave bulbs through a mobile application
image
When the device appears on the network (when the user comes home)
turning on the ZWave light, Modbus RTU relay module, starting the computer via WakeOnLan and turning on the TV
image
Launching the browser, switching to Yandex. Radio,
flipping tracks (hotkey emulation)

In short:

1. The main part of the software is a server that runs on Windows, written in C #;
2. Client on Android OS, written in Java;
3. Clients are planned for UWP and IOS, a web client.
')
Some features of the software:

1. Script Builder. Creation of complex scenarios with cycles and conditions;
2. Work with devices ZWave and Modbus;
3. Nesting scripts. You can use one script in another as a procedure;
4. Run a remote script. In the current server script, you can run a remote script;
5. The ability to add to the system its functionality through the creation of modules;
6. Run scripts using a smartphone.

Script Designer


The program allows you to create a complex scenario, as well as a single action.

A single action is a script that contains only one action. It is not possible to create cycles and conditions in it, but you can only “muzzle” a certain action on a button in the client's UI.

I will give my own way of using them as an example: I created the “Rosettes” category, in it I collected all the lamps, a household fan, lamps, a TV and a computer. Now, to enable one of these devices, open the client on the android, go to the “Rosettes” category and select the appropriate menu item.

Usually, it is inconvenient to use single actions, since various devices are conveniently run under some condition or at least not one by one. This is what the “complex scenario” is for, which is further discussed below.

The designer of a complex script allows you to create scripts with cycles and conditions. It has two modes: viewing and editing.
Sample Script in View Mode
Sample script in edit mode
image
image

IF and OTHERWISE in the constructor . In these constructions, you can create chains of conditions with the logical operators NOT, OR, I. The constructor allows you to create a group of conditions and use the operators directly with the group. If the condition is left empty, then it is automatically calculated as a lie.

There are a number of built-in checks (such as checking for date, time, etc.), as well as a number as plug-ins.

Cycle bye in the constructor . The cycle consists of a condition and a body. The condition is created in the same way as it is created in the IF design (groups of conditions, operators NOT, OR, AND).
Operator IF and possible conditions
Operator bye
image
image

image
The bodies IF, OTHERWISE and WHILE it is necessary to fill with something. Actually, this content is the most important thing in the script.

Main Script Designer Window
image

You can also configure the following script options:

- Run from the outside (on / off), allows you to prevent or allow the launch of the script from another machine or from the client;
- Automatic script launch at system startup;
- Select the category of the script, allows you to display in the client UI a menu item to run the script in a specific category.

Work with ZWave and Modbus devices


Currently, the system supports ZWave (based on openzwave) and Modbus RTU (based on nmodbus) devices.

ZWave is a wireless communication protocol used in home automation. To implement the protocol, miniature low-power radio frequency modules are used. Now on the ZWave market there is a rather extensive list of devices, such as ZWave light bulbs, sockets, relay modules, switches, locks, temperature sensors (humidity, movement, leakage), thermostats, air conditioning control devices, etc. Multi-sensors are also common - devices that combine several sensors (for example, a light sensor, presence, temperature, door sensor, etc.), which is very attractive in terms of financial costs and location in the room.

In my program, the ZWave module allows you to perform all standard operations with devices, such as deleting, adding devices, resetting the controller. You can also use multiple ZWave controllers, the end user will not see the difference. For example, you can read the temperature from the sensor, which is connected to the controller "A", and start the air conditioner using the controller "B". There are no restrictions, any action and verification are carried out in standard ways and are added to the script designer.
image
The market for ZWave devices is quite wide. There are many actuators, such as relay modules, light bulbs, devices for working with air conditioning, temperature controllers, floor heating regulators, sockets, switches. There are also many sensors: door opening sensor, temperature, leakage sensor, presence sensor, etc. You can use a USB stick as a ZWave controller.
image
The main window of the ZWave module
image
Controller selection and operations window
image
Node selection (sensors, switches, etc.)
image
Choice of node parameter (on / off, various numeric parameters such as temperature, humidity, etc.)

Modbus is a wired protocol used for communication between electronic devices that support it. In the context of our program, it can be useful for working with relay modules, for which I use it at home.
image
Modbus relay module. Connects to the controller via the COM port.
image
The main window of the Modbus RTU module

Scripting Nesting


Scripting nesting is used to decompose smart home scenarios. Often there are situations when one action is involved in many scenarios (for example, disconnecting all household devices can occur by clicking on the menu item in the program, by exiting all wi-fi devices from the network, just by timer), and therefore every time (or edit) the same algorithm in each of the scenarios does not seem convenient. For this there is a built-in action that allows you to run an already created script in the current one. It can also be convenient when new home appliances are often added (or other frequent changes in the “smart home” operation algorithm); to change the operation of all scenarios, it will be enough to change only one scenario that is used in them.
Action "Existing Script" in the list
Select an existing script
image
image

Run remote scripts


By running remote scripts, you can run a script from one server to another. As an example, I would like to cite my use of this functionality: I created a script (on a home server) called “light + multimedia”, which turns on the light in the room, starts my desktop (using WakeOnLan), turns on the TV to which the desktop is connected and waits On it (the desktop), an instance of our program will be launched, then it will launch “enable music” and “20 units sound” scripts on it by running remote scripts.
"Run remote script" listed
Choosing a server and its script
image
image

Writing your own modules


In addition to the fact that the user can create complex scripts with standard tools, the program allows you to “extend” it with custom modules in C #. All elements of actions and checks in scripts (such as “Check by date”, “Show message”, “Modbus action”, “ZWave action”, etc.) are classes inherited from ICustomAction and ICustomChecker. By following certain rules, any user can create his own module, which can be either very simple (for example, sounding the current air temperature outside the window) or complex, which can be covered by a whole framework. It is enough to inherit from the ICustomAction or ICustomChecker interfaces, arrange several attributes, compile the DLL and add to the program via the “MODULES” tab ( complete instructions for creating modules).
MODULES tab
image

Running Scripts with a Smartphone


* for now only Android OS

Scripts are displayed on the main screen and in categories. The category is a virtual “folder”. When the script is run, the status of the corresponding button is updated.
Connection Settings Screen
Script launch screen
image
image

In addition, it is possible to run scripts from the quick launch menu on the PC.
Quick Start Menu
image

In the future, a client is planned for UWP, IOS, web, as well as a voice module for managing devices (plans for the near future) and creating scenarios using voice (strategic plans).

Video at last:



» Program Page
» Download link
» Instructions for use
» Instructions for creating your own modules

PS: If you find an error in the program, then please send it to the mail .

Source: https://habr.com/ru/post/309070/


All Articles