Growatt API Rust
A Rust client for interacting with the Growatt API. This library allows you to:
- Login and authenticate with the Growatt server
- Retrieve plant and device information
- Get energy statistics (daily, monthly, yearly, total)
- Access mix status and battery statistics
- Retrieve fault logs and other device information
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
use Growatt;
async
Environment Variables Configuration
You can initialize the client with environment variables for easier configuration:
use Growatt;
use dotenv;
async
Expected environment variables:
GROWATT_USERNAME: Your Growatt account usernameGROWATT_PASSWORD: Your Growatt account passwordGROWATT_BASE_URL(optional): Alternative base URLGROWATT_SESSION_DURATION(optional): Session duration in minutes
Client Initialization Options
Standard Initialization
// Create with default options
let client = new;
Alternative Server URL
// Use an alternative API server
let client = new.with_alternate_url;
Custom Session Duration
// Set a custom session duration (60 minutes)
let client = new.with_session_duration;
Authentication
Login
// Login with username and password
let success = client.login.await?;
Logout
// Properly terminate the session
let success = client.logout.await?;
Authentication Status
// Check if currently logged in
if client.is_logged_in
Core API Methods
Plant Management
// Get all plants for the account
let plants = client.get_plants.await?;
// Get detailed information about a specific plant
let plant_details = client.get_plant.await?;
// Get weather information for a plant
let weather = client.get_weather.await?;
Device Management
// Get list of MIX device IDs for a plant
let mix_ids = client.get_mix_ids.await?;
// Get detailed device list for a plant
let devices = client.get_device_list.await?;
// Get devices with pagination
let devices_page = client.get_devices_by_plant_list.await?;
Mix Device Data
// Get total measurements from a specific MIX
let mix_total = client.get_mix_total.await?;
// Get current status of a MIX device
let mix_status = client.get_mix_status.await?;
// Update MIX AC discharge time period
let result = client.post_mix_ac_discharge_time_period_now.await?;
Energy Statistics
// Get daily energy statistics
let daily_stats = client.get_energy_stats_daily.await?;
// Get monthly energy statistics
let monthly_stats = client.get_energy_stats_monthly.await?;
// Get yearly energy statistics
let yearly_stats = client.get_energy_stats_yearly.await?;
// Get total energy statistics
let total_stats = client.get_energy_stats_total.await?;
Battery Statistics
// Get weekly battery statistics
let battery_stats = client.get_weekly_battery_stats.await?;
Fault Logs
// Get fault logs with detailed parameters
let fault_logs = client.get_fault_logs.await?;
// Using the alias method (identical functionality)
let fault_logs = client.get_plant_fault_logs.await?;
Error Handling
The library uses a custom error type GrowattError which covers various error scenarios:
// Example of error handling
match client.login.await
Data Structures
The library provides structured access to Growatt data:
// Example of working with plant data
let plants = client.get_plants.await?;
for plant in plants.0
// Example of working with plant details
let plant_details = client.get_plant.await?;
if let Some = plant_details.total_energy
Advanced Usage
Session Management
The library automatically handles session expiry and renewal:
// The client will automatically re-authenticate if needed
client.get_plants.await?;
Token Access
// Get the authentication token (if needed for external use)
if let Some = client.get_token
License
MIT