We often think about how to automate our home, but often this question comes down to the fact that ready-made systems are too inflexible and expensive, and there is absolutely no time to figure out how to do something yourself.
Under the cut is a detailed guide on setting up a smart home system: we will make it possible for ZWave devices and custom MQTT devices based on ESP8266 to work, we will set up home control using HomeKit and Yandex Alice.
Raspberry PI initial setup
System installation
raspberry pi os https://www.raspberrypi.org/downloads/raspberry-pi-os/ MicroSD 16 . 10 , .
$ sudo dd bs=4M if=raspbian.img of=/dev/sdf status=progress
Headless
SSH
boot ssh( : ssh raspberry sshd , sudo raspi-config ssh )
# mkdir /mnt/boot_partition
# mount /dev/sdf1 /mnt/boot_partition
# touch /mnt/boot_partition/ssh
# umount /dev/sdf1
ssh.
Wi-Fi
wifi, boot wpa_supplicant.conf
# mkdir /mnt/boot_partition
# mount /dev/sdf1 /mnt/boot_partition
# vim /mnt/boot_partition/wpa_supplicant.conf
# umount /dev/sdf1
wpa_supplicant.conf
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
update_config=1
country=RU
network={
ssid="your_ssid"
psk="your_wifi_password"
}
, ethernet , wifi, microUSB, 2 .
Raspberry PI , .
ssh.
, ip- raspberry pi . , nmap. ip .
# nmap -sn 192.168.0.1/24
Starting Nmap 7.80 ( https://nmap.org ) at 2020-08-23 23:49 MSK
Nmap scan report for 192.168.0.1
Host is up (0.00033s latency).
Nmap scan report for 192.168.0.105
Host is up (0.00016s latency).
Nmap scan report for 192.168.0.120
Host is up (0.00050s latency).
Nmap done: 256 IP addresses (3 hosts up) scanned in 2.57 seconds
, (192.168.0.1) (192.168.0.105) 192.168.0.120 - , .
. /: pi/raspberry.
# ssh pi@192.168.0.120
Linux raspberrypi 4.19.118-v7+ #1311 SMP Mon Apr 27 14:21:24 BST 2020 armv7l
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sun Aug 23 21:54:16 2020 from 192.168.0.105
pi@raspberrypi:~ $
ssh raspberry pi .
Domoticz
Domoticz - . C++. , openhub home assistant, domoticz , , , C++, , , java python. , Lua python.
, domoticz . , .
pi@raspberrypi:~ $ sudo curl -L install.domoticz.com | sudo bash
, , , , . HTTP 80 , .
, , , , domoticz :
pi@raspberrypi:~ $ sudo service domoticz status
, web : http://192.168.0.120/
Watchdog
, Domoticz . , watchdog cron.
#!/bin/sh
# /etc/scripts/check_domoticz_online.sh
# check domoticz
status=`curl -s -i -H "Accept: application/json" "http://localhost:8080/json.htm?type=devices&rid=1" | grep "status"| awk -F: '{print $2}'|sed 's/,//'| sed 's/\"//g'`
if [ $status ]
then
echo "Domoticz has already been started"
else
/home/pi/domoticz/domoticz.sh restart
fi
pi@raspberrypi:~ $ sudo crontab -e -u root
*/5 * * * * /etc/scripts/check_domoticz_online.sh > /dev/null 2>&1
5 , , Domoticz ,
domoticz
, , .
IP-
, Domoticz - . web- Setup -> More options -> Cameras -> Add camera.
, , , .
Z-Wave USB Stick
Domoticz, Z-Wave IoT . , , , , Z-Wave , Z-Wave. , , Z-Wave , , / .
, Z-Wave Domoticz , Home Assistant openHub, USB Stick .
, Z-Wave, Z-Wave USB Stick. Raspberry pi, Hardware, Type OpenZWave USB. Serial Port : /dev/serial/by-id/usb-0658_0200-if00
, , Setup, ZWave . ZWave , .
: , Z-Stick Z-Wave
MQTT-
IoT Arduino . MQTT - , -. MQTT- - . Domoticz IoT , .
MQTT- Mosquitto.
pi@raspberrypi:~ $ sudo wget http://repo.mosquitto.org/debian/mosquitto-repo.gpg.key
pi@raspberrypi:~ $ sudo apt-key add mosquitto-repo.gpg.key
pi@raspberrypi:~ $ cd /etc/apt/sources.list.d/
pi@raspberrypi:/etc/apt/sources.list.d/ $ sudo wget http://repo.mosquitto.org/debian/mosquitto-jessie.list
pi@raspberrypi:/etc/apt/sources.list.d/ $ cd
pi@raspberrypi:~ $ sudo apt-get install mosquitto mosquitto-clients
pi@raspberrypi:~ $ rm mosquitto-repo.gpg.key
Mosquitto . 0.0.0.0:1883. .
Domoticz - MQTT
domoticz MQTT-. web- Domoticz - Setup -> Hardware.
Type - MQTT Client Gateway with LAN interface.
Remote address - localhost
Port - 1883
Data Timeout - disabled
Username password -
Prevent loop - , MQTT , prevent loop domoticz domoticz/in domoticz/out. , domoticz/in, domoticz/out, domoticz in out, .
Publish topic - , domoticz . - out, domoticz domoticz/out.
Add hardware. , , Enabled Yes.
Dummy switch
. - ( , ), domoticz .
Dummy hardware. web- Domoticz - Setup -> Hardware
Type - Dummy (Does nothing, use for virtual switches only)
. . , Type Create virtual sensors. ,
Name - lamp
Sensor type - Switch
Switches. :
, MQTT.
pi@raspberrypi:~ $ mosquitto_sub -h localhost -v -t "domoticz/out"
MQTT, , , domoticz . -
:
domoticz/out {
"Battery" : 255,
"RSSI" : 12,
"description" : "",
"dtype" : "Light/Switch",
"hwid" : "4",
"id" : "00014052",
"idx" : 2,
"name" : "lamp",
"nvalue" : 1,
"stype" : "Switch",
"svalue1" : "0",
"switchType" : "On/Off",
"unit" : 1
}
Domoticz . - JSON. name , switch' domoticz. nvalue.
IoT Arduino-like .
, MQTT- Domoticz , switch, . : , MQTT, Domoticz, , name , , . , , - .
Arduino Uno, Ethernet Shield, Arduino-like ESP8266, WiFi. , - Ethernet WiFi.
MQTT MQTT.h. JSON - ArduinoJSON.h.
, Arduino, , MQTTClient ArduinoJSON 500 String, 2 . 300 "" , , 300-400 , , , .
ESP8266 , .
! Domoticz, !
, ESP8266, :
Arduino UNO + Ethernet Shield - 1100 , WiFi - 400
, WiFi Domoticz,
Domoticz , - . , : mqtt , domoticz , homebridge - Apple, domoticz .
:
pi@raspberrypi:~ $ sudo apt update
pi@raspberrypi:~ $ sudo apt install -y nodejs npm libavahi-compat-libdnssd-dev
pi@raspberrypi:~ $ sudo npm install -g --unsafe-perm homebridge homebridge-config-ui-x
pi@raspberrypi:~ $ sudo npm install -g -g --unsafe-perm homebridge-edomoticz
sudo hb-service install --user homebridge
- homebridge 8581, admin:admin qr- , iphone. Homebridge domoticz , domoticz, homebridge iphone, . domoticz/in. , mqtt domoticz prevent loop. , , domoticz domoticz/in, domoticz/out , domoticz/out, . , domoticz/in , .
Homebridge g-on . - .
Domoticz,
, , IoT , IoT , WiFi, , Apple
P.S.
. " ", , ESP8266. MQTT Domoticz