Added mechanism to prevent false positives
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
bb131f2b1a
commit
27ef78e132
|
@ -95,4 +95,4 @@ lights = { lights = ["hallway_light"], timeout = 60 }
|
|||
[devices.bathroom_washer]
|
||||
type = "Washer"
|
||||
topic = "zigbee2mqtt/bathroom/washer"
|
||||
threshold = 1.2
|
||||
threshold = 1
|
||||
|
|
|
@ -95,4 +95,4 @@ lights = { lights = ["hallway_light"], timeout = 10 }
|
|||
[devices.bathroom_washer]
|
||||
type = "Washer"
|
||||
topic = "zigbee2mqtt/bathroom/washer"
|
||||
threshold = 1.2
|
||||
threshold = 1
|
||||
|
|
|
@ -29,7 +29,7 @@ pub struct Washer {
|
|||
|
||||
event_channel: EventChannel,
|
||||
threshold: f32,
|
||||
running: bool,
|
||||
running: isize,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
|
@ -49,7 +49,7 @@ impl CreateDevice for Washer {
|
|||
mqtt: config.mqtt,
|
||||
event_channel: event_channel.clone(),
|
||||
threshold: config.threshold,
|
||||
running: false,
|
||||
running: 0,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -60,6 +60,11 @@ impl Device for Washer {
|
|||
}
|
||||
}
|
||||
|
||||
// The washer needs to have a power draw above the theshold multiple times before the washer is
|
||||
// actually marked as running
|
||||
// This helps prevent false positives
|
||||
const HYSTERESIS: isize = 3;
|
||||
|
||||
#[async_trait]
|
||||
impl OnMqtt for Washer {
|
||||
fn topics(&self) -> Vec<&str> {
|
||||
|
@ -75,13 +80,18 @@ impl OnMqtt for Washer {
|
|||
}
|
||||
};
|
||||
|
||||
if self.running && power < self.threshold {
|
||||
debug!(id = self.identifier, power, "Washer state update");
|
||||
|
||||
if power < self.threshold && self.running >= HYSTERESIS {
|
||||
// The washer is done running
|
||||
debug!(
|
||||
id = self.identifier,
|
||||
power, self.threshold, "Washer is done"
|
||||
power,
|
||||
threshold = self.threshold,
|
||||
"Washer is done"
|
||||
);
|
||||
|
||||
self.running = false;
|
||||
self.running = 0;
|
||||
let notification = Notification::new()
|
||||
.set_title("Laundy is done")
|
||||
.set_message("Don't forget to hang it!")
|
||||
|
@ -97,13 +107,19 @@ impl OnMqtt for Washer {
|
|||
{
|
||||
warn!("There are no receivers on the event channel");
|
||||
}
|
||||
} else if !self.running && power >= self.threshold {
|
||||
} else if power < self.threshold {
|
||||
// Prevent false positives
|
||||
self.running = 0;
|
||||
} else if power >= self.threshold && self.running < HYSTERESIS {
|
||||
// Washer could be starting
|
||||
debug!(
|
||||
id = self.identifier,
|
||||
power, self.threshold, "Washer is starting"
|
||||
power,
|
||||
threshold = self.threshold,
|
||||
"Washer is starting"
|
||||
);
|
||||
|
||||
self.running = true
|
||||
self.running += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user