Washing Machine State Machine

Rules DSL has some odd quirks, one of them is guessing what a character is about based on what came before. Here, it’s ambiguous … the < may be the less-than operator, or the first of a pair as in <QuantityType>.

You need to give it a clue. Knowing the preceding thing was a Number would be enough … but here, it isn’t a Number it’s an Item state object.

Boils down to
( (BW1_Power.state as Number) < 0.4)

i understand your explanation, but have same issue

no change on “<”

forgot to mention

else if (BW1_Power.averageSince(now.minusMinutes(3), "influxdb") < 5){

in this line is the error of <

got it with your hint

else if ((BW1_Power.averageSince(now.minusMinutes(3))as Number) < 5){

Hi,
just switching to OH3 and trying to port my wasching maschine rule and just not getting anywhere. Since it is a must for switching to OH3 because of the WAF I would appreciate your help.

Here is what I tried so far:
First attemt:

  1. created Item to get my measuerments: WasherCEUtilityroom_Power and put that in the modell
    This works so I see the W when the maschine is running
  2. created the Washer_OpState_CE_Utilityroom item
  3. Copied the old rule to the rules folder
    Result: Washer_OpState_CE_Utilityroom stays at NULL

Second attemt:
3. Created a new rule via UI and put in the script part:

Summary

This text will be hidden

if (WasherCEUtilityroom_Power.state < 0.2) Washer_OpState_CE_Utilityroom.postUpdate(0)
    else if (WasherCEUtilityroom_Power.state > 7) Washer_OpState_CE_Utilityroom.postUpdate(2)
    else if (WasherCEUtilityroom_Power.state < 2.5) {
        if (Washer_OpState_CE_Utilityroom.state == 0) Washer_OpState_CE_Utilityroom.postUpdate(1)
        else if (Washer_OpState_CE_Utilityroom.state == 2) Washer_OpState_CE_Utilityroom.postUpdate(3)
    }

Result: Washer_OpState_CE_Utilityroom stays at NULL

Would be grateful if anybody can push me in the right direction.

What kind of Item? What values do you see? This makes a difference about how you perform if() comparisons on it’s state.

It’s a Number:Power Item created via UI. The values are stated in WATTS. Is it possible that the conversion to W is the problem?

Yes, it’s the units.

So … less than 0.2 mW? 0.2kW? To compare with your state “xx W”, you need to be comparing to something with units as well.
You can use units in a constant with a | pipe character

if (WasherCEUtilityroom_Power.state < 0.2 | W)
or, exactly the same,
if (WasherCEUtilityroom_Power.state < 200 | mW)
it doesn’t matter, openHAB takes care of any scaling.

2 Likes

Yep the | W did the trick.

Thank you very much! Another lesson learned!

I migrated this template from OH 2.5 to OH 3.1.

The rule is only working partly now, it triggers only State 0 and State 2. But not State 1 or State 3, even though the Watt numbers are coming correctly from my Fibaro Plug.

Rule:

val Number MODE_OFF = 0
val Number MODE_STANDBY = 1
val Number MODE_ACTIVE = 2
val Number MODE_FINISHED = 3
  
if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state < 1.0) WasherOpState.postUpdate(MODE_OFF)
    else if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state > 28.0) WasherOpState.postUpdate(MODE_ACTIVE)
    else if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state < 2.0) {
        if (WasherOpState.state == MODE_OFF) WasherOpState.postUpdate(MODE_STANDBY)
        else if (WasherOpState.state == MODE_ACTIVE) WasherOpState.postUpdate(MODE_FINISHED)
    }```

And here should be the trigger to change from State 2 to State 3, as Wattage is falling below 2.
2021-07-08 15:44:07.681 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower’ changed from 2.7 to 2.4

2021-07-08 15:44:08.681 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower’ changed from 2.4 to 2

2021-07-08 15:44:09.680 [INFO ] [openhab.event.ItemStateChangedEvent ] - Item ‘ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower’ changed from 2 to 1.7

Only if other conditions are met too. Log out the states of your Items before entering the if() to figure out what is going on, and to make sure the rule runs when you think it should.

I’m surprised your zwave power is not reported with units.

It’s fixed now. Issue was - I guess - that WasherOpState was not of type “Number”.
If it helps, below my rule that I enriched with some logInfos.

val Number MODE_OFF = 0
val Number MODE_STANDBY = 1
val Number MODE_ACTIVE = 2
val Number MODE_FINISHED = 3
logInfo("Washingmachine Consumption State Machine","I am running this rule")
  
if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state < 1.0 | W) {
   WasherOpState.postUpdate(MODE_OFF) 
   logInfo("Washingmachine Consumption State Machine","Washer is OFF")
} else if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state > 28.0 | W) {
    WasherOpState.postUpdate(MODE_ACTIVE)
    logInfo("Washingmachine Consumption State Machine","Washer is ON")
    } else if (ZWaveNode011FGWP101MeteredWallPlugSwitch_Sensorpower.state < 2.2 | W) {
        logInfo("Washingmachine Consumption State Machine","I am now checking if it's STANDBY or FINISHED (Status "+WasherOpState.state+")")
        if (WasherOpState.state == MODE_OFF) {
          logInfo("Washingmachine Consumption State Machine","Washer is STANDBY as it has been OFF before")  
          WasherOpState.postUpdate(MODE_STANDBY)
        } else if (WasherOpState.state == MODE_ACTIVE) {
          WasherOpState.postUpdate(MODE_FINISHED)
          logInfo("Washingmachine Consumption State Machine","Washer is FINISHED as it was ACTIVE before")
        } else {
          logInfo("Washingmachine Consumption State Machine","I did not enter here")
        }
    }
1 Like

@binderth
I’m trying to get this one working on openHAB 3.2

Unfortunately, vsCode shows some errors related to the operators:

ambiguous binary operation. the operator declarations operator_lessthan(number, number) in numberextensions and operator_lessthan(type, number) in numberextensions both match.

Did you run your rule already? What did the logs say?
I can’t think of why this rule would have issues with the operators…

Since I moved my rules to JS Scripting, I don’t have those DSL rule running anymore… :slight_smile:

Ouch, I forgot to persist the socket.

The rule is running but for some reason, it didn’t switch to “MODE_OFF” (0) - It’s still at 3 even though the machine isn’t consuming any power.

Found this add-on via market place. I do something like this by myself, but with some rules and items. On my investigations I wasn’t very satisfy with power measurements. In most cases some power plugs devices don’t show the real power, but a current. Everything under 1W aren’t really helpful. I realize that with current and get the bests results. I miss that in this add-on.