"Gray, blow, cool ...", or the logic of climate control in a smart home

Smart House

Recently, the subject of a smart home is gaining more and more popularity, there are more and more new articles, reviews, discussions, and almost any question you can immediately find a few opinions and answers. But in this whole world of information there is still one white area, namely the logic of work. We were not afraid and decided to submit to the public our preparations on this issue.

First, a few words about the object to be equipped with automation systems. This is a small apartment building, each apartment of which is equipped with independent air conditioning systems, ventilation, heating and underfloor heating.

As the main requirements, the customer noted: a single interface for managing all smart home systems, a limited budget and a minimum amount of additional wiring. After a little research of the market of automation systems, we settled on a solution from Fibaro, since the main advantages of this solution almost perfectly repeat our conditions.

In this article, we describe the process of creating a similarity of an HVAC system for an apartment based on the Z-Wave protocol. We hope to receive a bunch of comments from the community to bring our decision to an edible state. If the expected result is achieved, we will be happy to continue this cycle with other publications in which we will share our experience in using Z-Wave devices.

So, we will describe the initial data and conditions of functioning of our system.

First of all, we wondered what would manage all the systems. As the head unit, we stopped at the Home Center 2 controller. Initially, it was planned to create a network of five controllers and organize the system so that one controller controls all the apartments on the same floor of the building. But it soon became clear that building the system in such a way would not work, as HC2 has a limit on the number of connected z-wave devices, and combining controllers into one network only expands the coverage of the z-wave network, but does not increase the maximum allowable number of connected devices . At the same time, no more than 230 devices can be connected to one controller. Accordingly, only five hundred devices can still be connected to five controllers integrated into a single network. Therefore, we had to double the number of controllers in the project and refuse to merge them into a single network. Now one HC2 will work on 4-5 apartments, which gives us the opportunity to use from 46 to 57 z-wave devices in each apartment.

After we decided on the main controller, the question arose of what data should be collected, and how to do it. To control the climate, it is necessary to know the current state of affairs in the apartment, namely: the temperature inside and outside the room, humidity, CO2 level, the position of windows and doors, the presence of residents. As the project budget is limited, we refused to monitor humidity and CO2 levels.

To monitor indoor temperature, many z-wave devices contain built-in temperature sensors that complement the basic functionality of the device. And, of course, there are temperature sensors in a separate version. According to our project, in each apartment there will be about 35 devices that will somehow show the temperature value. These are three leakage sensors FIB_FGFS-101, three IR converters REM_ZXT120, thermostat RS 014G0160, motion sensors, and three temperature sensors DS 18B20 for each heated floor contour and the heating system circuit. Monitoring the temperature of the warm floor contour is necessary first of all in order to prevent the parquet from overheating, since The maximum allowable parquet temperature does not exceed 27 degrees.

Temperature control to protect the parquet from overheating


Temperature control to protect the parquet from overheating.

Since all these temperature values ​​can be quite different from each other, depending on where the device is installed, to determine the temperature in the room we will calculate the average value for all indicators from this room.

To determine the temperature outside the room, there are two options. In HC2, there is a function for receiving a weather forecast for a city, which is set when the controller was initially set up. However, this method of determining the temperature does not differ with acceptable accuracy, so for this purpose we will use several DS 18B20 sensors installed on the external facade of the building. It should be noted that the sensors should not be located directly on the facade and avoid direct sunlight.

In any smart home, one of the main goals of its creation is to reduce the cost of heating and cooling rooms, so understanding the current position of windows and doors becomes very important. In order to turn off heating and air conditioning, if a window or door is open, we will use conventional magnetic-contact sensors, and for their integration into the z-wave network they will be connected to universal binary sensors FIB_FGBS-001.

Connection of temperature sensors DS18B20

Connecting temperature sensors DS18B20

To determine the presence of tenants, we created a virtual device that represents a button. When you click on this button, the user informs the system that no one is at home.

Virtual device - home / work buttons


Virtual device - home / work enable buttons

When the system receives a signal that no one is at home, the controller turns off all HVAC systems and goes into power saving mode until the user gets home. Being in the energy saving mode, the system continues to monitor the temperature, and will not allow overcooling of the premises and the temperature to drop below 18 degrees.

Another important element of climate control in a residential area is the temperature setpoint. In our solution, users can change it in two ways. Using a wall thermostat or using a specially created virtual device using a smartphone or tablet.

Having dealt with monitoring the current state of the microclimate in the apartment, we proceeded to study directly the devices that we were to manage.

Each apartment will be equipped with 3 air conditioners manufactured by Mitsubishi Electric. They are planned to be controlled with the help of REM_ZXT120 IR converters. These devices have predefined settings for controlling the most common models of air conditioners from leading manufacturers, as well as the possibility of teaching IR to commands from the remote control.

In addition to air conditioning, each apartment will be equipped with an independent system of supply and exhaust ventilation, and its management will be organized using two-channel relays FIB_FGS-222.

Also, in all the apartments there will be installed seven contours of the heated floor and one central heating circuit. Each circuit is equipped with a three-way valve with servo. It is controlled by the RGBW module FIB_FGRGB-101.

