Automation
Thank you for the time you spent reading my notes.
Since the last article (link passed almost a year. And for this year, I rethought some things, the Internet and it turned out something like IoT 🙂 -> Internet of things)
I will try to briefly outline a new portion of the accumulated knowledge, describe where I am striving and what I want to achieve -> I ask for reading.
Noolite F v2.0
In the title, the words pebble & Noolite. Let’s move on to them!
I still manage with pebble my noolite light, garage and gates. About noolite already written a lot of useful information, the search shows new articles.
In addition to the blocks of the first generation of the noolite system, I have new ones: the power unit SLF-1-200 (nooLite-F) with feedback (and encryption of a new generation)
power unit SB-1-150
and updated usb adapter MTRF-64 USB.
The whole world in my house on the noolite system.
Until recently, I had a noolite USB adapter of the first generation and 16 devices, and now 64 channels (MTRF-64 USB), also for next-generation devices with feedback (in the “system home crib”) Noolite F). Nootech moves in the right direction, creating a new modern device.
There are 2 most important options for new devices: feedback and the principle of device identification to addresses: ID. Now you do not need to write 1 device to 1 channel and manage the channel. Now you can access a specific device in one channel by its ID and send it a performance command.
The documentation for the new generation blocks is available on the manufacturer’s website.
# - * - coding: utf-8 - * -
#! / Usr / bin / env python
Import serial
Import time
Class NooLiteCommand:
Def __init __ (self, ch, cmd, mode = 0, ctr = 0, res = 0, fmt = 0, d0 = 0, d1 = 0, d2 = 0, d3 = 0, id0 = 0, id1 = 0, id2 = 0, id3 = 0):
Self.st = 171
Self.mode = mode
Self.ctr = ctr
Self.res = res
Self.ch = ch
Self.cmd = cmd
Self.fmt = fmt
Self.d0 = d0
Self.d1 = d1
Self.d2 = d2
Self.d3 = d3
Self.id0 = id0
Self.id1 = id1
Self.id2 = id2
Self.id3 = id3
Self.sp = 172
@property
Def crc (self):
Crc = sum ([
self.st,
self.mode,
self.ctr,
self.res,
self.ch,
self.cmd,
self.fmt,
self.d0,
self.d1,
self.d2,
self.d3,
self.id0,
self.id1,
self.id2,
self.id3,
])
Return crc if crc <256 else divmod (crc, 256) [1]
Def to_bytes (self):
Return bytearray ([
self.st,
self.mode,
self.ctr,
self.res,
self.ch,
self.cmd,
self.fmt,
self.d0,
self.d1,
self.d2,
self.d3,
self.id0,
self.id1,
self.id2,
self.id3,
self.crc,
self.sp
])
Class NooliteSerial:
Def __init __ (self, tty_name):
Self.tty = self._get_tty (tty_name)
Def on (self, ch):
Self.send_command (ch, 2, 2, 0)
Pass
Def off (self, ch):
Self.send_command (ch, 0, 2, 0)
Pass
Def status (self, ch):
M = self.send_command (ch, 128, 2, 0)
Pass
Def send_command (self, ch, cmd, mode = 0, ctr = 0, res = 0, fmt = 0, d0 = 0, d1 = 0, d2 = 0, d3 = 0, id0 = 0, id1 = 0, id2 = 0, id3 = 0):
Command = NooLiteCommand (ch, cmd, mode, ctr, res, fmt, d0, d1, d2, d3, id0, id1, id2, id3)
Self.tty.write (command.to_bytes ())
While True:
Bytes_response = list (self.tty.read (117))
If bytes_response:
All_responses.append (bytes_response)
If bytes_response [3] == 0:
Break
Else:
Break
Return all_responses
@staticmethod
Def _get_tty (tty_name):
Serial_port = serial.Serial (tty_name, timeout = 0.1)
If not serial_port.is_open:
Serial_port.open ()
Serial_port.flushInput ()
Serial_port.flushOutput ()
Return serial_port
Noo_serial = NooliteSerial ('/ dev / ttyUSB0')
#ch, cmd, mode, ctr
# Noo_serial.send_command (1, 15, 2, 0) #include the binding on channel 1
# Noo_serial.send_command (0, 4, 2, 0) #switch
# Noo_serial.send_command (0, 2, 2, 0) #turn on
# Noo_serial.send_command (0, 3, 2, 0) # Brightness adjustment up
# Noo_serial.send_command (0, 0, 2, 0) #turn off
# Noo_serial.send_command (0, 15, 2, 0) #include the binding
# Noo_serial.send_command (0, 128, 2, 0,0,1) #CMD_Read_State + fmt = 1
# Noo_serial.on (0)
# Noo_serial.status (0)
# Noo_serial.off (0)
# Noo_serial.off (0)
# Noo_serial.status (0)
# Noo_serial.send_command (ch = 0, ctr = 8, cmd = 4, id0 = 0, id1 = 0, id2 = 48, id3 = 114) #switch noolite ID 0.0.48.114
Using the right functions at the right time, we can manage noolite blocks and get the status from new ones. Since I have 99% old blocks, I still have to use the old scheme of recording 1 block in 1 channel, taking into account that the usb adapter supports both old blocks and new ones (thanks to the developers for compatibility without dancing with a tambourine). On the fly, you can manage and receive the status of new blocks and manage the old ones.
Until recently, there was not a single button switch in the house. I had to add a light to the garage (I just got there to put things in order: D), as well as a switch appeared in the illumination of the make-up mirror. Knowing that there is a power unit SB-1-150 I set the switch to the normal one and connected the unit. The backlight of the mirror was made of a white plate, 3w 4000 K lamps, white light. SB-1-150 is unique in that it can be placed in the box of the wall switch, (switch) in the section of the existing circuit and the connection of the push button to the unit itself.
Pebble
When I started to get involved in automation, one of the main factors was: competent and convenient management.
It’s kind of convenient to manage from a smartphone, but … and it’s not convenient, every time to load an application where small uncomfortable buttons, left-hand automation or until you reach the button … the desire disappears. Voice control disappears, as it is also uncomfortable and strange 🙂 – let it remain in the plots of fantastic films.
And I solved the problem differently – through wristwatches, which are CONTINUOUS with me, do not occupy space and combine all the comforts, mobility and speed of control. In general – Pebble alive! But the most important thing is that, for hours, you can still write applications – your applications, to manage your automation systems. This is generally a “bomb”.
The tragic closure of the company’s pebble.com (Fitbit bought out all pebble.com for patents) did not affect their performance and performance. Recently ios upgraded, automation – the clock was unleashed from the cloud services pebble (in case of termination of support) and authorization.
Visually – nothing has changed, but the service remained: cloudpebble.net – WTF? This is a very useful thing. If you can write code on JS (and you do not want to spend a lot of time on C ++) – please, welcome on board 🙂 – cloud pebble allows you to quickly “skip” the application. Well, that’s how I did it. Of course, the performance of JS should not be compared with C ++ (it’s sacred), be tolerant.
var UI = require ('ui');
Var ajax = require ('ajax');
Var noolite = [
['ворота','http://your-home-server-ip-address:1183/mqtt/gate/slidegate', 'images/gate.png'],
['гараж','http://your-home-server-ip-address:1183/mqtt/gate/garage', 'images/door.png'],
['приехали!','http://your-home-server-ip-address:1183/noolite/switch/103', 'images/light.png'],
['выкл все','http://your-home-server-ip-address:1183/noolite/switch/100', 'images/system2.png'],
['1 этаж свет','', 'images/light.png'],
['2 этаж свет','', 'images/light.png'],
['выкл 1эт','http://your-home-server-ip-address:1183/noolite/switch/101', 'images/light.png'],
['выкл 2эт','http://your-home-server-ip-address:1183/noolite/switch/102', 'images/light.png'],
['вода','', 'images/water.png'],
['мусорка','http://your-home-server-ip-address:1183/admin/system/1', 'images/system1.png'],
];
Var water = [
['сенди вода','http://your-home-server-ip-address:1183/admin/poliv/1', 'images/water.png'],
['баня вода','http://your-home-server-ip-address:1183/admin/poliv/2', 'images/water.png'],
['зона 1 фасад','http://your-home-server-ip-address:1183/noolite/switch/20', 'images/water.png'],
['зона 2 фасад','http://your-home-server-ip-address:1183/noolite/switch/21', 'images/water.png'],
['зона 3 фасад','http://your-home-server-ip-address:1183/noolite/switch/22', 'images/water.png'],
['зона 4 фасад','http://your-home-server-ip-address:1183/noolite/switch/23', 'images/water.png'],
['зона 5 зад','http://your-home-server-ip-address:1183/admin/poliv/switch/5', 'images/water.png'],
['зона 6 зад','http://your-home-server-ip-address:1183/admin/poliv/switch/6', 'images/water.png'],
['зона 7 зад','http://your-home-server-ip-address:1183/admin/poliv/switch/7', 'images/water.png'],
['зона 8 зад','http://your-home-server-ip-address:1183/admin/poliv/switch/8', 'images/water.png'],
['зона 9 зад','http://your-home-server-ip-address:1183/admin/poliv/switch/9', 'images/water.png'],
];
Var light1 = [
['коридор свет','http://your-home-server-ip-address:1183/noolite/switch/6', 'images/light.png'],
['кухня свет','http://your-home-server-ip-address:1183/noolite/switch/0', 'images/light.png'],
['кухня стол свет','http://your-home-server-ip-address:1183/noolite/switch/1', 'images/light.png'],
['зал низ свет','http://your-home-server-ip-address:1183/noolite/switch/7', 'images/light.png'],
['зал верх свет','http://your-home-server-ip-address:1183/noolite/switch/8', 'images/light.png'],
['ванная 1 свет','http://your-home-server-ip-address:1183/noolite/switch/2', 'images/light.png'],
['ванная 1 свет','http://your-home-server-ip-address:1183/noolite/switch/3', 'images/light.png'],
['гостевая 1 свет','http://your-home-server-ip-address:1183/noolite/switch/4', 'images/light.png'],
['топочная свет','http://your-home-server-ip-address:1183/noolite/switch/5', 'images/light.png'],
['гараж свет','http://your-home-server-ip-address:1183/noolite/switch/9', 'images/light.png'],
];
Var light2 = [
['спальня свет','http://your-home-server-ip-address:1183/noolite/switch/15', 'images/light.png'],
['гардероб свет','http://your-home-server-ip-address:1183/noolite/switch/16', 'images/light.png'],
['коридор 2 свет','http://your-home-server-ip-address:1183/noolite/switch/10', 'images/light.png'],
['ванная 2 свет','http://your-home-server-ip-address:1183/noolite/switch/11', 'images/light.png'],
['гостевая 2 свет','http://your-home-server-ip-address:1183/noolite/switch/12', 'images/light.png'],
['Алиса свет','http://your-home-server-ip-address:1183/noolite/switch/13', 'images/light.png'],
['Алиса картина свет','http://your-home-server-ip-address:1183/noolite/switch/14', 'images/light.png'],
];
Var menu = new UI.Menu ({
Sections: [{
items: [{
title: '',
subtitle: ''
}]
}]
});
Var menu1 = new UI.Menu ({
Sections: [{
items: [{
title: '',
subtitle: ''
}]
}]
});
Var menu2 = new UI.Menu ({
Sections: [{
items: [{
title: '',
subtitle: ''
}]
}]
});
Var menu3 = new UI.Menu ({
Sections: [{
items: [{
title: '',
subtitle: ''
}]
}]
});
Var items = [];
For (var i = 0; i <noolite.length; i ++) {
Items [i] = {
Title: noolite [i] [0],
Subtitle: '',
Icon: noolite [i] [2]
};
}
Var items1 = [];
For (var i = 0; i <light1.length; i ++) {
Items1 [i] = {
Title: light1 [i] [0],
Subtitle: '',
Icon: light1 [i] [2]
};};
}
Var items2 = [];
For (var i = 0; i <light2.length; i ++) {
Items2 [i] = {
Title: light2 [i] [0],
Subtitle: '',
Icon: light2 [i] [2]
};};
}
Var items3 = [];
For (var i = 0; i <water.length; i ++) {
Items3 [i] = {
Title: water [i] [0],
Subtitle: '',
Icon: water [i] [2]
};};
}
Menu.items (0, items);
Menu1.items (0, items1);
Menu2.items (0, items2);
Menu3.items (0, items3);
Menu.show ();
Menu.on ('select', function (e) {
If (e.itemIndex == 4) {
Menu1.show ();
}
Else if (e.itemIndex == 5) {
Menu2.show ();
}
Else if (e.itemIndex == 8) {
Menu3.show ();
}
Else {
Var url = noolite [e.itemIndex] [1];
Console.log (url);
Ajax ({
Url: url,
Method: 'get'
}
Function (data) {
Console.log ('switched OK');
},
Function (error) {
// Failure!
Console.log ('error');
}
);
}
});
Menu1.on ('select', function (e) {
Var url = light1 [e.itemIndex] [1];
Console.log (url);
Ajax ({
Url: url,
Method: 'get'
},
Function (data) {
Console.log ('switched OK');
},
Function (error) {
// Failure!
Console.log ('error');
}
);
});
Menu2.on ('select', function (e) {
Var url = light2 [e.itemIndex] [1];
Console.log (url);
Ajax ({
Url: url,
Method: 'get'
},
Function (data) {
Console.log ('switched OK');
},
Function (error) {
// Failure!
Console.log ('error');
}
);
});
Menu3.on ('select', function (e) {
Var url = water [e.itemIndex] [1];
Ajax ({
Url: url,
Method: 'get'
},
Function (data) {
Console.log ('switched OK');
},
Function (error) {
// Failure!
Console.log ('error');
}
);
});
The code is written, compiled directly on the cloud Pebble site and through the phone, downloading the compiled application can be installed on the clock - in seconds. Everything is so simple that any young automator can cope;)
It’s a pity … that it’s a pity that Pebble ceased to exist and I do not see an alternative at the moment. Pebble Time will always be in our hearts!
MQTT
Last year I met such a wonderful protocol as MQTT (History: The first version of the protocol was developed by Dr. Andy Stanford-Clark (IBM) and Arlen Nipper (Arcom) in 1999 and published under a royalty-free license.The specification of MQTT 3.1.1 was standardized by the OASIS consortium in 2014. reference)
There is a lot of information about how the protocol works and what customers are … and was strong Disappointed that the real clients for mobile applications – no, only on android.
Understanding that the lack of a good mobile application is a very big problem in the IoT area (very many people say, but they do very little ….) – I decided to create a client with my team, at work For android, ios, wp, so that it met all the criteria and was convenient. I’ll write about the client a little later, as well as the way we made friends with ESP8266 + MTRF64 (Noolite) and prepared the Nodemcu firmware. It will be great, convenient, cheap and beautiful! Follow the news here.
[1945907] image “/>
You can now control Noolite lighting without any home servers and usb adapters for $ 50-100!
The general scheme of work of home automation
Still exists the following scheme:
– Video surveillance: xeoma video surveillance [ip камеры]
Server on the system unit: nginx + gunicorn + python + mqtt broker
Management: Pebble watch + MQTT client
Control modules (system nodes): ESP8266 + optocouplers sensors ds18b20, dht11 [22]
– In view of the fact that I saw in the MQTT protocol a lot of convenience, from the subscription architecture and instant communication with the end IoT devices, to the fact that MQTT messages can fly through the router, without “throwing” all the ports there and dancing with a tambourine. Conveniently! Fun!
All this led me to the decentralization of the system, that is, leaving one “home korchvagen” and switching to many so-called nodes and using the cloud MQTT broker (there are free MQTT brokers, for example: mqtt.ximxim. Com (on the site login and pass for access)) – because esp8266 solve all tasks, and it in turn works through wifi using the MQTT protocol.
Given that MQTT Buddy will provide scripting services, I generally will not think that I need to write any home scripts, I’ll just create them in a cloud solution and this will be a real IoT and it working! From words to deeds!
ESP8266
When I got acquainted with this development board, I was immediately impressed by the fact that the board is small, there is support for the programming language LUA on Nodemcu. What you need + MQTT module is. In automation, simple and reliable solutions are the automation. The cost from 2 $ to 5 $ for a fee (for 5 model at once with usb adapter on board) allows you to quickly deploy the subsystems.
Connection over WiFi fast, mass possibilities. For example: gate management garage irrigation lighting. I have 30% watering lawns running from the Noolite system (dry contact blocks), the remaining 70% from the esp8266 development board with LUA language control over MQTT protocol.
- load credentials
Dofile ("credentials.lua")
Function init (name, pass)
Wifi.setmode (wifi.STATION)
Wifi.sta.config (name, pass)
Wifi.sta.connect ()
Tmr.alarm (0, 1000, 1, function ()
If wifi.sta.getip () == nil then
Print ("IP unavaiable, Waiting ...")
Else
Tmr.stop (0)
Print ("Configured, IP is" ..wifi.sta.getip ())
Print ("mac:" ..wifi.sta.getmac ())
Dofile ("mqtt.lua")
End
End)
End
Print ("START!")
Init (SSID, PASSWORD)
– mqtt.lua file
Local door = 7 - gpio13
Local window = 6 - gpio12
Local cooler = 5 - gpio14
Local led = 4 --GPIO2 board led! LOW == turn ON
Local light1 = 8 - gpio 15
Local light2 = 1 - gpio 5
Local light3 = 2 - gpio 4
Function register_myself ()
M: subscribe ("mqtt_buddy / #", 0, function (conn)
Print ("subscribed to Xim mqtt.ximxim.com server")
End)
End
M = mqtt.Client ("MQTT_BUDDY_SHOW_ROOM", 120, MQTT_USER, MQTT_PASS)
M: on ("connect", function (client) print ("connected to Xim mqtt.ximxim.com server") end)
M: on ("offline", function (client) reconnect_mqtt () end)
M: on ("message", function (client, topic, data)
--print (topic .. "data:" .. data)
If topic == "mqtt_buddy / window" and data == "1" then
Print "open-close window ..."
Gpio.write (window, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Tmr.alarm (1, 1000, tmr.ALARM_SINGLE, function ()
Gpio.write (window, gpio.LOW)
Gpio.write (led, gpio.HIGH)
Print "command to close open window is sent!"
End)
Elseif topic == "mqtt_buddy / door" and data == "1" then
Print "open-close door ..."
Gpio.write (door, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Tmr.alarm (2, 1000, tmr.ALARM_SINGLE, function ()
Gpio.write (door, gpio.LOW)
Gpio.write (led, gpio.high)
Print "command to close open door is sent!"
End)
Elseif topic == "mqtt_buddy / cooler" then
If data == "1" then
Print "switch on fan ..."
Gpio.write (cooler, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Else
Print "switch off fan ..."
Gpio.write (cooler, gpio.LOW)
Gpio.write (led, gpio.HIGH)
End
Elseif topic == "mqtt_buddy / light1" then
If data == "1" then
Print "switch light1 ON ..."
Gpio.write (light1, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Else
Print "switch light1 off ..."
Gpio.write (light1, gpio.LOW)
Gpio.write (led, gpio.HIGH)
End
Elseif topic == "mqtt_buddy / light2" then
If data == "1" then
Print "switch light2 ON ..."
Gpio.write (light2, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Else
Print "switch light2 off ..."
Gpio.write (light2, gpio.LOW)
Gpio.write (led, gpio.HIGH)
End
Elseif topic == "mqtt_buddy / light3" then
If data == "1" then
Print "switch light3 ON ..."
Gpio.write (light3, gpio.HIGH)
Gpio.write (led, gpio.LOW)
Else
Print "switch light3 off ..."
Gpio.write (light3, gpio.LOW)
Gpio.write (led, gpio.HIGH)
End
End
End)
M: connect (MQTT_SERVER, MQTT_SERVER_PORT, 0, function (conn) register_myself () end)
Problem
Turning to the huge community [thinking people] I wanted to touch a very important topic, or rather the problem I want to solve, but There is not enough time for deeper research / knowledge.
The bottom line: with decentralization, there remains video surveillance, which somehow REQUIRES the host machine to (at least) transfer source images to either video surveillance servers (for example ivideon) or even process video on a home machine like xeoma (although They also have a cloud) – one way or another – you need to “TRY” the video streams, pictures for the ultimate processing power (cloud solutions) – or vice versa – to make streaming simple.
There are thoughts of getting source images from the camera (here too there is a problem, not every camera has a URL to get a picture from the camera and it’s not at all clear how others will recognize this URL ….) and cast to the MQTT channel, Where binary data is supported (that is, the picture can be easily transferred via mqtt protocol in binary form).
Perhaps someone already tried to implement such things = ESP8266 + IP web cam?
Please respond (bogdanovich.alex [@] gmail.com). I would be very grateful!
When implementing the skip, the question of the home server disappears. What for? Because he eats electricity and fires me:)
All the positive day and good mood!
I like EDM bands! I really do! And my favourite EDM band is The Cheinsmokers! DJs Alex Pall and Andrew Taggart are about to give more than 50 concerts to their fans in 2019 and 2020!
Carrie Underwood is my favourite US singer. She is young, beautiful and charming woman in her 30s. Her strong voice takes me away from all troubles of this world so I start enjoy my life and listen songs created by her voice. Now she is on a Cry Pretty 360 Tour started in May of 2019. The concerts scheduled for this year, up to the last day of October. Ticket prices are moderate and available for all men and women with different income. If you love contry music, then you must visit at least one of her concert.