How d00m4n/openwrt2ha works
This project—openwrt2ha—is a small, script-driven tool designed to bridge OpenWrt WiFi networks with Home Assistant via MQTT. In essence, it detects the configured SSID, manages network events, and even provides the option to reboot the system, specifically tested on the GL-MT6000 in AP mode.
Main Components
• OpenWrt Device: Represent the router/device running OpenWrt which manages the WiFi network.
• openwrt2ha Script: The core shell script (openwrt2ha.sh) that handles detection of the SSID and other system control logic.
• Environment Configuration: The openwrt2ha.env.example file which programs the script’s environment variables and connection details.
• Initialization & Setup: init.script and setup.sh, which likely handle the initial configuration and deployment of the tool.
• Home Assistant / MQTT Broker: The target system that receives WiFi network state information and any control commands (like reboot) via MQTT.
Relationships and Data Flow
• The OpenWrt device runs the openwrt2ha script.
• The script uses configuration parameters specified in the environment file.
• It auto-detects the configured SSID and interacts with the MQTT broker by publishing relevant network status.
• Home Assistant subscribes to these MQTT messages and can also send control commands (e.g., reboot system) via MQTT back to the device.
• Initialization and setup scripts facilitate the installation and environment configuration needed for the system to operate.
Architectural Patterns and Design Principles
• Modular Script-based Design: Involving separate shell scripts for initialization, environment configuration, and main functionality.
• Integration / Middleware Layer: The openwrt2ha.sh serves as an integration layer between the OpenWrt device and Home Assistant, using MQTT as the messaging protocol.
• Event-Driven Communication: The system leverages the publish/subscribe model of MQTT to react to network status changes and control commands.
Relevant Technologies and Frameworks
• OpenWrt OS: On the hardware side.
• Shell Scripting: For system control.
• MQTT: The messaging protocol facilitating communication between OpenWrt and Home Assistant.
• Home Assistant: The home automation platform that consumes data from MQTT.
Final Touches
• Modular design by singularly noting the roles of each script and configuration file.