Washing machine status widget

Not sure - is the item type 'Number:Type’ for _Remainingprogramtime?

Just a thought for people who have a washdryer combo: Would it be possible to introduce another state “DRYING” (next to OFF, RUNNING or FINISHED) and then automatically switch Dryer Mode to ON?

Good idea. But you should be able to do this without any changes to the widget: just use an expression for the dryer mode configuration and you should be fine :slight_smile:

Currently I have:

component: widget:washing_machine_v4
config:
  title: LG WashDryer
  state: =MQTTThinQ_WashDryerState.state
  runtime: =openHAB2_ItemThinqRemainingminutes.state
  dryer: =openHAB2_ItemThinqDrying.state

openHAB2_ItemThinqDrying is a switch but unfortunately it doesn’t work… Does it need to be a string?

Unfortunately it has to be a string yes. This is because I only use this as a static configuration without an item at all. You could remove the string literals in the widget code where checks for the dryer mode are implemented or use an expression that evaluates to a string based on your switch item.

I changed everything to String now but it seems it doesn’t read the state correctly… Also a .toString() at the end didn’t help… I will look at the widget source - maybe I can track down the problem…

You should use: items.openHAB2_ItemThinqDrying.state

It should work then I guess

Arg… I always do the same mistake! Thanks! :slight_smile:

sorry for the basic question, I would like to use your code, coincidentally I have some problems.
My main problem is, where did I have to put this format of code ?
I’ve created a rule with the OH3 Page and selected Rule DSL → with this, I ran into serious problems, is there an addon missing?
Or am I not seeing my fault ?

seconds question, → EnableLog_WaschmaschineRules is only an Item that can be set OFF and ON manually for debugging issues?

Script execution of rule with UID 'Laufzeit_Spuelmaschine' failed: configuration: null

also shown inside the log viewer

triggers:

  - id: "1"

    configuration:

      itemName: S4_Power

    type: core.ItemStateChangeTrigger

conditions: []

actions:

  - inputs: null

    id: "2"

    configuration:

      type: application/vnd.openhab.dsl.rule

      script: >-

        val Number MODE_OFF = 0

        val Number MODE_STANDBY = 1

        val Number MODE_ACTIVE = 2

        val Number MODE_FINISHED = 3

        val String logPrefix = 'Waschmaschine StateMachine - '

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('waschmaschine.rules', logPrefix + 'StateMachine Zustand alt: ' + Washingmachine_OpState.state.toString + '; Leistung momentan: '+ S4_Power.state.toString)

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('waschmaschine.rules', logPrefix + 'Leistung momentan (doubleValue): '+ (S4_Power.state as QuantityType<Power>).doubleValue.toString)

        if ((S4_Power.state as QuantityType<Power>).doubleValue < 0.5) {

          Waschmaschine_OpState.postUpdate(MODE_OFF)

        }

        else if ((S4_Power.state as QuantityType<Power>).doubleValue > 15) {

          if (Washingmachine_OpState.state != MODE_ACTIVE) {

            Washingmachine_OpState.postUpdate(MODE_ACTIVE)

            Waschmaschine_Runtime.postUpdate(1)

          }

        }

        else if ((S4_Power.state as QuantityType<Power>).doubleValue < 6.5) {

            if (Washingmachine_OpState.state == MODE_OFF) Washingmachine_OpState.postUpdate(MODE_STANDBY)

            else if (Washingmachine_OpState.state == MODE_ACTIVE) Washingmachine_OpState.postUpdate(MODE_FINISHED)

        }

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('waschmaschine.rules', logPrefix + 'StateMachine Zustand neu: ' + Washingmachine_OpState.state.toString)

    type: script.ScriptAction

Hi @Kahzia,

your initial way in creating a rule is quite correct.
You also have the possibility to add the rule directly with the code. Just click on the „Code“ tab on the top right area after clicking the „+“ for creating a new rule. Then paste the code into this box instead of the shown content (rule template).

What problems did you experience?
Can you name them or give more info on them?

Yes, I have for all rules such log enable switches, just to have my log viewer a bit cleaner when everything is running smoothly :grinning:.
So the script will fail as long as you have this item not available.
For now just remove the containing line from the script.

Cheers
Jonathan

thanks for the fast reply :slight_smile: @elektrolubach ,

oh wow… my bad… thanks for that hint =)
unfortunately, the error occurs again for me, I think there is something wrong with a definition from my item.

Error:

2022-08-04 01:07:30.981 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'Laufzeit_Spuelmaschine' failed: Could not cast 0 to org.openhab.core.library.types.QuantityType; line 8, column 6, length 37

Code:

configuration: {}
triggers:
  - id: "1"
    configuration:
      itemName: S4_Power
    type: core.ItemStateChangeTrigger
