aboutsummaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
Diffstat (limited to 'README.md')
-rw-r--r--README.md105
1 files changed, 95 insertions, 10 deletions
diff --git a/README.md b/README.md
index 4b8f818..7529443 100644
--- a/README.md
+++ b/README.md
@@ -1,17 +1,102 @@
1# embassy-ha 1# embassy-ha
2 2
3Home Assistant MQTT device library for embassy. 3[![Crates.io](https://img.shields.io/crates/v/embassy-ha.svg)](https://crates.io/crates/embassy-ha)
4[![Documentation](https://docs.rs/embassy-ha/badge.svg)](https://docs.rs/embassy-ha)
4 5
5To create a device use the [`new`] function. 6MQTT Home Assistant integration library for the [Embassy](https://embassy.dev/) async runtime.
6 7
7After the device is created you should create one or more entities using functions such as 8## Features
8[`create_button`]/[`create_sensor`]/...
9 9
10Once the entities have been created either [`run`] or [`connect_and_run`] should be called in a 10- Support for multiple entity types: sensors, buttons, switches, binary sensors, numbers, device trackers
11seperate task. 11- Built on top of Embassy's async runtime for embedded systems
12- No-std compatible
13- Automatic MQTT discovery for Home Assistant
14- No runtime allocation
12 15
13There are various examples you can run locally (ex: `cargo run --features tracing --example 16## Installation
14button`) assuming you have a home assistant instance running. To run the examples the
15environment variable `MQTT_ADDRESS` should be set to the mqtt server used by home assistant.
16 17
17License: MIT OR Apache-2.0 18```bash
19cargo add embassy-ha
20```
21
22## Quick Start
23
24This example does not compile as-is because it requires device-specific setup, but it should
25be easy to adapt if you already have Embassy running on your microcontroller.
26
27```rust
28use embassy_executor::Spawner;
29use embassy_ha::{DeviceConfig, SensorConfig, SensorClass, StateClass};
30use embassy_time::Timer;
31use static_cell::StaticCell;
32
33static HA_RESOURCES: StaticCell<embassy_ha::DeviceResources> = StaticCell::new();
34
35#[embassy_executor::main]
36async fn main(spawner: Spawner) {
37 // Initialize your network stack
38 // This is device specific
39 let stack: embassy_net::Stack<'static>;
40
41 // Create a Home Assistant device
42 let device = embassy_ha::new(
43 HA_RESOURCES.init(Default::default()),
44 DeviceConfig {
45 device_id: "my-device",
46 device_name: "My Device",
47 manufacturer: "ACME Corp",
48 model: "Model X",
49 },
50 );
51
52 // Create a temperature sensor
53 let sensor_config = SensorConfig {
54 class: SensorClass::Temperature,
55 state_class: StateClass::Measurement,
56 unit: Some(embassy_ha::constants::HA_UNIT_TEMPERATURE_CELSIUS),
57 ..Default::default()
58 };
59 let mut sensor = embassy_ha::create_sensor(&device, "temp-sensor", sensor_config);
60
61 // Spawn the Home Assistant communication task
62 spawner.spawn(ha_task(stack, device)).unwrap();
63
64 // Main loop - read and publish temperature
65 loop {
66 // let temperature = read_temperature().await;
67 sensor.publish(temperature);
68 Timer::after_secs(60).await;
69 }
70}
71
72#[embassy_executor::task]
73async fn ha_task(stack: embassy_net::Stack<'static>, device: embassy_ha::Device<'static>) {
74 embassy_ha::connect_and_run(stack, device, "mqtt-broker-address").await;
75}
76```
77
78## Examples
79
80The repository includes several examples demonstrating different entity types. To run an example:
81
82```bash
83export MQTT_ADDRESS="mqtt://your-mqtt-broker:1883"
84cargo run --example sensor
85```
86
87Available examples:
88- `sensor` - Temperature and humidity sensors
89- `button` - Triggerable button entity
90- `switch` - On/off switch control
91- `binary_sensor` - Binary state sensor
92- `number` - Numeric input entity
93- `device_tracker` - Location tracking entity
94
95## License
96
97Licensed under either of:
98
99- Apache License, Version 2.0 ([LICENSE-APACHE](LICENSE-APACHE) or http://www.apache.org/licenses/LICENSE-2.0)
100- MIT license ([LICENSE-MIT](LICENSE-MIT) or http://opensource.org/licenses/MIT)
101
102at your option.