I’m new to OH3 and Blockly. In order to to control a heating in the bathroom I did create 2 rules (#1 to turn it off, #2 to turn it on).
Rule #1 (this one works) checks if the ‘actual bathroom temperature’ ≥ ‘selected bathroom temperature’ and turns OFF the heating:
With rule #2 I want to turn the heating on if ‘actual bathroom temperature’ ≤ ‘selected bathroom temperature’-2°C. (if I use ‘19’ as a fixed number it works).
Unfortunately I’m not able to create a condition (blockly script) to do it with a value based on the ‘selected bathroom temp’. This is how I would do it (but obviously it doesn’t work like that )
Think about the order of operations. They happen from the inside outward. You want to do the comparison last so it’s the outermost block. The comparison has two operands. You can plug a block in for each operand. You want the subtraction to happen before the comparison so the subtract block needs to be put into one of the operands slots for the comparison. The subtraction likewise has two operands. So you’ll plug the get item state into one and 2 into the other.
Isn’t my last picture almost correct then? Unfortunately I can’t get the ‘BadTLSensor_SetPointTemperature’-block into the subtraction-block nor the subtraction-block into the comparison-block.
Try to store the state of your item into a variable first and then do the math with the variable
The item state is a string but math functions requires a number, therefore type conversion is not always working ootb and throw you cannot combine all blocks
Ah, I have missed in the first screenshot that you are using the wrong blocks.
Do not mix up “variables” (block: set … to …) and the “value storage” blocks (block: store value … into …).
The value storage is to store information across multiple runs of the same script, while the variable blocks defining a simple variable for one script execution only.
Again, please rebuild this as a script and add logging if changing the store value blocks to variable blocks will not solve your issue
If you have the script as condition, you always need true/false output.
If you put the logic into a separate script, you can run it standalone for testing / debugging purpose.
Also if you want to reuse your work, you can call a script from multiple other rules and pass some parameters to the script
You can do that with regular rules too. In fact, a Script is a regular rule, it just has a special UI to create a rule with just one script action and adds the “Script” tag.
Yes, but in the original post the script was not part of a rule action, but only part of a rule condition. Therefore I recommended for testing & debugging to run the code standalone as script.