conditions: []
actions:
  - inputs: {}
    id: "2"
    configuration:
      type: application/vnd.openhab.dsl.rule
      script: >-
        val Number MODE_OFF = 0 

        val Number MODE_STANDBY = 1 

        val Number MODE_ACTIVE = 2 

        val Number MODE_FINISHED = 3 

        val String logPrefix = 'Waschmaschine StateMachine - '

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('Lafuzeit_Spuelmaschine.rules', logPrefix + 'StateMachine Zustand alt: ' + Washingmachine_OpState.state.toString + '; Leistung momentan: '+ S4_Power.state.toString)

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('Lafuzeit_Spuelmaschine.rules', logPrefix + 'Leistung momentan (doubleValue): '+ (S4_Power.state as QuantityType<Power>).doubleValue.toString)


        if ((S4_Power.state as QuantityType<Power>).doubleValue < 0.5) {
          Washingmachine_OpState.postUpdate(MODE_OFF)
        }

        else if ((S4_Power.state as QuantityType<Power>).doubleValue > 15) {
          if (Washingmachine_OpState.state != MODE_ACTIVE) {
            Washingmachine_OpState.postUpdate(MODE_ACTIVE)
            dishwasher_machine_runtime.postUpdate(1)
          }
        }

        else if ((S4_Power.state as QuantityType<Power>).doubleValue < 6.5) {
            if (Washingmachine_OpState.state == MODE_OFF) Washingmachine_OpState.postUpdate(MODE_STANDBY)
            else if (Washingmachine_OpState.state == MODE_ACTIVE) Washingmachine_OpState.postUpdate(MODE_FINISHED)
        }

        if (EnableLog_WaschmaschineRules.state == ON) logInfo('Lafuzeit_Spuelmaschine.rules', logPrefix + 'StateMachine Zustand neu: ' + Washingmachine_OpState.state.toString)
    type: script.ScriptAction

There are quite a few threads about handling of quantity types in the forums. I suggest to look there or open a new thread because it is very likely that people that may be able to answer your question are not observing this thread.

@DrRSatzteil
okay back to basic, I’ve now struggling for days to get this work :smiley:
I’ll start from scratch with it, the other script which was posted here is not working for me, and also not with the good hint from my other thread.

So the main reason why I switched to the other script was, that I’ve got a similar op_state rule running which I wanted to implement.
Now I am helpless and unable to find my own mistakes…

just to make it right, your posted script:

var threshold = new QuantityType("5 W")
var zero = new QuantityType("0.1 W")
if (newState <= zero) {
 events.sendCommand('washing_machine_state', 'Aus')
} else if (newState >= threshold  && oldState < threshold) {
 events.sendCommand('washing_machine_state', 'Waschvorgang')
 events.sendCommand('washing_machine_runtime', 1)
} else if (newState < threshold  && oldState >= threshold) {
 events.sendCommand('washing_machine_state', 'Waschvorgang beendet')
}

needs to add to the rule → add action → run script → Rule DSL
Does the “newState” need to adapt to my consumption item correctly?
I don’t get what QuantityType does.
The Error I get every time using this is:

var zero = new QuantityType("0.1 W")

if (S4_Power.state <= zero) {

  events.sendCommand('washing_machine_state', 'Aus')

} else if (S4_Power.state >= threshold  && oldState < threshold) {

  events.sendCommand('washing_machine_state', 'Waschvorgang')

  events.sendCommand('dishwasher_machine_runtime', 1)

} else if (S4_Power.state < threshold  && oldState >= threshold) {

  events.sendCommand('washing_machine_state', 'Waschvorgang beendet')

}

   1. The method or field events is undefined; line 5, column 110, length 6

   2. The method or field oldState is undefined; line 6, column 204, length 8

   3. The method or field events is undefined; line 7, column 230, length 6

   4. The method or field events is undefined; line 8, column 292, length 6

   5. The method or field oldState is undefined; line 9, column 386, length 8

   6. The method or field events is undefined; line 10, column 413, length 6

   7. Bounds mismatch: The type argument <Quantity<?>> is not a valid substitute for the bounded type parameter <T extends Quantity<T>> of the constructor QuantityType<T>(String); line 1, column 20, length 12

   8. Bounds mismatch: The type argument <Quantity<?>> is not a valid substitute for the bounded type parameter <T extends Quantity<T>> of the constructor QuantityType<T>(String); line 2, column 55, length 12

All Items existing and can reach the expected values → test with openhab:update via console
I don’t find the problem, why are nearly “all” methods / files undefined. Also I tried to fill the machine state with “Waschvorgang” and “aus” cause I thought there must be set at least one time… but that didn’t work.

Hopefully, u have mercy on me and can help me a bit with this :slight_smile:

Hi,

I think the problem should be easy to solve: do not use a DSL script action but a JavaScript action. Maybe I forgot to mention that?! :scream_cat:

Please try and let me know if that works for you!

I’ve also tried this, but I thought that must be wrong, cause the OH Item can’t be found then.

Script execution of rule with UID 'TEST' failed: ReferenceError: "S4_Power" is not defined in <eval> at line number 4

It wouldn’t make sense to me to declare a existing Item again, that’s why I thought I must use DSL :smiley: according to the motto “try and error”

Or am I totally not understanding, what the script does :open_mouth: ?

To access the item state in JavaScript you need to use the syntax:

ir.getItem('S4_Power').state

Please try this and see if this resolved your issues.

Thanks for your help, I am a bloody beginner with JavaScript.
I see my limit here… anyways I won’t cancel it and try to finish it.
Your hint helped me.
Now I am struggling to understand what the “oldState” need to be.
I think the Input from the smartPlug is not the correct item to fill it.
Or must be standing the washing_machine_state there for oldState?

newState and oldState are variables that are implicitly available in the code depending on the rule triggers. If you have a state changed triggers these will be set by default so you should be able to use the code completely unchanged.

Need some hints how to configure the widget. Am running 3.4.0., snapshot #3020. Am not able to store the widget configuration using MainUI. My entries under “props” like header & footer are shown within the washing machine graphics but not stored within the jsonDB file “uicomponents_ui_widget.json”. Would be happy about any hint what i might make wrong.

Have items for status (WaschmaschineWMV960_Status) and running time (WaschmaschineWMV960_ElapsedTime) from the Miele binding.

What exactly do you mean by you cannot store the widget configuration? You mean you cannot save the configuration? Could you please clarify this (maybe with some screenshots)?

I’m still in 3.3 though. If you have some 3.4 related issues I probably won’t be able to help at this point in time.