Could not cast 0 to org.openhab.core.library.types.QuantityType

Hello there,

I am trying to get the washing machine widget running.
The Widget can be downloaded at the “User Interface” section, it comes with a script and the creator page.
unfortunately the page is not very well observed anymore, I hope someone here can give me a hint with my 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


configuration: {}
  - id: "1"
      itemName: S4_Power
    type: core.ItemStateChangeTrigger
conditions: []
  - inputs: {}
    id: "2"
      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('Laufzeit_Spuelmaschine.rules', logPrefix + 'StateMachine Zustand alt: ' + Washingmachine_OpState.state.toString + '; Leistung momentan: '+ S4_Power.state.toString)

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

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

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

        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 (EinbleLog_WaschmaschineRules.state == ON) logInfo('Laufzeit_Spuelmaschine.rules', logPrefix ,+ 'StateMachine Zustand neu: ' + Washingmachine_OpState.state.toString)
    type: script.ScriptAction

I found a topic where someone ran into this problem, I can’t transfer his solution to my problem.
Also, I tried different types.
I think the Input is the problem, my input is an energy measurement plug, and the item is declared as “Number”.

Can anyone here give me a hint on that?
I would be thankful to understand my problem.

You don’t give enough information such as the item name, type and the line number your problem is in to understand the problem (and frankly no I don’t want to debug the whole thing).

Generally speaking, you have to turn the value (0) into a QuantityType that matches the item or variable type you assign it to in rules DSL.
Easiest way is to declare your input item to be of Number:XXX type.
Probably Number:Power as it’s about current consumption.

thanks for the reply.
You are right, that’s not enough information, I see it when I read my own question.

Maybe I can’t read the syntax of the line of the error, but I am not able to find the correct line.
line 8, column 6, length 37 there is no specific code in it “looks empty to me” (or I am not able to read it correctly)

→ see picture

The Item S4_Power is declared as Number. → it measures the consumption of the washer
I’ve also tried to specifically declare it as Number:Power, which also was the solution from the old topic → sadly, that’s not working for me, I ran into the same error.

I think this generates the Error:

(S4_Power.state as QuantityType<Power>).doubleValue

The script is not from me, I just try to keep it work.
From my thought, it just detect the state from the washer (with the consumption over time)
and sets the value for the runtime item, what on the other hand fills the widget with values to show the remain time.
“EnableLog” is just an Switch to enable or disable the log output.

No offence but just a small remark from my side: I try to answer every question regarding the widget in the corresponding thread. However your question had nothing to do with the widget itself so I suggested to open a new thread instead.

the script depends on another user, which comments on your widget.
Correct, I just tried to say, that my error is maybe not “seen” for everyone as you answer me aswell at your thread :slight_smile: don’t misunderstand me :slight_smile:

1 Like

If S4_Power is “0” rather than “0 W” yes that’ll produce that error. Change S4_Power to
Number:Power and assign a new value (else it’s still “0”) e.g. via console openhab:update S4_Power "0 W".
Changing item type might not have worked for you it requires to remove and readd the item (if so the console command should fail).

1 Like