Can get consumption on Fronius inverter
This commit is contained in:
parent
784fe58c3e
commit
5408cd3a9c
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user