n3rgy_consumer_api_client

Crates.ion3rgy_consumer_api_client
lib.rsn3rgy_consumer_api_client
version0.1.1
sourcesrc
created_at2024-09-17 17:45:56.322985
updated_at2024-09-17 19:44:23.64691
descriptionA client for retrieving energy data from n3rgy's consumer API
homepage
repositoryhttps://github.com/rars/n3rgy_consumer_api_client
max_upload_size
id1377781
size22,150
Richard (rars)

documentation

README

n3rgy_consumer_api_client

A Rust client for accessing electricity and gas smart meter data in the United Kingdom via the n3rgy consumer data REST API.

Note: This library is not affiliated with or endorsed by n3rgy.

Prerequisites

To access your data, you must enroll in the n3rgy consumer access service. Follow these steps:

  1. Visit the n3rgy website: Go to the n3rgy consumer data page.
  2. Retrieve your IHD MAC address: Get your In Home Device (IHD) MAC address from the settings of your IHD device.
  3. Complete the enrollment process: Follow the instructions on the website to complete your enrollment.

Example usage

Set the environment variable N3RGY__APIKEY to your In Home Device (IHD) MAC address, formatted without hyphens.

use chrono::{Days, Local};
use n3rgy_consumer_api_client::{ConsumerApiClient, EnvironmentAuthorizationProvider};

#[tokio::main]
async fn main() {
    let ap = EnvironmentAuthorizationProvider {};
    let client = ConsumerApiClient::new(ap, None);

    let today = Local::now().date_naive();
    let yesterday = today.checked_sub_days(Days::new(1)).unwrap();

    if let Ok(consumption) = client.get_electricity_consumption(yesterday, today).await {
        println!(
            "Retrieved {} electricity consumption records",
            consumption.len()
        );
    }

    if let Ok(consumption) = client.get_electricity_tariff(yesterday, today).await {
        println!("Retrieved {} electricity tariff records", consumption.len());
    }

    if let Ok(consumption) = client.get_gas_consumption(yesterday, today).await {
        println!("Retrieved {} gas consumption records", consumption.len());
    }

    if let Ok(consumption) = client.get_gas_tariff(yesterday, today).await {
        println!("Retrieved {} gas tariff records", consumption.len());
    }
}

For interactive user input, consider using StaticAuthorizationProvider::new(api_key) rather than EnvironmentAuthorizationProvider.

Important security note

API keys are sensitive information. Ensure they are not stored in source control. Use environment variables or secure vaults to manage them safely.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Commit count: 0

cargo fmt