Skip to content

Repository files navigation

Ubiquiti mFi Custom Code

Custom firmware applications for Ubiquiti's mFi line of power monitoring and switching devices. Includes an MQTT client for Home Assistant integration, a REST API server, and a CLI tool — all built on a shared C++ library that wraps the mFi hardware interface.

Architecture

mfi-mqtt-client ─┬─ hass_mqtt_device (Home Assistant MQTT discovery)
                 ├─ mfi (hardware abstraction: sensors, relays, LEDs)
                 ├─ mfi-update (self-update from GitHub Releases)
                 └─ shmuelie-shared (string utilities)

mfi-rest-server ─┬─ civetweb (embedded HTTP server, C++ API)
                 ├─ mfi
                 ├─ mfi-update
                 └─ shmuelie-shared

mfi-cli ─────────┬─ mfi
                 ├─ mfi-update
                 └─ shmuelie-shared

Projects

Executables

Project Description Version
mfi-mqtt-client MQTT client with Home Assistant auto-discovery 1.2.1
mfi-rest-server HTTP REST API server 1.2.2
mfi-cli CLI tool for device inspection and control 1.1.0

Libraries

Project Description Version
mfi Hardware abstraction for sensors, relays, LEDs 1.0.1
hass_mqtt_device Home Assistant MQTT device library 1.2.0
mfi-update Self-update from GitHub Releases 1.0.0
shmuelie-shared String helper functions 1.0.0

Alternatives

There are several community shell-script projects for controlling mFi devices. This project differs in being a compiled C++ solution with a proper hardware abstraction layer, native MQTT, and Home Assistant auto-discovery.

Feature mfi-custom-code mpower-tools mFi-tools
Language C++ Shell scripts Shell scripts
MQTT Native (libmosquitto) Via mosquitto_pub Via mosquitto_pub
Home Assistant Auto-discovery (switches + sensors) Manual YAML config Manual YAML config
REST API Yes (civetweb) No No
CLI tool Yes No No
Sensor data Power, current, voltage, power factor Power, energy Power, energy
Change-only updates Yes (reduces MQTT traffic) No (polls on interval) No (polls on interval)
Hardware abstraction C++ library Direct file I/O Direct file I/O
Cross-compilation Buildroot toolchain Not needed Not needed
Unit tests Catch2 None None
Install complexity Build + deploy binary Copy scripts Copy scripts

Documentation

  • Building — packages, CMake presets, build commands, testing
  • Deploying — binary sizes, UPX, boot scripts, SCP
  • Updating — self-update from GitHub Releases
  • mFi Notes — persistent storage, save, boot hooks
  • cfgmtd — flash configuration utility internals

About

Providing custom code to run on Ubiquiti's mFi Devices

Topics

Resources

Stars

3 stars

Watchers

1 watching

Forks

Releases

Contributors

Languages