Can get consumption on Fronius inverter

This commit is contained in:
Pierre HUBERT 2024-10-12 17:28:49 +02:00
parent 784fe58c3e
commit 5408cd3a9c
3 changed files with 39 additions and 1 deletions

View File

@ -18,7 +18,7 @@ asn1 = "0.17"
actix-web = { version = "4", features = ["openssl"] }
futures = "0.3.30"
serde = { version = "1.0.210", features = ["derive"] }
reqwest = "0.12.7"
reqwest = { version = "0.12.7", features = ["json"] }
serde_json = "1.0.128"
rand = "0.8.5"
actix = "0.13.5"

View File

@ -35,6 +35,13 @@ pub enum ConsumptionBackend {
#[clap(short, long, default_value = "/dev/shm/consumption.txt")]
path: String,
},
/// Fronius inverter consumption
Fronius {
/// The origin of the domain where the webserver of the Fronius Symo can be reacher
#[clap(short, long)]
origin: String,
},
}
/// Solar system central backend

View File

@ -13,6 +13,30 @@ pub enum ConsumptionError {
pub type EnergyConsumption = i32;
#[derive(serde::Deserialize)]
struct FroniusResponse {
#[serde(rename = "Body")]
body: FroniusResponseBody,
}
#[derive(serde::Deserialize)]
struct FroniusResponseBody {
#[serde(rename = "Data")]
data: FroniusResponseBodyData,
}
#[derive(serde::Deserialize)]
struct FroniusResponseBodyData {
#[serde(rename = "Site")]
site: FroniusResponseSite,
}
#[derive(serde::Deserialize)]
struct FroniusResponseSite {
#[serde(rename = "P_Grid")]
grid_production: f64,
}
/// Get current electrical energy consumption
pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
let backend = AppConfig::get()
@ -38,5 +62,12 @@ pub async fn get_curr_consumption() -> anyhow::Result<EnergyConsumption> {
.parse()
.map_err(ConsumptionError::FileInvalidContent)?)
}
ConsumptionBackend::Fronius { origin } => {
let url = format!("{origin}/solar_api/v1/GetPowerFlowRealtimeData.fcgi");
let response = reqwest::get(url).await?.json::<FroniusResponse>().await?;
Ok(response.body.data.site.grid_production as i32)
}
}
}