| Crates.io | hass-rs |
| lib.rs | hass-rs |
| version | 0.4.1 |
| created_at | 2020-08-13 08:20:10.439769+00 |
| updated_at | 2025-08-25 18:53:35.610427+00 |
| description | An async websocket client for Home Assistant |
| homepage | |
| repository | https://github.com/danrusei/hass-rs |
| max_upload_size | |
| id | 276075 |
| size | 75,740 |
A simple async Rust client library for interacting with Home Assistant websocket API.
Connect to your Home Assistant server, or follow the instructions from the Installation Guide.
For development, docker can be used to easily bootstrap a test environment.
Steps to run the provided Examples:
docker run -d --name="home-assistant" -v /PATH_TO_YOUR_CONFIG:/config -v /etc/localtime:/etc/localtime:ro --net=host homeassistant/home-assistant:stable
Profile --> Long-Lived Access Tokens and create a token to be used by hass_rs clientcargo run --example get_cmdscargo run --example call_servicecargo run --example subscribe_eventcargo run --example get_cmds_async_std --features use-async-std --no-default-features - example with async-std runtimeCheck the Example folder for additional details on how to use various hass-rs functions.
use hass_rs::client::HassClient;
use lazy_static::lazy_static;
use serde_json::json;
use std::env::var;
lazy_static! {
static ref TOKEN: String =
var("HASS_TOKEN").expect("please set up the HASS_TOKEN env variable before running this");
}
#[tokio::main]
async fn main() {
let url = "ws://localhost:8123/api/websocket";
println!("Connecting to - {}", url);
let mut client = HassClient::new(url).await.expect("Failed to connect");
client
.auth_with_longlivedtoken(&*TOKEN)
.await
.expect("Not able to autheticate");
println!("WebSocket connection and authethication works\n");
println!("Getting the Config:\n");
let cmd2 = client
.get_config()
.await
.expect("Unable to retrieve the Config");
println!("config: {}\n", cmd2);
}