-
-
Notifications
You must be signed in to change notification settings - Fork 424
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Minus operator (-) does not work in rules (openHAB 4.2.0) #4304
Comments
averageSince now returns a QuantityType for Items that have a dimension. This is listed in the breaking changes. In your rule it causes a subtraction of a QuantityType (result of the subtraction in brackets) from a DecimalType (you defined sollflur as a Number). You should not convert sollflur or indeed, define the two others as a Number to stay consistent in your rule. |
I have also a problem with some math operations since 4.2.0. I experienced the issue on different openHAB installations, with DSL rules as well as with blockly and with 4.2.0 as well as 4.2.2 On my side it is more about mulitplications and divisions. From there I´m not sure whether it is the same problem or should be reported separatly. Anyhow, before 4.2.0 the calculations worked in the following way:
Since 4.2.0, it always subtracts 0. So the values remain the same. The really interesting part is, when I change around the multiplication and division, it works again!
The same with blockly: |
I can confirm that adding "as Number" resolves the issue with "-". I also found one calculation today not working anymore and creating the same error message as written in the first post. After adding "as Number" it works: @mherwege |
Sorry for the late reply. It is a bit hectic at work. What are the types of the items in your Blockly rules? If these are QuantityTypes, you should not use the straigth mutiplication and division operators, but the methods provided with QuantityTypes in Blockly. For DSL, I often struggle myself with the logic. But behind it is Java, and if you give Java 2 integers, it will divide into an integer result. That's why first multiplying and then dividing will probably work. You can also try first multiplying with 1.0 to make sure it is treated as a float. DSL does all kind of type magic as it tries to infer types, and that's where it often goes wrong. |
Thank you very much for your reply. How can I find out if they are QuantityTypes and what do I have then to use for other blocks for the calculation? The relevant code lines look as follows. From my understanding they are declared as normal variables and I would expect it to work (like it did before 4.2.0).
|
And where do you set |
Oh, good point:
|
Please provide the full information: How is Sollwert set? I notice in this specific line you are probably using the parseNumber block. Why do you use that? This is meant to parse a string, not the item state, which is an object. You should be careful, follow the tip from here. |
That´s the total Blockly code:
The items "Heizung_DG_Mischer_Ist", "Heizung_DG_Mischer_Zwangsoeffnung" and "Heizung_DG_Mischer_Soll" are all Number items without defined Dimension. The parsing to Numbers I was used to from the DSL ruls where it is (was?) required to get comparisons and calculations working. |
And yet Blockly (and javascript) is not DSL. The parseNumber block expects a String as an input. And what you get back as an item state may not be a String. In most cases you should not do that. Just put the result of the |
The minus operator (-) for subtraction does not work in rules in some cases since I updated from 4.1.3 to 4.2.0 Release Build.
Expected Behavior
The following code was working in 4.1.3:
Current Behavior
After I updated to 4.2.0, I am getting this error:
2024-07-08 14:13:57.877 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'main-40' failed: Unknown variable or command '-'; line 1543, column 30, length 18 in main
Possible Solution
My quick-fix was to add type Number to the variables:
But that does not solve the original issue.
Steps to Reproduce (for Bugs)
Put the lines above in a text file rule and save it as test.rules in the rules folder in your config folder.
Watch the log file.
Context
I was trying to perfom the subtraction to calculate a derived value.
Your Environment
The text was updated successfully, but these errors were encountered: