Skip to content
This repository has been archived by the owner on May 7, 2020. It is now read-only.

Units of Measurement: Follow up issues for the new QuantityType #5243

Open
htreu opened this issue Mar 16, 2018 · 34 comments
Open

Units of Measurement: Follow up issues for the new QuantityType #5243

htreu opened this issue Mar 16, 2018 · 34 comments
Labels

Comments

@htreu
Copy link
Contributor

htreu commented Mar 16, 2018

These are some known issues after the Units of Measurement support in ESH landed (#4818):

  • When the measurement system gets switched (or locale gets updated, which would result in another measurement system) there is no refresh on any item. So until bindings post a new state update or a REFRESH command is issued to the corresponding items the user gets the impression nothing changed.
  • Analyse Automation JavaScript support
  • The precision in state descriptions is currently static regardless of the chosen measurement system
  • Right now only measurement systems SI (metric) and Imperial are supported. There are countries which use mixed systems.
@htreu htreu changed the title Paper UI: after measurement system switch items do not get updated Units of Measurement: Follow up issues for the new QuantityType Mar 16, 2018
@wborn
Copy link
Contributor

wborn commented Mar 17, 2018

The documentation of the refactored bindings also needs to be updated:

@lolodomo
Copy link
Contributor

Yes please, an updated documentation would be helpful to understand in particular how to define the items now (item label).

@wborn
Copy link
Contributor

wborn commented Mar 17, 2018

@lolodomo
Copy link
Contributor

Good question: are all persistence services compatible with the new type ?
Someone reported it is not. That would be a major problem...

@kaikreuzer
Copy link
Contributor

@lolodomo That's a very valid question! I had actually thought about this, but in the end forgot to adapt the compatibility layer (through which all persistence in openHAB is still handled) accordingly.
Just created openhab/openhab-core#319 for it and will make sure to have it available in the distro asap.

@htreu
Copy link
Contributor Author

htreu commented Mar 19, 2018

I left a comment on the PR Kai did which shows a structural issue with persistence and UoM: openhab/openhab-core#319 (review)

@J-N-K
Copy link
Contributor

J-N-K commented Apr 1, 2018

Please see openhab/openhab-core#325. The question is, is it right to strip the unit-subtype there or is it better stripped in the ItemProvider in ESH?

@kaikreuzer
Copy link
Contributor

@J-N-K Clearly to be fixed in the compat layer, not in ESH.

@cweitkamp
Copy link
Contributor

cweitkamp commented Apr 4, 2018

I found another issue related to the new QuatityType. In sitemaps rendered with Basic UI the highlight features like labelcolor and valuecolor are not working like expected. The color isn't applied anymore. Probably because of not matching comparisons for the item type. If you need an example you are welcome to ask.

// EDIT: For clarification: The highlight works fine on Number items without a specified unit.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 4, 2018

The sitemap syntax should let you mention the unit for the visibility and color attributes.

@cweitkamp
Copy link
Contributor

cweitkamp commented Apr 4, 2018

How does it work? I didn't find an example. What has to be changed in the following line?

Text item=fritzWashingMachineDECT200Temperature label="FRITZ!DECT 200 (Waschmaschine) [%.1f %unit%]" valuecolor=[<15="blue", <=18="green", <=21="orange", >21="red"]

// EDIT: Item type is Number:Temperature.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 4, 2018

Sorry, I mean you should be able but unfortunately you probably can't ... until this is enhanced.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 6, 2018

@htreu : can you please remind us what is the new syntax including the unit in rules and in console commands ?

@lolodomo
Copy link
Contributor

lolodomo commented Apr 6, 2018

Looking at the code for the console commands, I have the feeling this was not updated, meaning you can't mention the unit ?

@htreu
Copy link
Contributor Author

htreu commented Apr 6, 2018

@lolodomo in the console you are able to provide the value & unit in one string:

smarthome update Weather_Pressure 1000hPa

Unfortunately in the IDE console you get parsing errors when using the ° character. This is a limitation of the Eclipse console implementation.

@htreu
Copy link
Contributor Author

htreu commented Apr 6, 2018

As for the syntax in rules it is missing in the docs right now. But I did a blog post here. The syntax is described in the "Scripts & Rules" section.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 6, 2018

So for sitemap, should we update the syntax the same way as for rules or should we consider the same syntax as in console commands ?
Console syntax with one unique string would mean no change of syntax in fact, just a fix in the code parsing the values. I would vote for this option and I can even try to fix it (but I have a limited free time for that at this moment).

@htreu
Copy link
Contributor Author

htreu commented Apr 6, 2018

For sitemaps the syntax follows the item state description syntax: label="my Label [%.2f °F]" will convert and render the given temperature value in degree Fahrenheit.

@htreu
Copy link
Contributor Author

htreu commented Apr 6, 2018

Console syntax with one unique string would mean no change of syntax in fact, just a fix in the code parsing the values.

The QuantityType is actually able to parse Strings like 20°C but the console implementation of the eclipse IDE has encoding issues. So the problem can not be fixed in the scope of ESH.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 6, 2018

As @cweitkamp explained, the problem is not the label attribute but would be the labelcolor /valuecolor / visibility attributes.

@lolodomo
Copy link
Contributor

lolodomo commented Apr 8, 2018

Netatmo binding is handling Co2 and noise data, respectively in ppm and decibel units.
Are these units available in ESH ?

@J-N-K
Copy link
Contributor

J-N-K commented Apr 8, 2018

@lolodomo, I have created #5385 for dB and ppm.

@lolodomo
Copy link
Contributor

@htreu : regarding your first point (refresh when the unit system is updated), I imagine that setUnitProvider will be called for the thing handler factory of any binding referencing it when the the unit system is updated by the user ?
If I am right, then the handler factory could then notify each thing handler of this change so that a refresh can be handled by these handlers.
WDYT ?

@htreu
Copy link
Contributor Author

htreu commented Apr 16, 2018

I imagine that setUnitProvider will be called for the thing handler factory of any binding referencing it when the the unit system is updated by the user ?

Unfortunately this is not the case. The framework provides one instance of the UnitProvider and changes are not propagated to referencing services. The service setter setUnitProvider is annotated as 1..1, STATIC which means the instance will not get overwritten once set.
Otherwise the whole HandlerFactory would be shut down and created from the ground up.

For the refresh to work we need some registration mechanism where bindings register for UnitProvider updates. The framework can then call all registered listeners and notify about the update.
Bindings could then issue the REFRESH command or simply update the state from their caches with the value and unit converted.

@lolodomo
Copy link
Contributor

As discussed in another PR (netatmo binding), it looks like the min/max/step attributes of a channel type are not correctly handled when the channel type uses UoM. It should be possible to set the unit with the value of these attributes, something like min="4.5°C".

@J-N-K
Copy link
Contributor

J-N-K commented May 4, 2018

As mentioned here, it is not possible to check for the correct type of an item's state without generating log messages.

@J-N-K
Copy link
Contributor

J-N-K commented May 4, 2018

Comparison in rules for % is not possible:

.items

Number:Dimensionless	Bad_hum	    "Bad [%.0f %%]"			    <humidity>

.rules

rule "bad test"
when
	Item Bad_hum changed
then
	logInfo("lueftung", "orig: {}, comparison: {}, {}", Bad_hum.state, Bad_hum.state>55, Bad_hum.state>0.55)
end

openhab.log

18:58:22.572 [INFO ] [lipse.smarthome.model.script.lueftung] - orig: 55.4185 %, comparison: false, false

If I change to Bad_hum.state>55% the log is

18:59:31.943 [WARN ] [del.core.internal.ModelRepositoryImpl] - Configuration model 'bad.rules' has errors, therefore ignoring it: [95,86]: no viable alternative at input ','

@cweitkamp
Copy link
Contributor

cweitkamp commented May 4, 2018

If I change to Bad_hum.state>55%

Did you try to put the % between square brackets like this Bad_hum.state > 55 [%]?

@J-N-K
Copy link
Contributor

J-N-K commented May 5, 2018

@cweitkamp, that works. It‘s even in the blog post @htreu mentioned above. Maybe it‘s me, but I didn‘t notice the necessity of the brackets.

@watou
Copy link
Contributor

watou commented Jun 16, 2018

In a rule under OH 2.3.0, I receive this log error:

'toUnit' is not a member of 'org.eclipse.smarthome.core.library.types.QuantityType'

in reaction to the expression MyItemName.state.toUnit('mph') for a Number:Speed item. Also, an attempt to import tec.uom.se.AbstractUnit at the top of the rule does not result in resolving AbstractUnit when the rule tries to use the parse static method.

@kaikreuzer
Copy link
Contributor

I have seen the same error and wondered why it happened. We might need some implicit imports in Xbase for it - @watou I would say that this is worth a separate issue (as I consider it a bug). Would you be so kind and create one?

@watou
Copy link
Contributor

watou commented Jun 20, 2018

Looking for a working way to use UoM to create a QuantityType in a rule from a variable, not a constant scalar value. The following under OH 2.3.0:

import org.eclipse.smarthome.core.library.unit.SIUnits
...
val double dewptc = (some computation)
val double dewptf = new QuantityType(dewptc, SIUnits::CELSIUS).toUnit('°F').doubleValue

produces the log messages:

2018-06-20 11:16:38.869 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'meteostick.rules', using it anyway:
The constructor QuantityType(Number, Object) refers to the missing type Object
2018-06-20 11:16:38.935 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'my.rules'
2018-06-20 11:17:22.958 [ERROR] [ntime.internal.engine.RuleEngineImpl] - Rule 'PWS': The name 'SIUnits' cannot be resolved to an item or type; line ...

@htreu
Copy link
Contributor Author

htreu commented Jun 20, 2018

@watou I created a separate issue #5759 for the missing unit constants. PR is also on the way.

@watou
Copy link
Contributor

watou commented Oct 3, 2018

Using 2.4.0-SNAPSHOT build # 1378, when using CELSIUS in a rule, the following is logged

2018-10-03 11:27:41.578 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'meteostick.rules', using it anyway:
The field SIUnits.CELSIUS refers to the missing type Object
2018-10-03 11:27:41.589 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'meteostick.rules'
2018-10-03 11:27:53.997 [INFO ] [el.core.internal.ModelRepositoryImpl] - Validation issues found in configuration model 'meteostick.rules', using it anyway:
The field SIUnits.CELSIUS refers to the missing type Object
2018-10-03 11:27:54.074 [INFO ] [el.core.internal.ModelRepositoryImpl] - Refreshing model 'meteostick.rules'

The only expression in the rule referencing CELSIUS is

val double dewptf = new QuantityType(dewptc, CELSIUS).toUnit('°F').doubleValue

There is no reference to SIUnits in the rule file. The rule appears to work as intended despite these log messages.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

8 participants