After selecting and studying all the necessary equipment, our next task was to develop the most efficient and self-sufficient climate control algorithm.

Clickable:

Flowchart with apartment climate control algorithm

The flowchart shows the algorithm, which is the main logic of the entire HVAC control system.

The resulting algorithm is implemented as one master script and several supporting ones. In NS2, these scripts are called scenes and are written in lua.
In order not to heavily load the controller, the scenes are launched only when the so-called triggers are triggered.

For the main scene, the following events are triggers:

  • one of the temperature indicators will change by more than one degree
  • user has changed the setpoint temperature
  • user turned on / off mode at work
  • window or door (on the loggia or entrance) were open / closed

Main Script Code
--[[
%% properties
3 Temperature   --температура за окном
85 value		--датчик температуры 1
86 value		--датчик температуры 2
87 value		--датчик температуры 3
%% events
%% globals
tempSet
--]]local temp1 = tonumber(fibaro:getValue(85, "value")) -- датчик температуры 1local temp2 = tonumber(fibaro:getValue(86, "value"))-- датчик температуры 2local temp3 = tonumber(fibaro:getValue(87, "value"))-- датчик температуры 3local tempOUT = tonumber(fibaro:getValue(3, "Temperature"))-- датчик температуры за окномlocal IDCooler = 99-- вентиляцияlocal IDCond = 100-- кондиционерlocal IDCondHeat = 102-- кондиционер обогрев (для тестирования)local IDFloor = 23-- теплый полlocal IDHeat = 24-- радиаторlocal tempset = fibaro:getGlobalValue("tempSet")
local workmode = fibaro:getGlobalValue("Workmode")
local tempInside = (temp1 + temp2 + temp3) / 3localdate = os.date("!*t", now)
local currtime = date.hour*60 + date.min--текущее время в минутахlocal d = tempset - tempInside
local w = tempset - tempOUT
--globals:  --	Workmode--	TempSet-- 	WinStatus--	Isventnow--	CHeatinglocal cHeating = "on"local winStatus = "closed"print("Starting Climate Control")
print("t в помещении = "..tempInside..",  t целевая = "..tempset)
print("Workmode: "..workmode..",  Windows: "..winStatus,",  Central Heating: "..cHeating)
--режим на работе включенif (fibaro:getGlobalValue("Workmode1") == "At work") 
then--если прохладноif (tempInside < 18) 
    then--включить подогревif (cHeating == "on")
    	then-- включить радиаторыprint("включить радиаторы")
      		fibaro:call(IDHeat, "turnOn")
      		if(Isventnow == "no")
        	then
      			fibaro:call(IDCooler, "turnOff")
      		end
            fibaro:call(IDCondHeat, "turnOff")
      		fibaro:call(IDCond, "turnOff")
      		fibaro:call(IDFloor, "turnOff")
      	elseif (windows == "closed")
      	then-- включить кондиционер наобогревprint("включить обогрев кондиционера")
      		fibaro:call(IDCondHeat, "turnOn")
      		fibaro:call(IDCond, "turnOn")
      		fibaro:call(IDFloor, "turnOff")
     		if(Isventnow == "no")
        	then
      			fibaro:call(IDCooler, "turnOff")
      		end      
      		fibaro:call(IDHeat, "turnOff")
      	end--если жарко и радиаторы включеныelseif (tempInside > 21)
    then--выключить радиаторыif(fibaro:getValue(IDHeat, value) >0)
		thenprint("выключить радиаторы")
    		fibaro:call(IDHeat, "turnOff")
		else
        	fibaro:call(IDCondHeat, "turnOn")
      		fibaro:call(IDCond, "turnOn")
      		fibaro:call(IDFloor, "turnOff")
            if(Isventnow == "no")
        	then
      			fibaro:call(IDCooler, "turnOff")
      		endendend-- если достигли нужной температурыelseif d < 1and d > -1thenprint("выключаем всё")
    --выключить кондиционер
	fibaro:call(IDCondHeat, "turnOff")
    fibaro:call(IDCond, "turnOff")
	--выключить вентиляциюif(Isventnow == "no")
    then
		fibaro:call(IDCooler, "turnOff")
    end--выключить радиаторы
	fibaro:call(IDHeat, "turnOff")
	--выключить теплый пол
	fibaro:call(IDFloor, "turnOff")
-- если включено центральное отоплениеelseif (cHeating == "on")
then--включено центральное отоплениеif (d >= 1)
    then--обогревif (d <= 3)
        thenprint("включить теплый пол")
            --включить теплый пол
            fibaro:call(IDFloor, "turnOn")		
            fibaro:call(IDCondHeat, "turnOff")
            fibaro:call(IDCond, "turnOff")
            fibaro:call(IDHeat, "turnOff")
            fibaro:call(IDCooler, "turnOff")
        elseif (d > 3)
        thenprint("включить теплый пол и радиаторы")
			--включить теплый пол
    		fibaro:call(IDFloor, "turnOn")
            --включить радиаторы
    		fibaro:call(IDHeat, "turnOn")
			fibaro:call(IDCondHeat, "turnOff")
      		fibaro:call(IDCond, "turnOff")
      	    if(Isventnow == "no")
    		then
				fibaro:call(IDCooler, "turnOff")
    		endendelseif (d <= -1)
    then--охлаждениеprint("включить вентиляцию")
        -- включить вентиляциюif(Isventnow == "no")
   	 	then
			fibaro:call(IDCooler, "turnOn")
    	end
        lastCondition = currTime
    end--если выключено центральное отоплениеelseif (cHeating == "off")
