-
-
Notifications
You must be signed in to change notification settings - Fork 243
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
[blockly] UOM handling, provide block to strip unit and convert Quantity to Decimal #1945
Comments
The other place where this is an issue is with event.itemState. I simplified the code above, leaving this out. It is covered for items, however, it is not always clear what unit one is getting back if you use the numeric value. In this case Certifikaten has no logical unit. I am getting money every time I produce 1000 kWh with my solar panels. I need to submit my solar panel meter readings for that. 1000 kWh represent a discrete certificate, no unit. Keeping track nd having OH generate a message triggers me to submit readings. So Certifikaten is effectively dimensionless. |
Another use case for this: getting the quantity state, converting to another unit and then rounding. To do the rounding, one again has to strip the unit and add it back again afterwards. You cannot force to get the numeric value of an item in a specific unit. |
The number has to be an integer, rounded down. If I keep units, I can't round down. |
The javascript library supports it, there is just no way to do it in Blockly, see documentation:
|
In OH 4 it will always be the unit defined by the
OK, but like I said, when you post a value with units to a Number Item, OH will strip the units for you. You don't have to do this in your rule.
I'm thinking for this it might be more appropriate to add support for all the |
Is there still an open issue that needs to be fixed, if yes, please update the description, otherwise it would be nice if you closed this one here? thx. |
There is still something open, but it probably would be more appropriate to create a new issue for it. I see regular questions in the forum about wanting to strip units to do math operations. As long as we don't have broader support for math functions, it will keep coming back. I will create a new issue for it. |
@stefan-hoehn Yes, so no need to open a new one. That should take care of a major reason to strip units. |
The problem
I am trying to replace the following Jython code by a blockly script:
Certifikaten
is a Number item without Dimension.CERTIFIKATEN_OFFSET
is a numeric constant in the script.There is no easy way to strip the unit from a Quantity and get the pure numeric value in Blockly. It can probably be done with a text replace block or by dividing the Quantity by a Quantity 1 with the same unit, but that does not feel natural and is not easy to understand for a novice.
Your suggestion
Provide a block in the Units of Measurement section to strip the unit from a Quantity.
The text was updated successfully, but these errors were encountered: