UoM Blockly Quantity not working with variable

I still have a few automations not working since OH4, latest issue I’ve found is with UoM and variables. I am unable to use variables with the quantity shape. I am using ℃, but to rule out that particular unit, I created an isolated example:

Given this:


Will generate this code:
image

Why does this:


Generate undefined:
image

And, how to I work around this? My example is iterating values and checking if any exceed a threshold.

  • Platform information:
    • Hardware: amd64 / oodles
    • OS: Linux 5.14.21-150400.24.81-default
    • Java Runtime Environment: OpenJDK 17.0.8
    • openHAB version:4.0.2

Looks like a bug. An issue should be files on the openhab-webuis repo.

I also had problems converting my rules and did a lot of trial an error to understand…
Found out that something like this is working:
image

image

This might be a workaround. It is still not 100 % clear for me.

As I was only experiencing problems with my initial variable set, as illustrated here, the way to achieve this is to type the initialisation:

image

Which gives:

image

So this doesn’t really answer the question, can you use a variable in a quantity (no), but it does provide an alternative approach to using quantity with variables.

I’ll note that you can then legitimately go on and do this:
image
Or even this:
image

I’d therefore suggest it might not be a bug, just a consideration - the bug may be allowing a variable in the quantity shape at all. I feel that’s one for the authors to ponder!

Either a variable should not be allowed or it should be allowed. The fact that it’s allowed but doesn’t work is most definitely a bug. Anything that results in undefined like that is a bug and it needs to be fixed. Please file an issue.

https://github.com/openhab/openhab-webui/issues/2057

1 Like