|
| 1 | +--- |
| 2 | +title: Architecture |
| 3 | +sidebar_position: 7 |
| 4 | +--- |
| 5 | +import Centered from '@site/src/components/Centered'; |
| 6 | + |
| 7 | +# Architecture |
| 8 | + |
| 9 | +## Software components |
| 10 | +There are 3 software components written for the NSPanel Manager project: |
| 11 | + |
| 12 | +* **Web interface**: The web interface that you interact with is built on top of the Django framework. This software gives |
| 13 | + the user an interface to interact and configure the project with. This software also manages the database with settings. |
| 14 | +* **MQTT Manager**: There is a second software running in the background on the NSPanel Manager container that |
| 15 | + hosts the web interface. This component is named "MQTTManager". The MQTTManager handles all things with |
| 16 | + MQTT. It loads the config from the web interface via the API and then processes all commands from panels, state |
| 17 | + updates from Home Assistant and OpenHAB and so on. It’s basically the glue that makes the panel’s actions affect |
| 18 | + Home Assistant and OpenHAB. The MQTTManager is also the software that send state updates from Home Assistant |
| 19 | + and OpenHAB to the panels when changes occur. |
| 20 | +* **The NSPanel firmware**: The firmware written for the NSPanel has been specifically designed to be as response |
| 21 | + and easy to use as possible. The firmware handles all communication with the TFT (Nextion) display and with |
| 22 | + MQTTManager via MQTT. |
| 23 | + |
| 24 | +## Data flow |
| 25 | + |
| 26 | +<Centered> |
| 27 | +```mermaid |
| 28 | +flowchart TD |
| 29 | + HAS(Home Assistant/OpenHAB) |
| 30 | + NSPM(NSPanel Manager container) |
| 31 | + MQTT(MQTT Server) |
| 32 | + NSP1(NSPanel 1) |
| 33 | + NSP2(NSPanel 2) |
| 34 | + HAS <--> NSPM |
| 35 | + NSPM <--> NSP1 |
| 36 | + NSPM <--> NSP2 |
| 37 | + MQTT <--> HAS |
| 38 | + MQTT <--> NSPM |
| 39 | + MQTT <--> NSP1 |
| 40 | + MQTT <--> NSP2 |
| 41 | +``` |
| 42 | +</Centered> |
| 43 | + |
| 44 | +The data flow within NSPanel Manager might look intimidating but it’s not that bad. Below is an explanation of all the |
| 45 | +arrows above. |
| 46 | + |
| 47 | +### Home Assistant and/or OpenHAB to/from NSPanel Manager container |
| 48 | + |
| 49 | +There is two types of traffic flowing between these nodes: |
| 50 | +* **Websocket**: A websocket connection is setup in order for the NSPanel Manager container to receive entity updates |
| 51 | + from Home Assistant and/or OpenHAB but also to sent entity commands (E.. turn light X on to 20%). A websocket |
| 52 | + is used to speed up the communication and also to not have to poll the home automation software for information. |
| 53 | +* **HTTP GET API**: The usual HTTP GET API is also used. This is used when adding entities to a room, as an |
| 54 | + example. When pressing the "Add new light" button, the NSPanel Manager container will make an HTTP GET request |
| 55 | + to gather all available entities and then send them back to the client (browser) so that the user may choose what |
| 56 | + entity to add to the room. |
| 57 | + |
| 58 | +### NSPanel Manager container to/from MQTT |
| 59 | + |
| 60 | +MQTT is used to send updated entity states received from the home automation software out to all NSPanels and also |
| 61 | +receive states and commands from NSPanels. |
| 62 | + |
| 63 | +### Home Assistant and/or OpenHAB to/from MQTT |
| 64 | + |
| 65 | +Home Assistant and OpenHAB can leverage the MQTT integration through "Home Assistant MQTT Auto-discovery" (which |
| 66 | +OpenHAB can also use) to auto-discover NSPanels and automatically register entities for panel temperature reading, panel |
| 67 | +relays, screen state and so on. |
| 68 | + |
| 69 | +### NSPanel Manager container to/from NSPanels |
| 70 | + |
| 71 | +The configuration of lights, scenes and so on does not reside on each panel. The panel only has locally the bare minimum |
| 72 | +configuration for setup. When the panel starts and has connected to WiFi it will do a HTTP GET request to the NSPanel |
| 73 | +Manager container in order to receive all configuration of entities, screen brightness and really, all settings |
| 74 | +available in the NSPanel Manager web interface. |
| 75 | + |
| 76 | +### MQTT to/from NSPanels |
| 77 | + |
| 78 | +Each NSPanel send states (E.g. temperature) and commands (E.g. turning on a light) over MQTT for the NSPanel Manager |
| 79 | +container to pickup. |
| 80 | + |
| 81 | +The panel also receives commands, E.g. turn on relay 1, turn on screen and so on. |
| 82 | + |
| 83 | +:::info |
| 84 | +The complete list of MQTT topics is documented [here](./mqtt-topics). |
| 85 | +::: |
0 commit comments