HAMQTT 0.1.0
ESP-IDF component for integrating devices with Home Assistant over MQTT
|
ESP-IDF component for integrating devices with Home Assistant over MQTT
HAMQTT is a small C library that lets your ESP32 firmware expose sensors, buttons, and other components to Home Assistant over MQTT.
Category | Feature |
---|---|
Discovery | Automatic generation & pubication of device and component discovery payloads. |
Availability | Online / offline last-will handled for you |
Components | Binary_Sensor, Button (more planned) |
Footprint | ~2.9 KB flash / ~0 B static RAM (heap usage depends on component count) |
License | Apache 2.0 |
Status | Component type | Description |
---|---|---|
✅ Done | Binary Sensor | Basic On/Off |
✅ Done | Button | Basic pressable button |
⏳ Planned | Switch | On/Off control + state |
⏳ Planned | Sensor | Generic sensor (temperature, humidity, etc.) |
⏳ Planned | Number | Publish numeric value / accept setpoint |
⏳ Planned | Select | Dropdown selection entity |
⏳ Planned | Notify | Send notifications |
⏳ Planned | Text | Publish / accept text values |
⏳ Planned | Tag Scanner | RFID/NFC tag reader |
⏳ Planned | Alarm Control Panel | Arm/disarm alarm system |
⏳ Planned | Device Trigger | Trigger automations based on events |
⏳ Planned | Event | Publish custom event data |
⏳ Planned | Device Tracker | Track device presence/location |
⏳ Planned | Cover | Open/close/stop (e.g., garage door, blinds) |
⏳ Planned | Fan | Control fan speed and oscillation |
⏳ Planned | Humidifier | Control humidifier devices |
⏳ Planned | Light | Brightness / RGB / color control |
⏳ Planned | Lock | Lock/unlock doors |
⏳ Planned | Siren | Trigger audible alarms |
⏳ Planned | Valve | Control valves for water/gas |
⏳ Planned | Water Heater | Manage water heater temperature/settings |
⏳ Planned | Camera | Stream or snapshot camera images |
⏳ Planned | Lawn Mower | Control robotic lawn mower |
⏳ Planned | Scene | Activate preconfigured scenes |
⏳ Planned | Update | Firmware/software update over MQTT |
⏳ Planned | Vacuum | Control robotic vacuum cleaners |
Release 1.0.0 will ship once most of the table above is ✅.
Feedback and assistance on this project is greatly appreciated. If you have any ideas on how to improve this project, or simply want to tell me how I've done everything in the worst way possible, I'd love to hear it. HAMQTT is still in its infancy, and I am not shy to rewriting the entire thing for the sake of improving it.
If there’s a component missing from the list above that you wish existed, feel free to implement it and submit a PR! I’ve tried to make the codebase self-explanatory and well-documented, but here’s a detailed guide to help you get started building your own component:
Every component in HAMQTT is defined by a C struct that holds its internal state and behavior. To integrate with the framework, it must follow a few conventions.
Your component's struct must have a HAMQTT_Component as its first field. This lets the framework treat it as a generic component and cast it safely when needed:
This design lets the HAMQTT_Device interact with all components uniformly.
Each component must define a HAMQTT_Component_VTable struct, which contains function pointers used by the framework to interact with the component.
Each function serves a specific role in the lifecyclle of a component:
Function name | Purpose |
---|---|
get_discovery_config | Called at startup to populate a cJSON object representing this component's discovery config. This object will be nested under the component's entry in the cmps section of the device discovery message. You must populate all required fields for the component type (see the MQTT discovery docs). |
handle_mqtt_message | Called when a subscribed MQTT topic for this component receives a new message. This is where you handle commands from Home Assistant (e.g. turning a switch on). |
update | Called periodically in the main loop to publish state updates. You are responsible for formatting and publishing the MQTT payload. |
get_unique_id | Returns a unique string identifier for this component. This will be used to build discovery topic paths and for de-duplication inside Home Assistant. |
get_subscribed_topics | Returns a pointer to an array of topic strings and a count. These topics are automatically subscribed to and routed to handle_mqtt_message |
Your component will now be included in device discovery, state updates, and command routing.
If you need a reference, take a look at the existing binary_sensor or button components for a simple example of a full implementation.
HAMQTT is licensed under the Apache License 2.0. See [LICENSE](LICENSE) for details.