OH4: rules do not work anymore

That really made me curious :sunglasses: if there wasn’t a way to improve the round block to work with Quantities and I think I was able to achieve it:

it produces the following automatically

console.info((String(Quantity((Math.round(Quantity('10.56 W').float)).toString() + ' ' + Quantity('10.56 W').symbol)) + '= 11 W'));
console.info((String(Quantity().add(Quantity('10 W'))) + '= 20.2 W'));

The block is even so smart that if you insert a quantity it changes into a Qty-Type (and therefore will only connect to something that expects that) and if you insert something else it will be a Number-Block as before. Note that a variable cannot be detected, so a var would be a “Number”.

If you are happy with this idea I can create PR for that.

4 Likes

It looks good to me. I wonder though if the same approach could be leveraged for other Math operations. Other useful operations I’ve seen used:

  • abs
  • ceil
  • floor
  • max
  • min
  • pow

I doubt many are doing trigonometry or logarithmic operations in rules with Quantities but the above (maybe not pow) I can see being useful and I’ve seen them used in the wild.

2 Likes

Yep, could be done but with round I was fortunate that I completely REIMPLEMENTED for OH, so I was able to adapt. Even though it looks like a “standard blockly block” it has been rewritten by me. With all the others you mentioned I need to reimplement them which is probably not a lot of work but not a quick win to be able to add quantity.
Having said that I like the idea. So, if you wouldn’t mind, could you open a request for it, so I won’t forget it :pray:

2 Likes
2 Likes

Unfortunately I have no clue what u guys are talking about but thank you very much for all the effort you are putting into this!
You guys rock!

Hey guys,

this is my solution to the problem. I got rid of the unit and added it later in my sitemap with [%.0f kWh]

I don’t know if this is a good solution or not but I wanted to share it with you because it is working fine for me :slight_smile:

1 Like