diff --git a/config/config.toml b/config/config.toml index 473dcce..266b5c5 100644 --- a/config/config.toml +++ b/config/config.toml @@ -87,3 +87,4 @@ presence = { timeout = 900 } [devices.bathroom_washer] type = "Washer" topic = "zigbee2mqtt/bathroom/washer" +threshold = 2 diff --git a/config/zeus.dev.toml b/config/zeus.dev.toml index fec6064..df1701d 100644 --- a/config/zeus.dev.toml +++ b/config/zeus.dev.toml @@ -88,3 +88,4 @@ lights = { lights = ["bathroom_light"], timeout = 10 } [devices.bathroom_washer] type = "Washer" topic = "zigbee2mqtt/bathroom/washer" +threshold = 2 diff --git a/src/devices/washer.rs b/src/devices/washer.rs index c518e49..d701c28 100644 --- a/src/devices/washer.rs +++ b/src/devices/washer.rs @@ -1,7 +1,7 @@ use async_trait::async_trait; use rumqttc::{AsyncClient, Publish}; use serde::Deserialize; -use tracing::{error, warn}; +use tracing::{debug, error, warn}; use crate::{ config::{CreateDevice, MqttDeviceConfig}, @@ -17,6 +17,7 @@ use super::{ntfy::Priority, Device, Notification}; pub struct WasherConfig { #[serde(flatten)] mqtt: MqttDeviceConfig, + threshold: f32, // Power in Watt } // TODO: Add google home integration @@ -27,6 +28,7 @@ pub struct Washer { mqtt: MqttDeviceConfig, event_channel: EventChannel, + threshold: f32, running: bool, } @@ -46,6 +48,7 @@ impl CreateDevice for Washer { identifier: identifier.to_owned(), mqtt: config.mqtt, event_channel: event_channel.clone(), + threshold: config.threshold, running: false, }) } @@ -72,8 +75,12 @@ impl OnMqtt for Washer { } }; - if self.running && power < 1.0 { - // The washer is done running + if self.running && power < self.threshold { + debug!( + id = self.identifier, + power, self.threshold, "Washer is done" + ); + self.running = false; let notification = Notification::new() .set_title("Laundy is done") @@ -90,8 +97,12 @@ impl OnMqtt for Washer { { warn!("There are no receivers on the event channel"); } - } else if !self.running && power >= 1.0 { - // We just started washing + } else if !self.running && power >= self.threshold { + debug!( + id = self.identifier, + power, self.threshold, "Washer is starting" + ); + self.running = true } }