then--обогревif (d >= 1)
    thenif (w <= 0)
        thenprint("включить вентиляцию")
            -- включить вентиляциюif(Isventnow == "no")
      		then
				fibaro:call(IDCooler, "turnOn")
    		end
    		fibaro:call(IDCondHeat, "turnOff")    
			lastCondition = currTime
        elseif (d < 4)
        thenprint("включить вентиляцию")
			-- включить вентиляцию
    		fibaro:call(IDCondHeat, "turnOff")
      		if(Isventnow == "no")
    		then
				fibaro:call(IDCooler, "turnOn")
    		end
        	lastCondition = currTime
        elseif (winStatus == "closed")
        thenprint("включить кондиционер на обогрев")
			-- включить кондиционер на обогрев
    		fibaro:call(IDCondHeat, "turnOn")
      		fibaro:call(IDCond, "turnOn")    
      		if(Isventnow == "no")
    		then
				fibaro:call(IDCooler, "turnOff")
    		endendelseif (d <= -1)
    then--охлаждениеif(w >= 0)
		thenif(d > -4)
	    	thenprint("включить вентиляцию")
	        	-- включить вентиляциюif(Isventnow == "no")
                then
                    fibaro:call(IDCooler, "turnOn")
                end
    			fibaro:call(IDCondHeat, "turnOff")
      			fibaro:call(IDCond, "turnOff")
	    	elseif (winStatus == "closed")
        	thenprint("включить кондиционер")
	        	-- включить кондиционер
      			fibaro:call(IDCond, "turnOn")
      			fibaro:call(IDCondHeat, "turnOff")
                if(Isventnow == "no")
                then
                    fibaro:call(IDCooler, "turnOff")
                endendelseif (winStatus == "closed")
      	thenprint("включить кондиционер")
	    	-- включить кондиционер
   			fibaro:call(IDCond, "turnOn")
      		fibaro:call(IDCondHeat, "turnOff")    
            if(Isventnow == "no")
            then
                fibaro:call(IDCooler, "turnOff")
            endendendend


As can be seen from the code of the main scene, she uses global variables in her work:

  • Workmode {"at work", "at home"} // mode at work
  • TempSet // setpoint temperature
  • WinStatus {'opened "," closed "} // whether windows and doors to the loggia are open (needed to limit the operation of air conditioners)
  • CHeating {"on", "off"} // whether central heating is on

Monitoring of the current position of the windows and doors in the apartment will be carried out by an auxiliary stage. The result of its work is stored in the global variable WinStatus. Also, a separate scene controls the temperature change of the sensors near the central heating pumps in the basement of the building and determines whether central heating is turned on. The result of its work is stored in the global variable CHeating.

Since it is very important for comfort that the air in the apartment is fresh, we decided that it would be right to make a system of forced ventilation of rooms through the supply and exhaust ventilation. If the ventilation has not worked during the last three hours, the scenario of airing the room for 15 minutes will automatically start. Forced ventilation is not carried out if the “at work” mode is activated.

Forced Airing Script
functionvent_forced()local workmode = fibaro:getGlobal('Workmode')
local isventnow = fibaro:getGlobal('Isventnow')
local lastModified = fibaro:getGlobalModificationTime('Isventnow')
  if ((os.time() - lastModified) < 10800) thenprint ("время с последнего проветривания в секундах  "..(os.time() - lastModified))
    	print ("с последнего проветривания прошло меньше 3-х часов")
  endif ( workmode == 'At home'and isventnow == 'no'and (os.time() - lastModified) > 10800 ) thenprint ("время с последнего проветривания в секундах  "..(os.time() - lastModified))
    		fibaro:call(99, "turnOn")
		fibaro:setGlobal('Isventnow', 'yes')
 		print ("с последнего проветривания прошло больше 3 часов")
		print ("принудительное проветривание помещения включено")
    		fibaro:sleep(900000)
		fibaro:call(99, "turnOff")
    		fibaro:setGlobal('Isventnow', 'no')
		print ("принудительное проветривание помещения выключено")
	endendlocal sourceTrigger = fibaro:getSourceTrigger()
	if (sourceTrigger["type"] == "autostart") thenwhiletruedo
       		fibaro:debug('Сцена запущена автоматически')
        		local currentDate = os.date("*t")
			if (currentDate.min >= 0and currentDate.min <= 60) then
          		vent_forced()
          		end
		fibaro:debug('Сцена отработала, следующий запуск через 1 час')
  		fibaro:sleep(3600*1000)
        endend


That's how we plan to solve the problem. There are still many issues on the agenda, many problems to be solved and many difficulties to overcome. This is our first attempt at writing, we ask you to treat with kindness and understanding.

Also popular now: