{"id":285414,"date":"2017-04-24T11:25:03","date_gmt":"2017-04-24T07:25:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=285414"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=285414","title":{"rendered":"\u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 SDM-220 \u0432 OpenHab"},"content":{"rendered":"<p>\u041f\u0440\u043e\u0448\u0435\u043b \u043f\u043e\u0447\u0442\u0438 \u0433\u043e\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0435\u0439 <a href=\"https:\/\/geektimes.ru\/post\/277358\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a> \u043e\u0431 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0435 \u0441 RS485\/ModBus \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <b>SDM-220<\/b>, \u0437\u0430\u0442\u0435\u043c \u0431\u044b\u043b\u0430 <a href=\"https:\/\/habrahabr.ru\/post\/309580\/\">\u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441 \u043d\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443. \u042d\u0442\u043e \u0442\u0440\u0435\u0442\u044c\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f. \u041e\u043d\u0430 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441 <a href=\"https:\/\/www.openhab.org\/\">OpenHab<\/a>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/47d\/b1b\/9a8\/47db1b9a82544d269fa610d403687edb.png\"\/><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418\u0442\u0430\u043a, \u043f\u0435\u0440\u0432\u0430\u044f \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0441\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u043f\u0440\u0435\u0434\u043f\u0440\u0438\u043d\u0438\u043c\u0430\u043b\u0430\u0441\u044c \u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0432\u043d\u0435\u0448\u043d\u0435\u0433\u043e \u043e\u0431\u043b\u0430\u0447\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0438\u0441\u0430 <a href=\"https:\/\/thingspeak.com\/\">ThingSpeak<\/a>. \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u0442 \u0441\u0447\u0435\u0442\u0447\u0438\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043d\u043a\u0438\u0439 \u043a\u043b\u0438\u0435\u043d\u0442 (\u043c\u0438\u043d\u0438-\u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440) \u0441 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u044b\u043c \u043d\u0430 \u0444\u043b\u0435\u0448\u043a\u0443 <b>Ubuntu Server<\/b>. \u042d\u0442\u043e \u0431\u044b\u043b\u0430 \u043f\u0435\u0440\u0432\u0430\u044f \u043e\u0448\u0438\u0431\u043a\u0430 \u2014 \u0444\u043b\u0435\u0448\u043a\u0430 \u00ab\u0443\u043c\u0435\u0440\u043b\u0430\u00bb \u0447\u0435\u0440\u0435\u0437 3 \u043c\u0435\u0441\u044f\u0446\u0430 (\u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e\u0441\u0442\u044c, \u043f\u043e\u0434\u0443\u043c\u0430\u043b \u044f). \u041d\u0435 \u0441\u0434\u0435\u043b\u0430\u0432 \u043d\u0438\u043a\u0430\u043a\u0438\u0445 \u0432\u044b\u0432\u043e\u0434\u043e\u0432, \u0432\u0442\u043e\u0440\u0443\u044e \u0444\u043b\u0435\u0448\u043a\u0443 \u044f \u0443\u0431\u0438\u043b \u0437\u0430 2 \u043c\u0435\u0441\u044f\u0446\u0430 (\u0437\u0430\u043a\u043e\u043d\u043e\u043c\u0435\u0440\u043d\u043e\u0441\u0442\u044c). \u0412 \u0442\u0440\u0435\u0442\u044c\u0435\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0445\u0440\u0430\u043d\u0438\u043b\u0438\u0449\u0430 \u0443\u0436\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f usb-\u043a\u0430\u0440\u043c\u0430\u043d \u0441 \u0432\u0438\u043d\u0442\u043e\u043c 2,5&quot;.<\/p>\n<p>  \u0421\u0430\u043c \u0441\u0435\u0440\u0432\u0438\u0441 ThingSpeak \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u0443\u044e \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0443, \u043d\u043e \u043d\u0435 \u0434\u0430\u0435\u0442 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e\u0439 \u0433\u0438\u0431\u043a\u043e\u0441\u0442\u0438 \u0441 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u043c\u0438. \u0414\u0430\u043d\u043d\u044b\u0435 \u0437\u0430 \u0441\u0443\u0442\u043a\u0438, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0431\u0438\u0440\u0430\u043b\u0438\u0441\u044c \u043a\u0430\u043a \u0441\u0443\u043c\u043c\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 \u043f\u043e \u0447\u0430\u0441\u0430\u043c. \u0415\u0441\u043b\u0438 \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u043f\u0430\u043a\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440 \u043d\u0435 \u043f\u043e\u0441\u0442\u0443\u043f\u0438\u043b \u0438\u043b\u0438 \u044f \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u043b \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u0434\u0430\u043d\u043d\u044b\u0445 \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f, \u043f\u043e\u044f\u0432\u043b\u044f\u043b\u0430\u0441\u044c \u043e\u0448\u0438\u0431\u043a\u0430. \u041c\u044b\u0441\u043b\u0438 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u043f\u0440\u0438\u0434\u0435\u0442\u0441\u044f \u0432\u0435\u0441\u0442\u0438 \u0434\u0432\u0443\u0445\u0442\u0430\u0440\u0438\u0444\u043d\u044b\u0439 \u0443\u0447\u0435\u0442 \u0441 \u043f\u0440\u0438\u0432\u044f\u0437\u043a\u043e\u0439 \u043f\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0441\u0443\u0442\u043e\u043a, \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u043c\u0430 \u043d\u0435 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u043b\u0438.<\/p>\n<p>  \u0412 \u043e\u0431\u0449\u0435\u043c, \u0440\u0435\u0448\u0438\u043b \u044f \u043e\u0441\u0432\u0430\u0438\u0432\u0430\u0442\u044c <b>OpenHab<\/b>.<\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 \u043f\u0435\u0440\u0432\u0430\u044f: \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u044b\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043e \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430.<\/h3>\n<p>  \u0423\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0430 \u0441\u0430\u043c\u043e\u0433\u043e OpenHab \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u0438\u0437\u043b\u043e\u0436\u0435\u043d\u0430 \u0432 <a href=\"http:\/\/docs.openhab.org\/installation\/linux.html\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438<\/a>. \u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u043d\u0443\u0436\u043d\u043e \u0447\u0435\u0440\u0435\u0437 \u043f\u0430\u043d\u0435\u043b\u044c <b>Paper UI -&gt; Bindings<\/b> \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c <b>ModBus binding<\/b> \u2014 <i>binding-modbus1 \u2014 1.9.0<\/i><\/p>\n<p>  \u041e\u043f\u0440\u043e\u0441 \u0448\u0438\u043d\u044b Mod\u0412us \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442 \u0447\u0435\u0440\u0435\u0437 USB-RS485 \u0430\u0434\u0430\u043f\u0442\u0435\u0440, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f, \u0447\u0442\u043e \u0430\u0434\u0430\u043f\u0442\u0435\u0440 \u0435\u0441\u0442\u044c \u0432 \u0441\u0438\u0441\u0442\u0435\u043c\u0435, \u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044e openhab \u043f\u0440\u0430\u0432\u0430 \u043d\u0430 \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043f\u043e\u0440\u0442\u0443:  <\/p>\n<pre><code class=\"bash\">lsusb Bus 002 Device 002: ID 0403:6001 Future Technology Devices International, Ltd FT232 Serial (UART) IC  ls \/dev\/ttyUSB* \/dev\/ttyUSB0  sudo adduser openhab dialout sudo adduser openhab tty <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0440\u0435\u043a\u043e\u043c\u0435\u043d\u0434\u0443\u0435\u0442\u0441\u044f \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u0434\u043b\u044f Java (\u043e\u0431 \u044d\u0442\u043e\u043c \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u0432 \u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0438 \u043f\u043e \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0435 OpenHab):  <\/p>\n<pre><code class=\"bash\">sudo vi \/etc\/default\/openhab2  EXTRA_JAVA_OPTS=&quot;-Dgnu.io.rxtx.SerialPorts=\/dev\/ttyUSB0&quot; <\/code><\/pre>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u0438\u0445 \u043c\u0430\u043d\u0438\u043f\u0443\u043b\u044f\u0446\u0438\u0439 \u043d\u0443\u0436\u043d\u043e \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u043e\u043d\u0444\u0438\u0433\u0443\u0440\u0430\u0446\u0438\u043e\u043d\u043d\u044b\u0439 \u0444\u0430\u0439\u043b <b>services\/modbus.cfg<\/b>:  <\/p>\n<pre><code> sudo vi  \/etc\/openhab2\/services\/modbus.cfg  #\u041f\u0435\u0440\u0438\u043e\u0434 \u043e\u043f\u0440\u043e\u0441\u0430 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 poll=30000  #\u0421\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u0432\u044b\u0447\u0438\u0442\u0430\u0442\u044c \u0432\u0441\u0435 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u044b \u0437\u0430 \u043e\u0434\u043d\u043e \u043e\u0431\u0440\u0430\u0449\u0435\u043d\u0438\u0435, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430. \u041f\u043e\u043b\u0435 start - \u043d\u043e\u043c\u0435\u0440 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430. \u0412 \u0441\u0442\u0440\u043e\u043a\u0435 connection \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043d\u043e\u043c\u0435\u0440 \u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043f\u043e\u0440\u0442\u0430 (9600,8,n,1), \u0437\u0430\u0434\u0435\u0440\u0436\u043a\u0443 \u043f\u0435\u0440\u0435\u0434 \u0447\u0442\u0435\u043d\u0438\u0435\u043c \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430 \u0438 \u0442\u0430\u0439\u043c\u0430\u0443\u0442 \u043e\u0442\u0432\u0435\u0442\u0430.  #\u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435 - 0x00 serial.slave1.connection=\/dev\/ttyUSB0:9600:8:none:1:rtu:2000:1000:none:none serial.slave1.type=input serial.slave1.start=0 serial.slave1.length=2 serial.slave1.valuetype=float32  #\u0442\u043e\u043a - 0x06 serial.slave2.connection=\/dev\/ttyUSB0:9600:8:none:1:rtu:2000:1000:none:none serial.slave2.type=input serial.slave2.start=6 serial.slave2.length=2 serial.slave2.valuetype=float32  #\u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u044c - 0x0C serial.slave3.connection=\/dev\/ttyUSB0:9600:8:none:1:rtu:2000:1000:none:none serial.slave3.type=input serial.slave3.start=12 serial.slave3.length=2 serial.slave3.valuetype=float32  #\u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 (\u0430\u043a\u0442\u0438\u0432\u043d\u0430\u044f \u044d\u043d\u0435\u0440\u0433\u0438\u044f) - 0x156 serial.slave4.connection=\/dev\/ttyUSB0:9600:8:none:1:rtu:2000:1000:none:none serial.slave4.type=input serial.slave4.start=342 serial.slave4.length=2 serial.slave4.valuetype=float32 <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u043d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u0444\u0430\u0439\u043b\u0435 <b>items\/sdm220.items<\/b>:  <\/p>\n<pre><code>sudo vi \/etc\/openhab2\/items\/sdm220.items  #\u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0433\u0440\u0443\u043f\u043f\u0443 \u0434\u043b\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 Group gSDM220  #\u0438 \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c, \u043e\u0442\u043a\u0443\u0434\u0430 \u0438\u0445 \u0431\u0440\u0430\u0442\u044c \u0438 \u043a\u0430\u043a \u0432\u044b\u0432\u043e\u0434\u0438\u0442\u044c, energy - \u044d\u0442\u043e \u0438\u043c\u044f \u0438\u043a\u043e\u043d\u043a\u0438 \u0438\u0437 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0433\u043e \u043d\u0430\u0431\u043e\u0440\u0430 Number sdm220_voltage  &quot;\u041d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u0435  [%.1f \u0412]&quot; &lt;energy&gt; (gSDM220) {modbus=&quot;slave1:0&quot;} Number sdm220_current  &quot;\u0422\u043e\u043a  [%.2f \u0410]&quot; &lt;energy&gt; (gSDM220) {modbus=&quot;slave2:0&quot;} Number sdm220_actpower  &quot;\u041c\u043e\u0449\u043d\u043e\u0441\u0442\u044c  [%.1f \u0412\u0442]&quot; &lt;energy&gt; (gSDM220) {modbus=&quot;slave3:0&quot;} Number sdm220_actcounter  &quot;\u0421\u0447\u0435\u0442\u0447\u0438\u043a \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u044d\u043d\u0435\u0440\u0433\u0438\u0438  [%.1f \u043a\u0412\u0442*\u0447]&quot; &lt;energy&gt; (gSDM220) {modbus=&quot;slave4:0&quot;} <\/code><\/pre>\n<p>  \u041e\u0441\u0442\u0430\u043b\u043e\u0441\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u043d\u0430 dashboard. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0439\u043b <b>sitemaps\/default.sitemap<\/b>:  <\/p>\n<pre><code>sudo vi \/etc\/openhab2\/sitemaps\/default.sitemap   sitemap default label=&quot;alk0v SmartHome (default sitemap)&quot; {     Frame label=&quot;\u042d\u043b\u0435\u043a\u0442\u0440\u043e\u0441\u0447\u0435\u0442\u0447\u0438\u043a&quot; {         Text item=sdm220_voltage         Text item=sdm220_current         Text item=sdm220_actpower         Text item=sdm220_actcounter     } } <\/code><\/pre>\n<p>  \u0412 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0435, \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u0443\u0432\u0438\u0434\u0435\u0442\u044c \u0442\u0435\u043a\u0443\u0449\u0438\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/2b5\/2df\/18b\/2b52df18bc8e4f5aa2bfdf7e55b56e09.png\"\/><\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 \u0432\u0442\u043e\u0440\u0430\u044f: \u043d\u0430\u0441\u0442\u0440\u043e\u0439\u043a\u0430 HabPanel \u0438 \u0432\u0438\u0437\u0443\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u0439<\/h3>\n<p>  OpenHab \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u043d\u0435\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043f\u0430\u043d\u0435\u043b\u0435\u0439 \u0443\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u0438\u044f. \u041c\u043d\u0435 \u0432\u043d\u0435\u0448\u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u043f\u043e\u043d\u0440\u0430\u0432\u0438\u043b\u0430\u0441\u044c <b>HabPanel<\/b>. \u0427\u0435\u0440\u0435\u0437 <b>Paper UI -&gt; User Interfaces<\/b> \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c <b>HabPanel<\/b> \u2014 <i>ui-habpanel \u2014 2.0.0<\/i>. <\/p>\n<p>  \u0414\u043b\u044f \u043e\u0442\u0440\u0438\u0441\u043e\u0432\u043a\u0438 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u0442\u0430\u043a\u0436\u0435 \u043d\u0443\u0436\u043d\u043e \u0433\u0434\u0435-\u0442\u043e \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435. OpenHab \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0442\u0435\u0440\u043c\u0438\u043d <b>Persistence <\/b>\u0434\u043b\u044f \u0431\u0430\u0437 \u0434\u0430\u043d\u043d\u044b\u0445. \u041c\u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 MySQL, \u0432 community \u043e\u0431\u0441\u0443\u0436\u0434\u0430\u043b\u0438 \u043c\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0431\u043b\u0435\u043c \u0441 \u044d\u0442\u043e\u0439 \u0431\u0430\u0437\u043e\u0439, \u0432 \u0438\u0442\u043e\u0433\u0435 \u044f \u043d\u0430\u0448\u0435\u043b <a href=\"https:\/\/community.openhab.org\/t\/openhab2-mysql-persistence-setup\/15829\">\u0438\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e<\/a>, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u0437\u0430\u0440\u0430\u0431\u043e\u0442\u0430\u043b\u0430 \u0438 \u0443 \u043c\u0435\u043d\u044f. <\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c MySQL Persistence (persistence-mysql \u2014 1.9.0).<\/p>\n<p>  \u0423\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c MySQL  <\/p>\n<pre><code>sudo apt-get install mysql-server sudo mysql -u root -p<\/code><\/pre>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u0431\u0430\u0437\u0443  <\/p>\n<pre><code class=\"sql\">CREATE DATABASE OpenHAB; CREATE USER 'openhab'@'localhost' IDENTIFIED BY 'YOURPASSWORD'; GRANT ALL PRIVILEGES ON OpenHAB.* TO 'openhab'@'localhost'; quit<\/code><\/pre>\n<p>  \u0420\u0435\u0441\u0442\u0430\u0440\u0442\u0443\u0435\u043c openhab  <\/p>\n<pre><code>sudo service openhab2 stop sudo service openhab2 start<\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043c <b>services\/mysql.cfg<\/b>:  <\/p>\n<pre><code># the database url like 'jdbc:mysql:\/\/&lt;host&gt;:&lt;port&gt;\/&lt;database&gt;' (without quotes) url=jdbc:mysql:\/\/localhost:3306\/openhab  # the database user user=openhab  # the database password password=YOURPASSWORD<\/code><\/pre>\n<p>  \u041f\u0440\u0430\u0432\u0438\u043c <b>persistence\/mysql.persist<\/b>. \u041f\u043e \u0443\u043c\u043e\u043b\u0447\u0430\u043d\u0438\u044e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u0445 Items \u0431\u0443\u0434\u0443\u0442 \u0437\u0430\u043d\u043e\u0441\u0438\u0442\u044c\u0441\u044f \u0432 \u0431\u0430\u0437\u0443 \u043f\u0440\u0438 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u0438:  <\/p>\n<pre><code>Strategies {         \/\/ if no strategy is specified for an item entry below, the default list will be used         everyMinute     : &quot;0 * * * * ?&quot;         every5Minutes : &quot;0 *\/5 * * * ?&quot;         everyHour   : &quot;0 0 * * * ?&quot;         everyDay    : &quot;0 0 0 * * ?&quot;         default = everyChange }  Items {     \/\/ persist all items once a day and on every change and restore them from the db at startup     * : strategy = default, restoreOnStartup } <\/code><\/pre>\n<p>\u0415\u0441\u043b\u0438 \u0432\u0441\u0451 \u043d\u0430\u0441\u0442\u0440\u043e\u0435\u043d\u043e \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u043e, \u0432 \u0431\u0430\u0437\u0435 \u0434\u043e\u043b\u0436\u043d\u0430 \u043f\u043e\u044f\u0432\u0438\u0442\u044c\u0441\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 Items \u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b ItemXX \u0434\u043b\u044f \u043a\u0430\u0436\u0434\u043e\u0433\u043e Item.  <\/p>\n<pre><code class=\"sql\"> mysql&gt; use openhab; Database changed  mysql&gt; show tables; +-------------------+ | Tables_in_openhab | +-------------------+ | Item1             | | Item2             | | Item3             | | Item4             | | Items             | +-------------------+ 5 rows in set (0.00 sec)  mysql&gt; select * from Items; +--------+--------------------------+ | ItemId | ItemName                 | +--------+--------------------------+ |      1 | sdm220_voltage           | |      2 | sdm220_actpower          | |      3 | sdm220_actcounter        | |      4 | sdm220_current           | +--------+--------------------------+ 4 rows in set (0.00 sec) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u043c\u043e\u0436\u043d\u043e \u043d\u0430\u0432\u043e\u0434\u0438\u0442\u044c \u043a\u0440\u0430\u0441\u043e\u0442\u0443 \u0432 HabPanel.<\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Dashboard, \u043d\u0430 \u043d\u0435\u0433\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u044b\u0435 \u0432\u0438\u0434\u0436\u0435\u0442\u044b. \u0414\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432\u0438\u0434\u0436\u0435\u0442 <b>Dummy<\/b>, \u0434\u043b\u044f \u0432\u044b\u0432\u043e\u0434\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u043e\u0432 \u2014 <b>Chart<\/b>. \u0422\u0443\u0442 \u0432\u0441\u0451 \u0438\u043d\u0442\u0443\u0438\u0442\u0438\u0432\u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u043e. \u041f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u043c\u043e\u0449\u043d\u043e\u0441\u0442\u0438 \u0438 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u044f \u044f \u0432\u044b\u0432\u0435\u043b \u043d\u0430 \u043e\u0434\u0438\u043d \u0433\u0440\u0430\u0444\u0438\u043a, \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0448\u043a\u0430\u043b\u044b Y.<\/p>\n<p>  \u0423\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u0438\u0441\u0442\u043e\u0447\u043d\u0438\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 mysql:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/68b\/2ca\/963\/68b2ca963f91446fa5d2ab96c1b186d5.png\"\/><\/p>\n<p>  \u041d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0440\u043e\u0433\u0438 \u0434\u043b\u044f \u043e\u0441\u0438 \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u044f:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/21b\/8cc\/e7e\/21b8cce7e47f4b7090d5315fe795ac29.png\"\/><\/p>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c Items, \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u0434\u043b\u044f \u043d\u0438\u0445 \u0446\u0432\u0435\u0442 \u0438 \u0442\u0438\u043f \u043b\u0438\u043d\u0438\u0438, \u0434\u043b\u044f \u043d\u0430\u043f\u0440\u044f\u0436\u0435\u043d\u0438\u044f \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u043c \u043e\u0441\u044c Secondary:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/28d\/3d1\/0e5\/28d3d10e515347a59044c272d2e671ed.png\"\/><\/p>\n<p>  \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \ud83d\ude42<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/065\/852\/5e5\/0658525e52384e3b8b23c1e5597807b0.png\"\/><\/p>\n<h3>\u0417\u0430\u0434\u0430\u0447\u0430 \u0442\u0440\u0435\u0442\u044c\u044f: \u043f\u043e\u0447\u0430\u0441\u043e\u0432\u044b\u0439 \u0438 \u043f\u043e\u0441\u0443\u0442\u043e\u0447\u043d\u044b\u0439 \u0443\u0447\u0435\u0442 \u0437\u0430\u0442\u0440\u0430\u0447\u0435\u043d\u043d\u043e\u0439 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u044d\u043d\u0435\u0440\u0433\u0438\u0438<\/h3>\n<p>  \u041e\u0442\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u044f \u0432\u043e \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u2014 \u044d\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e, \u043d\u043e \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0435\u0449\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u0437\u0430 \u0447\u0430\u0441, \u0441\u0443\u0442\u043a\u0438, \u043c\u0435\u0441\u044f\u0446. \u0422\u043e \u0435\u0441\u0442\u044c \u0437\u0430\u0434\u0430\u0447\u0430 \u2014 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0438\u0437\u0432\u043e\u0434\u0438\u0442\u044c \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u044f. \u0422\u0443\u0442 \u043d\u0430 \u043f\u043e\u043c\u043e\u0449\u044c \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u043f\u0440\u0430\u0432\u0438\u043b \u0432 OpenHab. <\/p>\n<p>  \u0418\u0442\u0430\u043a, \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u043c <b>Rules<\/b>.<\/p>\n<p>  \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u043e\u0432\u044b\u0435 Items \u0432 <b>items\/sdm220.items<\/b>:  <\/p>\n<pre><code>Number sdm220_hourcounter (gSDM220) Number sdm220_daycounter (gSDM220) <\/code><\/pre>\n<p>  \u0417\u0430\u0442\u0435\u043c \u0441\u043e\u0437\u0434\u0430\u0435\u043c \u0444\u0430\u0439\u043b <b>rules\/energy.rules<\/b>, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u043d\u0443\u0436\u043d\u043e \u0443\u043a\u0430\u0437\u0430\u0442\u044c 2 \u043f\u0440\u0430\u0432\u0438\u043b\u0430: \u043e\u0434\u043d\u043e \u0431\u0443\u0434\u0435\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u044c\u0441\u044f \u0440\u0430\u0437 \u0432 \u0447\u0430\u0441, \u0432\u0442\u043e\u0440\u043e\u0435 \u2014 \u0440\u0430\u0437 \u0432 \u0441\u0443\u0442\u043a\u0438.  <\/p>\n<pre><code>rule &quot;Energy by hour&quot; when         Time cron &quot;0 0 * * * ?&quot; then \/\/\u0432\u044b\u0447\u0438\u0441\u043b\u0435\u043d\u0438\u0435 \u0440\u0430\u0441\u0445\u043e\u0434\u0430. \u0418\u0437 \u0442\u0435\u043a\u0443\u0449\u0438\u0445 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u0439 \u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0430 \u0432\u044b\u0447\u0438\u0442\u0430\u044e\u0442\u0441\u044f \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0438\u0437 \u0431\u0430\u0437\u044b \u043d\u0430 \u0447\u0430\u0441 \u0440\u0430\u043d\u044c\u0448\u0435            var hour = sdm220_actcounter.state as DecimalType - sdm220_actcounter.historicState(now.minusHours(1), &quot;mysql&quot;:).state as DecimalType \/\/\u0432\u044b\u0432\u043e\u0434 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043b\u043e\u0433 \u0434\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438         logInfo(&quot;TEST&quot;,&quot;sdm220_hourcounter = &quot;+hour) \/\/\u043f\u0440\u0438\u0441\u0432\u0430\u0438\u0432\u0430\u0435\u043c \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 Item         postUpdate(sdm220_hourcounter, hour) end  rule &quot;Energy by day&quot; when         Time cron &quot;0 0 0 * * ?&quot; then         var day = sdm220_actcounter.state as DecimalType - sdm220_actcounter.historicState(now.minusDays(1), &quot;mysql&quot;:).state as DecimalType         postUpdate(sdm220_daycounter, day) <\/code><\/pre>\n<p>  \u0414\u043b\u044f \u043e\u0442\u043b\u0430\u0434\u043a\u0438 \u043c\u043e\u0436\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u043e\u043b\u044c OpenHab. \u0421\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u044b\u0435 \u043b\u043e\u0433\u0438\u043d \u0438 \u043f\u0430\u0440\u043e\u043b\u044c: openhab\/habopen. \u041f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c\u0441\u044f \u043a \u043d\u0435\u0439 \u043c\u043e\u0436\u043d\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439:  <\/p>\n<pre><code>ssh -p 8101 openhab@localhost openhab&gt; log:tail  19:22:00.012 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_hourcounter_day = 0.526123046875 19:22:00.014 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_daycounter = 10.861083984375 19:22:09.462 [INFO ] [marthome.event.ItemStateChangedEvent] - sdm220_current changed from 16.0433025360107421875 to 5.69449329376220703125 19:22:11.500 [INFO ] [marthome.event.ItemStateChangedEvent] - sdm220_actcounter changed from 2387.51904296875 to 2387.5458984375 19:22:13.532 [INFO ] [marthome.event.ItemStateChangedEvent] - sdm220_voltage changed from 192.7679595947265625 to 200.4195098876953125 19:22:15.568 [INFO ] [marthome.event.ItemStateChangedEvent] - sdm220_actpower changed from 2271.8486328125 to 1132.8717041015625 19:23:00.014 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_hourcounter_day = 0.515869140625 19:23:00.015 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_daycounter = 10.8769531250 <\/code><\/pre>\n<p>  \u0418\u043b\u0438 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0442\u044c \u0444\u0430\u0439\u043b \u043b\u043e\u0433\u0430:  <\/p>\n<pre><code>tail -f \/var\/log\/openhab2\/openhab.log 2017-04-18 19:17:45.587 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'energy.rules' 2017-04-18 19:18:00.259 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_hourcounter_day = 0.571044921875 2017-04-18 19:18:00.272 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_daycounter = 10.8330078125 2017-04-18 19:19:00.015 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_daycounter = 10.83789062500 2017-04-18 19:19:00.025 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_hourcounter_day = 0.557861328125 2017-04-18 19:20:00.013 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_hourcounter_day = 0.55517578125 2017-04-18 19:20:00.024 [INFO ] [.eclipse.smarthome.model.script.TEST] - sdm220_daycounter = 10.859130859375 <\/code><\/pre>\n<p>  \u042f \u043f\u043b\u0430\u043d\u0438\u0440\u0443\u044e \u043c\u0435\u043d\u044f\u0442\u044c \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u0441\u0447\u0435\u0442\u0447\u0438\u043a \u043d\u0430 \u0434\u0432\u0443\u0445\u0442\u0430\u0440\u0438\u0444\u043d\u044b\u0439, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u044d\u043d\u0435\u0440\u0433\u0438\u044f, \u043f\u043e\u0442\u0440\u0435\u0431\u043b\u044f\u0435\u043c\u0430\u044f \u0432 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u0435 \u0441 23:00 \u0434\u043e 07:00, \u043e\u043f\u043b\u0430\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u0441 \u043a\u043e\u044d\u0444\u0444\u0438\u0446\u0438\u0435\u043d\u0442\u043e\u043c 0.5, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0431\u044b \u0432\u0438\u0434\u0435\u0442\u044c \u043e\u0436\u0438\u0434\u0430\u0435\u043c\u044b\u0439 \u044d\u0444\u0444\u0435\u043a\u0442 \u0438 \u0432\u0435\u0441\u0442\u0438 \u0434\u0432\u0443\u0445\u0442\u0430\u0440\u0438\u0444\u043d\u044b\u0439 \u0443\u0447\u0435\u0442. \u0421\u043d\u0430\u0447\u0430\u043b\u0430 \u044f \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u0438\u043b \u0432 Items \u0438 Rules \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0443\u0441\u043b\u043e\u0432\u0438\u044f \u0434\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u0438 \u0441\u043a\u043b\u0430\u0434\u044b\u0432\u0430\u043b \u0434\u043d\u0435\u0432\u043d\u044b\u0435 \u0438 \u043d\u043e\u0447\u043d\u044b\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u0438\u044f \u0432 \u0434\u0432\u0435 \u0440\u0430\u0437\u043d\u044b\u0445 \u0442\u0430\u0431\u043b\u0438\u0446\u044b. \u0412 \u0431\u0430\u0437\u0435 \u0432\u0441\u0451 \u0431\u044b\u043b\u043e \u043a\u0440\u0430\u0441\u0438\u0432\u043e, \u0430 \u0432\u043e\u0442 \u043d\u0430 \u0433\u0440\u0430\u0444\u0438\u043a\u0435 \u0432\u044b\u0433\u043b\u044f\u0434\u0435\u043b\u043e \u043a\u043e\u0440\u044f\u0432\u043e, \u0442\u0430\u043a \u043a\u0430\u043a \u0433\u0440\u0430\u0444\u0438\u043a \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u043b \u0434\u0432\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0438\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u043f\u0440\u044f\u043c\u043e\u0439 \u043b\u0438\u043d\u0438\u0435\u0439:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0a5\/3dc\/e24\/0a53dce24ebd402f98823161a333f479.png\"\/><\/p>\n<p>  \u0427\u0442\u043e\u0431\u044b \u043f\u043e\u0442\u0435\u0448\u0438\u0442\u044c \u0441\u0432\u043e\u0435 \u0447\u0443\u0432\u0441\u0442\u0432\u043e \u043f\u0440\u0435\u043a\u0440\u0430\u0441\u043d\u043e\u0433\u043e, \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0437\u0430\u043c\u043e\u0440\u043e\u0447\u0438\u0442\u044c\u0441\u044f.<\/p>\n<p>  \u0418\u0442\u0430\u043a, \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 Rules \u0434\u043b\u044f \u0434\u0432\u0443\u0445\u0442\u0430\u0440\u0438\u0444\u043d\u043e\u0433\u043e \u0443\u0447\u0435\u0442\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:  <\/p>\n<pre><code>rule &quot;Energy by hour&quot; when         Time cron &quot;0 0 * * * ?&quot; then         var hour = sdm220_actcounter.state as DecimalType - sdm220_actcounter.historicState(now.minusHours(1), &quot;mysql&quot;:).state as DecimalType \/\/\u043e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u044b \u0432\u0440\u0435\u043c\u0435\u043d\u0438         if(now.getHourOfDay &gt; 7 && now.getHourOfDay &lt; 23)         {                 logInfo(&quot;TEST&quot;,&quot;sdm220_hourcounter_day = &quot;+hour)                 postUpdate(sdm220_hourcounter_day, hour)         }         else         { \/\/\u043d\u0430 \u0433\u0440\u0430\u043d\u0438\u0446\u0435 \u0434\u0438\u0430\u043f\u0430\u0437\u043e\u043d\u043e\u0432 \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u0443\u043b\u0435\u0432\u044b\u0435 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f \u0432 \u0433\u0440\u0430\u0444\u0438\u043a \/\/\u0442\u0430\u043a \u043a\u0430\u043a \u0432 \u0442\u0430\u0431\u043b\u0438\u0446\u0435 \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 primary key \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f timestamp, \u043c\u0435\u0436\u0434\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 \u043e\u0434\u043d\u0443 \u0438 \u0442\u0443 \u0436\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u0443 \u0441\u0442\u043e\u0438\u0442 \u043f\u0430\u0443\u0437\u0430 \u0432 \u043e\u0434\u043d\u0443 \u0441\u0435\u043a\u0443\u043d\u0434\u0443                 if(now.getHourOfDay==7)                 {                         postUpdate(sdm220_hourcounter_night, hour)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_night, 0)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_day, 0)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_day, hour)                 }                 else if(now.getHourOfDay==23)                 {                         postUpdate(sdm220_hourcounter_day, hour)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_day,0)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_night, 0)                         Thread::sleep(1000)                         postUpdate(sdm220_hourcounter_night, hour)                 }                 else                 {                         postUpdate(sdm220_hourcounter_night, hour)                 }         }         postUpdate(sdm220_hourcounter, hour) end  rule &quot;Energy by day&quot; when         Time cron &quot;0 0 0 * * ?&quot; then         var day = sdm220_actcounter.state as DecimalType - sdm220_actcounter.historicState(now.minusDays(1), &quot;mysql&quot;:).state as DecimalType         \/\/night counter, 00:00..07:00 + 23:00..00:00         var day2 = sdm220_actcounter.historicState(now.minusHours(17),&quot;mysql&quot;:).state as DecimalType - sdm220_actcounter.historicState(now.minusDays(1), &quot;mysql&quot;:).state as DecimalType + sdm220_actcounter.state as DecimalType - sdm220_actcounter.historicState(now.minusHours(1),&quot;mysql&quot;:).state as DecimalType         \/\/day counter, 07:00..23:00         var day1 = sdm220_actcounter.historicState(now.minusHours(1),&quot;mysql&quot;:).state as DecimalType - sdm220_actcounter.historicState(now.minusHours(17),&quot;mysql&quot;:).state as DecimalType         logInfo(&quot;TEST&quot;,&quot;sdm220_daycounter_day = &quot;+day1)         logInfo(&quot;TEST&quot;,&quot;sdm220_daycounter_night = &quot;+day2)         logInfo(&quot;TEST&quot;,&quot;sdm220_daycounter = &quot;+day)         postUpdate(sdm220_daycounter, day)         postUpdate(sdm220_daycounter_day, day1)         postUpdate(sdm220_daycounter_night, day2) end <\/code><\/pre>\n<p>  \u041f\u0435\u0440\u0435\u0434 \u0440\u0435\u0434\u0430\u043a\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u043a\u0440\u0438\u043f\u0442\u0430 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043d\u0443\u0436\u043d\u044b\u0435 Items:  <\/p>\n<pre><code>Number sdm220_hourcounter_day (gSDM220) Number sdm220_hourcounter_night (gSDM220) Number sdm220_daycounter_day (gSDM220) Number sdm220_daycounter_night (gSDM220) <\/code><\/pre>\n<p>  \u0422\u0435\u043f\u0435\u0440\u044c \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u043e\u0447\u0430\u0441\u043e\u0432\u043e\u0433\u043e \u0438 \u043f\u043e\u0441\u0443\u0442\u043e\u0447\u043d\u043e\u0433\u043e \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u0442\u0430\u043a:<br \/>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/0fc\/e9c\/c0c\/0fce9cc0c4cd43fbbf7ac36745309426.png\"\/><\/p>\n<p>  \u041d\u0430 \u044d\u0442\u043e\u043c, \u043f\u043e\u0436\u0430\u043b\u0443\u0439, \u0432\u0441\u0435. \u0412 \u043f\u043b\u0430\u043d\u0430\u0445 \u0435\u0449\u0435 \u0434\u043e\u0431\u0430\u0432\u0438\u0442\u044c \u043f\u043e\u0434\u0441\u0447\u0435\u0442 \u0440\u0430\u0441\u0445\u043e\u0434\u0430 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u044d\u043d\u0435\u0440\u0433\u0438\u0438 \u0438 \u0434\u0435\u043d\u0435\u0433 \u0437\u0430 \u043c\u0435\u0441\u044f\u0446 \u043f\u043e \u0434\u043d\u0435\u0432\u043d\u043e\u043c\u0443 \u0438 \u043d\u043e\u0447\u043d\u043e\u043c\u0443 \u0442\u0430\u0440\u0438\u0444\u0443 \u0438 \u0433\u0435\u043d\u0435\u0440\u0430\u0446\u0438\u044e \u043e\u0442\u0447\u0435\u0442\u0430 \u0441 \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u043e\u0439 \u043d\u0430 \u043f\u043e\u0447\u0442\u0443.<br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/geektimes.ru\/post\/288206\/\"> https:\/\/geektimes.ru\/post\/288206\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u041f\u0440\u043e\u0448\u0435\u043b \u043f\u043e\u0447\u0442\u0438 \u0433\u043e\u0434 \u0441 \u043c\u043e\u043c\u0435\u043d\u0442\u0430 \u043c\u043e\u0435\u0439 <a href=\"https:\/\/geektimes.ru\/post\/277358\/\">\u043f\u0435\u0440\u0432\u043e\u0439 \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438<\/a> \u043e\u0431 \u044d\u043b\u0435\u043a\u0442\u0440\u043e\u0441\u0447\u0435\u0442\u0447\u0438\u043a\u0435 \u0441 RS485\/ModBus \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u043e\u043c <b>SDM-220<\/b>, \u0437\u0430\u0442\u0435\u043c \u0431\u044b\u043b\u0430 <a href=\"https:\/\/habrahabr.ru\/post\/309580\/\">\u0432\u0442\u043e\u0440\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f<\/a> \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0441\u043e\u0431\u0438\u0440\u0430\u0442\u044c \u0441 \u043d\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443. \u042d\u0442\u043e \u0442\u0440\u0435\u0442\u044c\u044f, \u043d\u0430\u0434\u0435\u044e\u0441\u044c, \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f. \u041e\u043d\u0430 \u043e \u0442\u043e\u043c, \u043a\u0430\u043a \u0438\u043d\u0442\u0435\u0433\u0440\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0447\u0435\u0442\u0447\u0438\u043a \u0441 <a href=\"https:\/\/www.openhab.org\/\">OpenHab<\/a>. \u0420\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043d\u0430\u043a\u043e\u043d\u0435\u0446-\u0442\u043e \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0443\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442. <\/p>\n<p>  <img decoding=\"async\" src=\"https:\/\/habrastorage.org\/files\/47d\/b1b\/9a8\/47db1b9a82544d269fa610d403687edb.png\"\/>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-285414","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285414","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=285414"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/285414\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=285414"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=285414"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=285414"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}