📜 ⬆️ ⬇️

As I intercom Vizit connected to mqtt

Good time to everyone. The first of January, there is nothing to do, so I decided to roll an article on Giktayms. In connection with the move to another apartment there was such an option as an intercom. Everything would be fine, but running and opening the door to everyone who came was very annoying, and since phones, tablets, computers are always within walking distance, only reach out, it was decided to connect this benefit to the already running iobroker automation system. Below I will describe what happened with this.

Assembled in haste from what was lying under my feet was available. As a result, the whole thing looks like this.

image

Since I already have a wonderful iobroker automation system, it was decided to connect to it in order to be able to centrally control and configure changes in behavior in a single interface. It is time to choose how the hardware and the total system will communicate. What just did not occur to me as an exchange protocol from 1wire emulation to get requests, the mqtt protocol eventually won as the most convenient in my vision of the situation, and the exchange between the piece of iron and iobroker is implemented.
')
On the tablet, it looks like a tab with the display of the current camera and control

image

Part one is iron. It consists of arduino uno, ethernet shields, and a small matching circuit with the intercom line. The scheme itself:

image

Everything is simple, the incoming call is monitored by the incoming call, and upon admission it simply presses the arduino's zero leg. Opening the door is implemented on the relay in the normal state is always closed, when a command from iobroker is received (a button is pressed in the interface, automatically according to the condition in the script, a command from the telegrams arrived) breaks the line for 7.5 seconds, while the vizit takes it as a command to open and starts the guest .

Additionally, on the optocounter vo2, the TV automatically switches to AV mode for display from the doorphone camera.

Part two is software, which is also essentially divided into two. The first is a sketch that is stitched in arduino and implements the exchange via the mqtt protocol with the iobroker system.

#include <SPI.h> #include <Ethernet.h> #include <PubSubClient.h> int flag = 0; #define ring1_pin 0 //   1 #define open1_pin 2 //  1 #define open2_pin 3 //  2 #define mon1_pin 5 //    #define ID_CONNECT "DoorbellControll" byte mac[] = { 0xDE, 0xED, 0xBA, 0xFE, 0xFE, 0xED }; byte server[] = { 192, 168, 55, 170 }; byte ip[] = { 192, 168, 55, 40 }; EthernetClient ethClient; PubSubClient client(server, 1883, callback, ethClient); void callback(char* topic, byte* payload, unsigned int length) { payload[length] = '\0'; String strTopic = String(topic); String strPayload = String((char*)payload); if (strTopic == "myhome/DoorbellControll/open1") { if (strPayload == "false") { digitalWrite(2, HIGH); } else if (strPayload == "true") { digitalWrite(2, LOW); } } else if (strTopic == "myhome/DoorbellControll/open2") { if (strPayload == "false") digitalWrite(3, LOW); else if (strPayload == "true") digitalWrite(3, HIGH); } else if (strTopic == "myhome/DoorbellControll/mon1") { if (strPayload == "false") digitalWrite(5, LOW); else if (strPayload == "true") digitalWrite(5, HIGH); } } void reconnect() { while (!client.connected()) { if (client.connect(ID_CONNECT)) { client.subscribe("myhome/DoorbellControll/#"); } else { delay(5000); } } } void setup() { pinMode(ring1_pin, INPUT); pinMode(open1_pin, OUTPUT); digitalWrite(open1_pin, HIGH); pinMode(open2_pin, OUTPUT); digitalWrite(open2_pin, LOW); pinMode(mon1_pin, OUTPUT); digitalWrite(mon1_pin, LOW); Ethernet.begin(mac, ip); if (client.connect("DoorbellControll")) { client.publish("myhome/DoorbellControll/open1", "false"); client.publish("myhome/DoorbellControll/open2", "false"); client.publish("myhome/DoorbellControll/mon1", "false"); client.publish("myhome/DoorbellControll/ring1", "false"); client.subscribe("myhome/DoorbellControll/#"); } } void loop() { client.loop(); //    if (digitalRead(ring1_pin) == LOW && flag == 0) { client.publish("myhome/DoorbellControll/ring1", "true"); flag = 1;//  flag   } else if (digitalRead(ring1_pin) == HIGH && flag == 1) { client.publish("myhome/DoorbellControll/ring1", "false"); flag = 0; //  flag } if (!client.connected()) { reconnect(); client.subscribe("myhome/DoorbellControll/#"); } } 

And the second is a js script to implement user interaction:

 //************       ******************** createState('doorbellcontroll.rings', 'false'); createState('doorbellcontroll.visopen', 'false'); //   vis on("mqtt.0.myhome.DoorbellControll.ring1", function (obj){ if (obj.newState.val == "true" || obj.newState.val === true) { setState('javascript.0.doorbellcontroll.rings', true); setTimeout(function() { }, 60000); } }); //********      ,        **************** on("javascript.0.doorbellcontroll.rings", function (obj){ if (obj.newState.val == "true" || obj.newState.val === true) { setState('sayit.0.tts.text', '  '); //     sendTo('telegram.0', '  '); //    setState('mqtt.0.myhome.DoorbellControll.mon1', true); //     setState("vis.0.control.command", '{"instance": "FFFFFFFF", "command": "changeView", "data": "Camers"}'); //    "" //***********  30      ******************** setTimeout(function () { setState('mqtt.0.myhome.DoorbellControll.mon1', false); //     setState("vis.0.control.command", '{"instance": "FFFFFFFF", "command": "changeView", "data": "StartView"}'); //    "Home" setState('javascript.0.doorbellcontroll.rings', false); }, 30000); } }); //*******************   ""  Vis************** on("javascript.0.doorbellcontroll.visopen", function (obj){ if (obj.newState.val == "true" || obj.newState.val === true) { setState('mqtt.0.myhome.DoorbellControll.open1', true); //   toLog('   . ', true, 'orange'); //   setTimeout(function () { setState('mqtt.0.myhome.DoorbellControll.open1', false); setState('javascript.0.doorbellcontroll.visopen', false); //    }, 7500); } }); 

The iobroker system is displayed as objects with which you can interact.

image

In this narrative to what brings laziness craving to simplify his routine actions has come to a logical conclusion.

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


All Articles