From 5bb36d5cefb5d4decd169fb6c417cd16b3cb5535 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 16 Mar 2024 11:26:08 +0100 Subject: [PATCH 1/7] Enhance cooperation with S-Miles Cloud --- src/bin/hms-mqtt-publish/main.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index 3d8ca170..0c0abee2 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -14,7 +14,7 @@ use rumqttc_wrapper::RumqttcWrapper; use serde_derive::Deserialize; use std::fs; use std::thread; -use std::time::Duration; +use std::time::{SystemTime, UNIX_EPOCH, Duration}; use log::{error, info}; @@ -84,6 +84,20 @@ fn main() { } loop { + let now = SystemTime::now(); + let duration_since_epoch = now.duration_since(UNIX_EPOCH).unwrap(); + let seconds_since_epoch = duration_since_epoch.as_secs(); + + let seconds_in_current_minute = seconds_since_epoch % 60; + let minutes_since_epoch = seconds_since_epoch / 60; + let minutes_in_current_hour = minutes_since_epoch % 60; + + // This is the time at which the S-Miles update seems to take place + // Adding some extra time before and after, in which we dont publish + if minutes_in_current_hour % 15 == 14 && seconds_in_current_minute >= 15 { + thread::sleep(Duration::from_millis(5000 + (60 - seconds_in_current_minute)* 1000)); + } + if let Some(r) = inverter.update_state() { output_channels.iter_mut().for_each(|channel| { channel.publish(&r); From 4a7b54a465b7216cfb753b3ebf62a40edff56736 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 17 Mar 2024 10:54:29 +0100 Subject: [PATCH 2/7] Cooperative Mode for S-Miles cloud with parameter --- src/bin/hms-mqtt-publish/main.rs | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index 0c0abee2..b2b37c61 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -22,6 +22,7 @@ use log::{error, info}; struct Config { inverter_host: String, update_interval: Option, + smiles_cooperation: bool, home_assistant: Option, simple_mqtt: Option, } @@ -83,19 +84,26 @@ fn main() { output_channels.push(Box::new(SimpleMqtt::::new(&config))); } + if config.smiles_cooperation { + info!("S-Miles cloud cooperative mode enabled"); + } + loop { - let now = SystemTime::now(); - let duration_since_epoch = now.duration_since(UNIX_EPOCH).unwrap(); - let seconds_since_epoch = duration_since_epoch.as_secs(); - - let seconds_in_current_minute = seconds_since_epoch % 60; - let minutes_since_epoch = seconds_since_epoch / 60; - let minutes_in_current_hour = minutes_since_epoch % 60; - - // This is the time at which the S-Miles update seems to take place - // Adding some extra time before and after, in which we dont publish - if minutes_in_current_hour % 15 == 14 && seconds_in_current_minute >= 15 { - thread::sleep(Duration::from_millis(5000 + (60 - seconds_in_current_minute)* 1000)); + // Do not query the inverter when the S-Miles cloud is about to update + if config.smiles_cooperation { + let now = SystemTime::now(); + let duration_since_epoch = now.duration_since(UNIX_EPOCH).unwrap(); + let seconds_since_epoch = duration_since_epoch.as_secs(); + + let seconds_in_current_minute = seconds_since_epoch % 60; + let minutes_since_epoch = seconds_since_epoch / 60; + let minutes_in_current_hour = minutes_since_epoch % 60; + + // This is the time at which the S-Miles update seems to take place + // Adding some extra time before and after, in which we dont publish + if minutes_in_current_hour % 15 == 14 { + thread::sleep(Duration::from_millis((15 + 60 - seconds_in_current_minute) * 1000)); + } } if let Some(r) = inverter.update_state() { From 61bf1ae9992b9c386a27ad839ead52dbaea549e8 Mon Sep 17 00:00:00 2001 From: gendelo3 Date: Sun, 17 Mar 2024 10:55:58 +0100 Subject: [PATCH 3/7] Cooperative Mode for S-Miles cloud with parameter --- config.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/config.toml b/config.toml index fcb6dc53..682a4aba 100644 --- a/config.toml +++ b/config.toml @@ -1,5 +1,6 @@ inverter_host = "192.168.4.182" update_interval = 30500 +smiles_cooperation = false [home_assistant] host = "192.168.178.250" From 5db092c99aa77daff82c89a351a49448ed4839e6 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sun, 17 Mar 2024 11:04:58 +0100 Subject: [PATCH 4/7] Cooperative Mode for S-Miles cloud with parameter --- src/bin/hms-mqtt-publish/main.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index b2b37c61..54703b01 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -14,7 +14,7 @@ use rumqttc_wrapper::RumqttcWrapper; use serde_derive::Deserialize; use std::fs; use std::thread; -use std::time::{SystemTime, UNIX_EPOCH, Duration}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; use log::{error, info}; @@ -102,7 +102,9 @@ fn main() { // This is the time at which the S-Miles update seems to take place // Adding some extra time before and after, in which we dont publish if minutes_in_current_hour % 15 == 14 { - thread::sleep(Duration::from_millis((15 + 60 - seconds_in_current_minute) * 1000)); + thread::sleep(Duration::from_millis( + (15 + 60 - seconds_in_current_minute) * 1000, + )); } } From fbb725c7eb62da18044bb645b720470328d287cb Mon Sep 17 00:00:00 2001 From: gendelo3 Date: Sun, 17 Mar 2024 14:52:41 +0100 Subject: [PATCH 5/7] Update src/bin/hms-mqtt-publish/main.rs Co-authored-by: Dennis Luxen --- src/bin/hms-mqtt-publish/main.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index 54703b01..22c3a7ca 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -84,7 +84,12 @@ fn main() { output_channels.push(Box::new(SimpleMqtt::::new(&config))); } - if config.smiles_cooperation { + if config + .smiles_cooperation + .is_some_and(|value| value) { + info!("S-Miles cloud cooperative mode enabled"); + } + { info!("S-Miles cloud cooperative mode enabled"); } From 20a325af00f4c5af64e26413ba72ef3e528a5b36 Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 18 Mar 2024 17:40:45 +0100 Subject: [PATCH 6/7] SMiles-Cooperation as an optional parameter --- src/bin/hms-mqtt-publish/main.rs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index 22c3a7ca..ef33b2db 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -22,7 +22,7 @@ use log::{error, info}; struct Config { inverter_host: String, update_interval: Option, - smiles_cooperation: bool, + smiles_cooperation: Option, home_assistant: Option, simple_mqtt: Option, } @@ -84,18 +84,16 @@ fn main() { output_channels.push(Box::new(SimpleMqtt::::new(&config))); } - if config - .smiles_cooperation - .is_some_and(|value| value) { - info!("S-Miles cloud cooperative mode enabled"); - } + if config.smiles_cooperation.is_some_and(|value| value) { + info!("S-Miles cloud cooperative mode enabled"); + } { info!("S-Miles cloud cooperative mode enabled"); } loop { // Do not query the inverter when the S-Miles cloud is about to update - if config.smiles_cooperation { + if config.smiles_cooperation.is_some_and(|value| value) { let now = SystemTime::now(); let duration_since_epoch = now.duration_since(UNIX_EPOCH).unwrap(); let seconds_since_epoch = duration_since_epoch.as_secs(); From 7e966d2127fcdb7b46d887f041573fcc8a1cd7a1 Mon Sep 17 00:00:00 2001 From: gendelo3 Date: Wed, 17 Apr 2024 11:18:47 +0200 Subject: [PATCH 7/7] Update src/bin/hms-mqtt-publish/main.rs Co-authored-by: Dennis Luxen --- src/bin/hms-mqtt-publish/main.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/bin/hms-mqtt-publish/main.rs b/src/bin/hms-mqtt-publish/main.rs index ef33b2db..eca29379 100644 --- a/src/bin/hms-mqtt-publish/main.rs +++ b/src/bin/hms-mqtt-publish/main.rs @@ -86,9 +86,8 @@ fn main() { if config.smiles_cooperation.is_some_and(|value| value) { info!("S-Miles cloud cooperative mode enabled"); - } - { - info!("S-Miles cloud cooperative mode enabled"); + } else { + info!("S-Miles cloud cooperative mode disabled"); } loop {