ioBroker.javascript
ioBroker.javascript copied to clipboard
[RULES] rules module "operate two states" calculates wrong results
Describe the bug
The rules module "operate two states" mixes the operands and hence calculates wrong results for "minus" and "divide" operations.
So for example if the module is configured as A=A-B the culculation results in A=B-A.
Example see screenshots and js code extract.
To Reproduce
Steps to reproduce the behavior:
- create a rule which stores the result of a minus operation between operand at the first operand: A=A-B
- check the result of the operation
Expected behavior
a correct calculation :-)
Screenshots & Logfiles

Code generated:
let cond = false;
on({id: "pid.0.C-1.out.y", change: "ne"}, async function (obj) {
_sendToFrontEnd(1680632417356, {val: obj.state.val, ack: obj.state.ack, valOld: obj.oldState && obj.oldState.val, ackOld: obj.oldState && obj.oldState.ack});
const _cond = true;
if (_cond) {
// pid.0.C-1.in.act - pid.0.C-1.out.y => pid.0.C-1.in.act
const val2_1680632515086 = (await getStateAsync("pid.0.C-1.in.act")).val;
const val1_1680632515086 = (await getStateAsync("pid.0.C-1.out.y")).val;
_sendToFrontEnd(1680632515086, {val: val1_1680632515086 - val2_1680632515086, ack: false});
await setStateAsync("pid.0.C-1.in.act", val1_1680632515086 - val2_1680632515086, false);
} else {
}
});````
**Versions:**
- Adapter version: Javascript 6.1.4
- JS-Controller version: 4.0.24
- Node version: 16.19.0
- Operating system: Raspian
**Additional context**
If working at the graphics two, please consioder making the operation field (dropdown field) cpontaining + - * / bigger and miore visible. Currently the '+' sign which is uses as block Logo is prominent and the field showing the true operation performed "hides" as it is a little bit small. But thats cosmetic and only noted as it related to the same function block.