class PlaceOS::Driver::Presence::Smoother

Overview

Smooths the output of an unreliable presence sensor over a sliding time window, latching the state and only switching once the opposing signal dominates the window. Compose one instance per sensor.

Defined in:

placeos-driver/interface/presence_smoother.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(window : Time::Span = 3.minutes, threshold : Float64 = 0.70) #

[View source]

Instance Method Detail

def confidence(now : Time::Instant = Time.instant) : Float64 | Nil #

Returns confidence in the current smoothed output state, from 0.0 to 1.0.

Calling this also evaluates whether the smoothed state should change.


[View source]
def confidence_percent(now : Time::Instant = Time.instant) : Float64 | Nil #

Returns confidence in the current smoothed output state as a percentage.

For example, 56.3 means 56.3% confidence.


[View source]
def observe(state : Bool, at : Time::Instant = Time.instant) : Nil #

Records a raw sensor state.

The first observation establishes the initial smoothed output state. Repeated observations of the same state are ignored because the state continues accumulating time without requiring another transition.


[View source]
def output_state : Bool | Nil #

[View source]
def poll(now : Time::Instant = Time.instant) : Snapshot | Nil #

Evaluates the current sliding window and returns the smoothed state, confidence and supporting information.

Returns nil until the first sensor observation.


[View source]
def raw_state : Bool | Nil #

[View source]