Especifications

  • Power supply redundancy. Critical functions can run even during multi-days power outages
  • All devices (RPi, Critical Nodes, Modem, DVR) can be powered on/off remotely. Current and Voltage are measured and logued. 
  • 4G backup internet connection. All Nodes and Core change to alternate link on failure. 
  • Backup of the Core on an external VPS.  All Nodes should connect to alternate Broker on failure.  
  • The two MQTT Brokers are bridged, so clients can be connected to either

Topology

The topology is simple and classic: In the Core is a MQTT Broker, the logic is done in Node-RED and the Nodes are mainly ESP8266 + PS + Whatever is needed (sensors, relays, ADC, Led, Switches, etc)

In the cloud , in a VPS, is the Secondary Node, which has an online MQTT Broker, and a Paused Node-RED. Also is in charge of watch the Main Core, in case of failure a Push Message is sended to the clients

This creates redundancy, but also gives the posibility of connect  the house with a 4G link (with no public IP) and still have control from outside (as the Main Core MQTT Broker is bridged the the External Core)

The 4G link is created with a hotspot This SSID is defined in every node has a secondary network. So in the event for losing connection, they will try the secondary. In case of the main internet link is down and even the Main Core is down, the nodes will still be conneted the the External Core by 4G


Power

Here in Argentina, power outages are a common occurrence. Since my system is responsible for the alarm (and thefts are also frequent), I wanted a system capable of running critical functions without relying on external energy.

Additionally, I desired the ability to remotely control the power of different parts of the system.

After several iterations now I have this:

This gives a high level of redundance, including the ability to run critical functions without relying on the mains. The "Power Control" box is a node capable of turning on and off the four buses (3x12V + 1x5V). It also measures voltage and current using an ADS1115. Additionally, the node has connection redundancy (as discussed in the "Nodes" section) and incorporates some level of intelligence (e.g. The modem bus will turn itself on, after 30sec of being off)

Also measuring voltage allows to check if I lost mains, because the Power Supply has a greater voltage than the battery. Dirty, but works.


Main Core

The core is a Rpi3 with Raspbian Lite,  Mosquitto as MQTT Broker, and  Node-RED. There is most of the intelligence of the house:

  • Turning on and off lights, acording the time of the day, sensors, etc
  • Turning on and off pumps, acording tank levels / time of the day / presence
  • Detection of open doors, gates, etc
  • Lighs
  • Pool automation
  • Alarm, siren, sensors
  • Loggin data
  • Feeding the cat
  • Pushing data to cells
  • ... and many more!

Not big fan of Node-RED, it's hard to debug, but very easy to add a new function. 


Nodes Hardware

All the Nodes are ESP8266, several versions (ESP01, ESP12...) but lastly I only use Wemos D1. They are small, had USB which is very handy to program, can be powered by 3.3V, or 5V, are easy to replace.

There are several versions of nodes, for example 

A light control could be: Wemos D1 + 220V to 5V PS + Rele

A Infrared alarm sensor: ESP01 + 12V to 3.3V PS + IR Sensor



Nodes Firmware

I choose to use NodeMCU LUA to program the nodes. As an interpreted lenguaje allows me a very quick development, and debug (even remotly through some sort of MQTT console). 

All nodes shared the 90% of the code and  basic functions. e.g. 

  • On power up looks for the same SSIDs,
  • When connect to the MQTT broker they send a message reporting being power up
  • They subscribe to its configurable MQTT topic, but also to a broadcast one.  Usefull to reset all nodes, to send the keep alive message,...
Read more »