Skip to main content

Crate homeassistant_rs

Crate homeassistant_rs 

Source
Expand description

Implements the Homeassistant API for use in rust

A simple lib, that queries different endpoints and returns the data in a usable format.

The first 2 arguments of each function are always: HA_URL, API_Token.

These arguments do not have to be filled with actual data, they can be None, but in this case you will need to use environment variables.

Under the hood we use dotenvy.

Example env:

HA_URL="http://localhost:8123"
HA_TOKEN="api_token_from_hass"
  • Easily get HA’s config:
use homeassistant_rs::{self, hass};
let config = hass().config(None, None).await.unwrap();

println!("{}", config.version);

You can check all available endpoints here: HomeAssistant

  • More Examples:
use homeassistant_rs::hass;
 
hass().config(None, None).await.unwrap();
hass().events(None, None).await.unwrap();
hass().services(None, None).await.unwrap();
hass()
    .history(
        None,
        None,
        Some("light.bedroom_light_shelly"),
        /// minimal_response
        true,
        /// no_attributes
        true,
        /// significant_changes_only
        true,
        Some(chrono::Local::now() - chrono::Duration::hours(1)),
        None,
    )
    .await.unwrap();
hass().logbook(None, None, Some("light.bedroom_light_shelly")).await.unwrap();
hass().states(None, None, Some("light.bedroom_light_shelly")).await.unwrap();
hass().states(None, None, None).await.unwrap();
hass().error_log(None, None).await.unwrap();

Re-exports§

pub use ::bytes;
pub use ::lazy_static;
pub use ::reqwest;
pub use ::serde;
pub use ::serde_json;
pub use ::chrono;
pub use ::anyhow;
pub use ::dotenvy;

Modules§

structs

Structs§

CLIENT
HomeAssistant
HomeAssistantPost

Functions§

hass