Made washer power threshold configurable
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
ee00959e8a
commit
7f89780696
|
@ -87,3 +87,4 @@ presence = { timeout = 900 }
|
||||||
[devices.bathroom_washer]
|
[devices.bathroom_washer]
|
||||||
type = "Washer"
|
type = "Washer"
|
||||||
topic = "zigbee2mqtt/bathroom/washer"
|
topic = "zigbee2mqtt/bathroom/washer"
|
||||||
|
threshold = 2
|
||||||
|
|
|
@ -88,3 +88,4 @@ lights = { lights = ["bathroom_light"], timeout = 10 }
|
||||||
[devices.bathroom_washer]
|
[devices.bathroom_washer]
|
||||||
type = "Washer"
|
type = "Washer"
|
||||||
topic = "zigbee2mqtt/bathroom/washer"
|
topic = "zigbee2mqtt/bathroom/washer"
|
||||||
|
threshold = 2
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use rumqttc::{AsyncClient, Publish};
|
use rumqttc::{AsyncClient, Publish};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use tracing::{error, warn};
|
use tracing::{debug, error, warn};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::{CreateDevice, MqttDeviceConfig},
|
config::{CreateDevice, MqttDeviceConfig},
|
||||||
|
@ -17,6 +17,7 @@ use super::{ntfy::Priority, Device, Notification};
|
||||||
pub struct WasherConfig {
|
pub struct WasherConfig {
|
||||||
#[serde(flatten)]
|
#[serde(flatten)]
|
||||||
mqtt: MqttDeviceConfig,
|
mqtt: MqttDeviceConfig,
|
||||||
|
threshold: f32, // Power in Watt
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Add google home integration
|
// TODO: Add google home integration
|
||||||
|
@ -27,6 +28,7 @@ pub struct Washer {
|
||||||
mqtt: MqttDeviceConfig,
|
mqtt: MqttDeviceConfig,
|
||||||
|
|
||||||
event_channel: EventChannel,
|
event_channel: EventChannel,
|
||||||
|
threshold: f32,
|
||||||
running: bool,
|
running: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -46,6 +48,7 @@ impl CreateDevice for Washer {
|
||||||
identifier: identifier.to_owned(),
|
identifier: identifier.to_owned(),
|
||||||
mqtt: config.mqtt,
|
mqtt: config.mqtt,
|
||||||
event_channel: event_channel.clone(),
|
event_channel: event_channel.clone(),
|
||||||
|
threshold: config.threshold,
|
||||||
running: false,
|
running: false,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -72,8 +75,12 @@ impl OnMqtt for Washer {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if self.running && power < 1.0 {
|
if self.running && power < self.threshold {
|
||||||
// The washer is done running
|
debug!(
|
||||||
|
id = self.identifier,
|
||||||
|
power, self.threshold, "Washer is done"
|
||||||
|
);
|
||||||
|
|
||||||
self.running = false;
|
self.running = false;
|
||||||
let notification = Notification::new()
|
let notification = Notification::new()
|
||||||
.set_title("Laundy is done")
|
.set_title("Laundy is done")
|
||||||
|
@ -90,8 +97,12 @@ impl OnMqtt for Washer {
|
||||||
{
|
{
|
||||||
warn!("There are no receivers on the event channel");
|
warn!("There are no receivers on the event channel");
|
||||||
}
|
}
|
||||||
} else if !self.running && power >= 1.0 {
|
} else if !self.running && power >= self.threshold {
|
||||||
// We just started washing
|
debug!(
|
||||||
|
id = self.identifier,
|
||||||
|
power, self.threshold, "Washer is starting"
|
||||||
|
);
|
||||||
|
|
||||||
self.running = true
|
self.running = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user