Ok i live in a small appartment, but at least I have three Window and a little bit stuff to connect with each other. I startes with Ikea TRÅDFRI and some selfe made components based Arudino/Wemos. About one year ago I tried zigbee2mqtt to connect the ikea bulbs to MQTT without using my own buggy code. I used a MQTT-Broker on a Virtual Server somewhere in the internet and develop some PHP-Application with lumen (some of them running in kubernetes) to connect everything.
After some issues with my Internet Provider I beginn with a easyer and locale alternative. I already used a Raspberry Pi for zigbee2mqtt so i want to run everything on it. On the other hand I want a secound MQTT Server in the Internet(tm) to connect from other networks. Also I like the idear of smaller “services” managed single features.
First i setup supervisord on the pi to managed all scripts. I develope the new Services in golang, so first i build a small wrapper arround paho.mqtt.golang, so all Services has the same configure also for the Last Will and Testament. It connected without crdentials to a mqtt server running on the same pi (localhost). Than i could start creating single services. One react to all incomming MQTT-Message if a button is pressed and change the light-modus. The light-modus are topics with retained messages. Another services subscribed to this topic and send the mqtt messages to zigbee2mqtt which changed the light bulbs.
For all topics contained a state like the light-modus i created a set topic. The light modus for the “main” room could be
light-modus/main, to change it i published a message to
light-modus/main/set. I used another service just mirrow the incomming messages at the set topic (not retained) and send it to the original topic (as retained messages).
The Mosquito MQTT Broker has a feature to setup a bridge between two MQTT Server. So i setup another instanc of it at a VM in the internet. After that i can configure on the MQTT Broker on my locale pi to connect to the remote mqtt server. I relay messages from status topics (like light-modus), sensor and device informations (from zigbee2mqtt) and subscripe to some */set topics. With this setup everything works fine without internet in my apparment. But as long as the internet connection is avalible I can publish messages to the online mqtt server which would be recived locale.
All Automation Services are also written in go, and had a feature toggle as retained mqtt topic (with a seperate /set topic). With this I can change the behavior of it. For example i had a service checking if I’m currenlty in im appartment and the value of the lumex sensor falls below a special value. If that happends it will turn on the light. But I dont always want that to happend to I can toggle this feature.
Also all status information are avalible as retained messages at the MQTT-Broker. So each service can restart without any issues.
I still use Mqtt Dash at my Android Device do control most things. Some information like the room temperature are already stored in a graphite database to have access via grafana. In the feature I want to create some status dashboard based on the last will of the service and some zigbee2mqtt messages. Also maybe a webpage connecting to the broker to controll the light with a tablet.