OH4: Blockly UoM

My package manager updated to 4, and I’m now desperately trying to get everything working again. I’ve cleared through a lot of errors by resaving things due to “itemRegistry” not being defined. I am now struggling with UoM.

I see there are new blocks and have looked at the docs, maybe because it’s super late and I’m tired, but I can’t see the option to return the raw value of an item without the unit appended. I am doing calculations on numbers which no longer work because they have units on the end, how do I just get the value?

Hopefully by following the release notes and opening your scripts and resaving them?

There are a few changes here. The “state” of the Item is the String representation of the state (always has been in Blockly but the new JS Scripting is stricter about types). The “get [name] of item” block has options to get the numeric state (raw number without units) as well as the quantity state (Quantity Object with number and units to be used with the new Qty blocks).

Ultimately though you should either use units or not use units. If you don’t want to use units, change the definitions of your Items to be just Number and the original state won’t have units in the first place. You’ll still need to use get [numeric state] of item to get the state as a number you can do math with.

But if you want to keep the units, you should keep the units in your rules as well and use the Qt blocks to do the math. This leads to more robust and self documenting code in the long run.

That’s the magic bit I’m looking for, thanks.

I’ve found the release notes now about the JS engine change. I wasn’t intending to do the upgrade until things had settled a bit, but my PM got the best of me so I’m not approaching this in a very planned way!!