Blockly failure "+" and "-" values with "<" and ">"

Hi Community!
Now I am on openhab 4. Ubuntu server 22.04.

I write two ident rules in blockly. One with ECMA11 and one with ECMA 5.1.
The rule in ECMA5.1 works absolute correct.
In ECMA 11 there is a Problem with “-” values and “<” and “>”
When I change the values in the wrong way from > to < then the rule works.
But I think -50 is less then -49 ?!
Here is the blockly skript:

Better post the code of the rule instead of screenshots, they are hard to read.
Also add the code of the rule that’s working, so that everyone can compare both.

Are both rules running on the same instance with same items, or different instances with different items (where you maybe assume the items are identical)?

Add log messages to show the item state at the beginning of your rule and also add the log output to this post. By this is far more easier for others to help.

OK, here is the wrong ECMA 11code…Both rules are on the same system with all the same items,…

if (items.getItem('FroniusSmartMeter_RealPowerSum').state <= '-50' || items.getItem('ShellyHeizstab1_Temp1').state > '60' || items.getItem('Temperatur_Schalter').state == 'ON') {
  items.getItem('ShellyHeizstab1_Betrieb').sendCommand('OFF');
  console.info('Rule Heizpatrone AUS');
} else {
  if (items.getItem('FroniusSmartMeter_RealPowerSum').state >= '-2500') {
    items.getItem('ShellyHeizstab1_Betrieb').sendCommand('ON');
    console.info('Rule Heizpatrone EIN');
  }
}

The Problem in ECMA11: <= -50 is wrong, >= -50 is correct.

In all rules from ECMA5.1 to ECMA11 I must change the “<” to “>” !
Whats happened with this?!

I have tried to reproduce it but I can’t

Can you please check what the status is that you are comparing by logging the value?
Can please try to do it in a way so I can do reproduce it?

In ECMAScript 11 the following line is doing a String compare, not a numeric compare.

if (items.getItem('FroniusSmartMeter_RealPowerSum').state <= '-50'

So, for example, using a String compare "5" > "1000" is true even though as numbers it would be false.

You need to do a numeric comparison. Use the “get [name] of item” block to extract the “numeric state” from the Item and a math number block for the -50.

Hi Rich !
You are a genius again, it looks like the solution. :smiley:

if (items.getItem('FroniusSmartMeter_RealPowerSum').numericState > -50 || items.getItem('ShellyHeizstab1_Temp1').state > '60' || items.getItem('Temperatur_Schalter').state == 'ON') {
  items.getItem('ShellyHeizstab1_Betrieb').sendCommand('OFF');
  console.info('Rule Heizpatrone AUS');
} else {
  if (items.getItem('FroniusSmartMeter_RealPowerSum').numericState < -2500) {
    items.getItem('ShellyHeizstab1_Betrieb').sendCommand('ON');
    console.info('Rule Heizpatrone EIN');
  }
}

But this is horrible, I must change this in all my old rules to be up to date.
Will openhab remove the old ECMA 5.1?!

@stefan.hoehn thanks for help !

Blockly no longer works with Nashorn ECMAScript 5.1 in OH 4.

Nashorn is supported through an add-on so you can continue to use it for text based script actions and conditions, but not Blockly. And you really should move to the newer version in any case. ECMAScript is ancient, Nashorn should be treated as deprecated, and less “magic” involved when dealing with operations like these is a good thing.

It does impose some work on you, but that’s the nature of major version updates to OH. These are where breaking changes are allowed and breaking changes usually cause work for end users.

OK, thank you :smiley: !