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.
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.
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.