Skip to content

Conversation

Copy link

Copilot AI commented Nov 10, 2025

Implements a management subsystem that bridges Zbus channels to Home Assistant, eliminating networking boilerplate for IoT device integration.

Implementation

Core subsystem (subsys/mgmt/homeassistant/)

  • Background thread monitors registered Zbus channels and syncs state via Home Assistant REST API
  • Supports sensors, binary sensors, switches, and numeric entities
  • Configurable server address, API token, update interval, thread stack size

Public API (include/zephyr/mgmt/homeassistant/)

  • HOMEASSISTANT_ENTITY_DEFINE() macro for one-line channel→entity registration
  • homeassistant_register_entity() for runtime registration
  • Entity types: HOMEASSISTANT_ENTITY_SENSOR, HOMEASSISTANT_ENTITY_BINARY_SENSOR, HOMEASSISTANT_ENTITY_SWITCH, HOMEASSISTANT_ENTITY_NUMBER

Sample (samples/subsys/homeassistant/basic/)

  • Temperature sensor, humidity sensor, light switch demo
  • Shows complete workflow from Zbus channel definition to automatic HA synchronization

Usage

// Define Zbus channel
ZBUS_CHAN_DEFINE(temperature_chan, struct temp_msg, 
                 NULL, NULL, ZBUS_OBSERVERS_EMPTY, 
                 ZBUS_MSG_INIT(.value = 20));

// Register as Home Assistant entity
HOMEASSISTANT_ENTITY_DEFINE(temp_sensor, "temperature",
                            HOMEASSISTANT_ENTITY_SENSOR,
                            "°C", "temperature", temperature_chan);

// Publish data - library handles HTTP communication
struct temp_msg temp = { .value = 25 };
zbus_chan_pub(&temperature_chan, &temp, K_NO_WAIT);

Configuration

Required prj.conf settings:

CONFIG_HOMEASSISTANT=y
CONFIG_HOMEASSISTANT_SERVER_ADDR="192.168.1.100"
CONFIG_HOMEASSISTANT_API_TOKEN="your_token"
CONFIG_ZBUS=y
CONFIG_HTTP_CLIENT=y

Limitations

  • Max 16 entities (compile-time configurable)
  • Simple integer data types only (extensible via callbacks)
  • Unidirectional: sends state updates, doesn't receive commands
  • REST API only (no MQTT discovery protocol)
Original prompt

add a new library (module?) that provides simple and easy home assistant integration

use zbus so that user needs not to think about networkin at all - they just expose data to zbus channels and boom

add a sample too


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 3 commits November 10, 2025 10:34
- Created subsys/mgmt/homeassistant with Kconfig, CMakeLists, and implementation
- Added public API header in include/zephyr/mgmt/homeassistant/
- Integrated subsystem into main build system
- Created basic sample in samples/subsys/homeassistant/basic/
- Added comprehensive documentation

Co-authored-by: kartben <[email protected]>
- Fixed Kconfig to properly use logging template
- Updated HOMEASSISTANT_ENTITY_DEFINE macro to accept string name parameter
- Updated sample and documentation to match new macro signature
- Simplified inet_pton usage to match other samples

Co-authored-by: kartben <[email protected]>
- Added configurable HOMEASSISTANT_THREAD_STACK_SIZE option
- Increased default stack size from 2048 to 4096 bytes
- This ensures sufficient stack for HTTP client operations

Co-authored-by: kartben <[email protected]>
Copilot AI changed the title [WIP] Add new library for home assistant integration using zbus Add Home Assistant integration subsystem with Zbus bridge Nov 10, 2025
Copilot AI requested a review from kartben November 10, 2025 10:46
Copilot finished work on behalf of kartben November 10, 2025 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants