Washing Machine State Machine

My Sonoff Pow (or my Washing Machine, or my Dryer?) detects some peaks, even if the program is finished. Partly because they machine perfome some “anti-crease” actions to prevent the laundry to get knitted. partly because of some internal measuring effects of the Pow.

So I came up with an different approach for detecting the machine states: If you’re using persistance, why not use historic data for this. So I use the item.averageSince(AbstractInstant) extension to get an average of the last minutes to check, if there’s just noise or if it’s really a change of state:

so my rule ended up like this:

val Number MODE_OFF = 0
val Number MODE_STANDBY = 1
val Number MODE_ACTIVE = 2
val Number MODE_FINISHED = 3

rule "Washingmachine Consumption State Machine"
when
    Item Washingmachine_Power changed
then
    if (Washingmachine_Power.averageSince(now.minusMinutes(2)) < 0.2) Washingmachine_OpState.postUpdate(MODE_OFF)
    else if (Washingmachine_Power.averageSince(now.minusMinutes(2))> 10) Washingmachine_OpState.postUpdate(MODE_ACTIVE)
    else if (Washingmachine_Power.averageSince(now.minusMinutes(2))< 5) {
        if (Washingmachine_OpState.state == MODE_OFF) Washingmachine_OpState.postUpdate(MODE_STANDBY)
        else if (Washingmachine_OpState.state == MODE_ACTIVE) Washingmachine_OpState.postUpdate(MODE_FINISHED)
    }
end
3 Likes