Washing Machine State Machine

Hello,
I’ve tried every solution given in this tutorial but for some reason i had no success. This could also be due to cheap “Tuya SP23” that loves to report 0W between the cycles when power drop from 1000w to 1w.
It may be me that didn’t have success with InfluxDb but in Grafana i can see everything.
Long story short…I took simplified version of the tutorial and i added timers to confirm if the power is constant or was just a spike, if it was a spike then the timer gets cancelled and is waiting for the next power drop.
the two variables on top represents the gaps between cycles.
this it works for me and i would like to share with others if helpful but i would like an opinion from someone with more experience if can be polished or it’s bad way of doing
I’ve left logInfo to help debug until timings are identified and working as intended
Washingmachine.rules

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

val Washingmachine_Timer_1_Delay_sec  = 15
val Washingmachine_Timer_2_Delay_sec  = 21 //time off between cycles

var Timer Washingmachine_Timer_1       // timer < 0.5 W
var Timer Washingmachine_Timer_2       // timer < 3.5 W

rule "Washingmachine Consumption State Machine"
when
    Item Power4 changed
then
    if (Power4.state < 0.5){ 
        if (Washingmachine_Timer_1 === null) {
            Washingmachine_Timer_1 = createTimer(now.plusSeconds(Washingmachine_Timer_1_Delay_sec), [ |
                logInfo("Washingmachine Timer1", "Started < 0.5 W")
                if (Power4.state < 0.5){ 
                        Washingmachine_OpState.postUpdate(MODE_OFF) 
                        Washingmachine_Timer_1 = null  // Cancels the timer 1 when run out
                        logInfo("Washingmachine Timer1", "MODE_OFF < 0.5 W")
                }
                else if (Power4.state > 0.5){
                    if (Washingmachine_Timer_1 !== null) {  //// Cancels the timer 2 when Power4 > 3.5 W
                    Washingmachine_Timer_1.cancel()
                    Washingmachine_Timer_1 = null
                    logInfo("Washingmachine Timer1", "Canceled >0.5 W")
                    }
                }
            ])
            
        }
    }        
        
    else if (Power4.state > 3.5) {
                Washingmachine_OpState.postUpdate(MODE_ACTIVE)
                if (Washingmachine_Timer_1 !== null) {  //// Cancels the timer 1 when Power4 > 3.5 W
                    Washingmachine_Timer_1.cancel()
                    Washingmachine_Timer_1 = null
                    logInfo("Washingmachine Timer1", "Canceled > 3.5 W")
                }
                else if (Washingmachine_Timer_2 !== null) {  //// Cancels the timer 2 when Power4 > 3.5 W
                    Washingmachine_Timer_2.cancel()
                    Washingmachine_Timer_2 = null
                    logInfo("Washingmachine Timer2", "Canceled > 3.5 W")
                }

    }
    else if (Power4.state < 3.5) {
        if (Washingmachine_Timer_2 === null) {
            Washingmachine_Timer_2 = createTimer(now.plusSeconds(Washingmachine_Timer_2_Delay_sec), [ |
                if (Power4.state < 3.5) { 
                        logInfo("Washingmachine Timer2", "Started < 3.5 W")
                        if (Washingmachine_OpState.state == MODE_OFF){
                            Washingmachine_OpState.postUpdate(MODE_STANDBY)
                            Washingmachine_Timer_2 = null  // Cancels the timer 2 when run out
                            logInfo("Washingmachine Timer2", "Standby after MODE_OFF ")
                            }
                        else if (Washingmachine_OpState.state == MODE_ACTIVE){
                            Washingmachine_OpState.postUpdate(MODE_FINISHED) 
                            Washingmachine_Timer_2 = null  // Cancels the timer 2 when run out
                            logInfo("Washingmachine Timer2", "Finished after MODE_FINISHED ")
                            }
                    }
                else if (Power4.state > 3.5){
                    if (Washingmachine_Timer_2 !== null) {  //// Cancels the timer 2 when Power4 > 3.5 W
                    Washingmachine_Timer_2.cancel()
                    Washingmachine_Timer_2 = null
                    logInfo("Washingmachine Timer2", "Canceled >3.5 W")
                    }
                    else if (Washingmachine_Timer_1 !== null) {  //// Cancels the timer 1 when Power4 > 3.5 W
                    Washingmachine_Timer_1.cancel()
                    Washingmachine_Timer_1 = null
                    logInfo("Washingmachine Timer1", "Canceled > 3.5 W")
                    }  
                }
            ])
                
        }
    }
end