OH4 Blockly sum calculation does not sum but just add the new number. 3+3 results in 33

  • Platform information:

    • Hardware: rpi 3B+
    • OS: openhabian
    • Java Runtime Environment: 17
    • openHAB version: 4.0.1
  • Issue of the topic:
    From OH 3.x I have a simple sum calculation in a blockly rule, which do not sum correctly anymore using OH4. I also built a new blockly rule with the same behaviour.
    Example:
    Var Timer = 3
    Var Timer + 3 results in 33 instead of 6.

  • configuration
    Openhab_Blockly_Sum

Generated Code:
type: application/javascript
script: |
var Timer;

    items.getItem('Waschmaschine_Zaehler').postUpdate(3);
    Timer = items.getItem('Waschmaschine_Zaehler').state;
    console.log('Timer current value');
    console.info(Timer);
    Timer = Timer + 3;
    console.log('Timer value "Timer + 3"');
    console.info(Timer);
    items.getItem('Waschmaschine_Zaehler').postUpdate(Timer);
type: script.ScriptAction

Output:

2023-08-12 10:21:51.891 [INFO ] [rg.openhab.automation.script.ui.test] - Timer current value
2023-08-12 10:21:51.894 [INFO ] [rg.openhab.automation.script.ui.test] - 3
2023-08-12 10:21:51.895 [INFO ] [rg.openhab.automation.script.ui.test] - Timer value “Timer + 3”
2023-08-12 10:21:51.897 [INFO ] [rg.openhab.automation.script.ui.test] - 33

Can anyone confirm this behaviour?

Update
Just found out it is related to the item state (which is a number item by the way).
If I choose “numeric state” it works…
image

regards
Levin

1 Like

Exactly, this is the exact reason why I added the numeric state. Otherwise the JavaScript that is generated would perceive the state as a String and does a js like string concatenation.

1 Like