-
-
Notifications
You must be signed in to change notification settings - Fork 428
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
conversion to base unit on persisting #3167
Comments
Consider the following scenario. I live in the US and use °F for temperature. All my sensors report °F and all but let's say I've one device that only supports °C. Let's consider the Setpoint channel on that one device. I've linked that to a Number:Temperature Item and I've configured the state description to °F and my locale defaults are °F. My understanding is that the Item would carry °C but show me °F and ultimately store °F in persistence. What's going to happen on restoreOnStartup? Will I have to worry about calculation errors creeping in if this Item is constantly being converted back and forth between °C and °F? What if I change the scenario a little and instead of being delivered °C from the binding, for this one Item I set the state description of °C but my locale still defaults to °F. Same question, will conversion errors potentially accumulate as the value is converted back and forth? My main point is, as this gets implemented, consider some of the edge cases and make sure we have a reasonable answer for them. |
I think I am already running into the issue. |
That's a different issue. It might be worth filing a separate issue as this one is strictly dealing with persistence, and it's not yet been implemented anyway. I'm not sure whether it belongs here or on the MQTT binding though. Either the MQTT binding is not supplying the kWh the way it should, or somehow the system default is taking precedence over the binding provided units. Your fix, by using the stateDescription works because that takes precedence over the system default. |
For almost any item type, physics define the base unit to be used.
I did not check but assume that C is the default unit for temps introduced in #3121 (I know it's American to believe you are the reference but this time the Old World reigns physics, sorry :-) :-)). |
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/uom-default-units-and-consequences/142360/42 |
I can't emphasize enough how strongly I am against this! Let's stick to the Fahrenheit example: The DB is also connected e.g. with Graphana which is used for charting. Other example: If you only use openHAB and openHAB internal charting all this is no problem but as soon as you want further work with the data in database it'll get a huge pain. The only correct way is to respect the unit of the item and persist the value how it's represented in openHAB. |
I agree with @spacemanspiff2007, this would make visualization using e.g. grafana a real pain. Another example: the SMHI binding (and perhaps other weather bindings?) report precipitation intensity in mm/h, which is a unit of speed. The default unit for speed according to SI is m/s, so in my grafana graphs a precipitation intensity of 5 mm/h would be displayed as 5 / 3 600 000 = 1.3888888888889E-6 m/s (0.00000139 m/s), which would be very hard to interpret. Either use the state description and store the value in that unit, or create a new configuration for the base unit for each Item (which falls back to the default if not set), and use that unit when restoring from persistence. |
See #3248 |
Better not use this as an example because this is not about normalization. It is a special case to convert to handle changes across measurement system borders.
And it's only breaking if you 1) have been using a non-default unit so far 2) you want to keep working with historic data across the point in time you apply the change (rather than make a simple cut) 3) don't want to convert your pre-change historic data (which would be a simple one-time action, particularly when you use an external DB. That's a low-cost effort, isn't it.)
I think that's not the right view angle on the problem. And you don't have to use m/s. |
See https://community.openhab.org/t/uom-default-units-and-consequences/142360/98 Someone should test this out with 3.4. |
Please read carefully.
That would imply that everything that interacts with databases from openHAB has support for these display conversions. It would be much more elegant if there is one place to define once which unit and scale is used for an item and that should be on the item itself. |
I've posted it before but I think it's worth saying a little more. PR #3248 is super relevant to this conversation. The reason why is that it implements exactly this. A way to define a default base unit on persisting. You'll have metadata to define on the Item (simple, something like Only in cases where there is no defaultUnit defined will a conversion take place to the system default unit for the Item type, if the Item isn't already in that unit. In short PR #3248 gives the end user a way to control what units/scale the values have when they get saved. And this way is independent from your display on the sitemap/MainUI which is still controlled through the State Description pattern. |
This issue has been mentioned on openHAB Community. There might be relevant details there: https://community.openhab.org/t/uom-default-units-and-consequences/142360/115 |
I'll try again to explain my thoughts again because of all the default discussion I still have the feeling that my point is lost.
From what I understand from the issue the PR implements the following: Additionally the persistence service will use the Both things are a good start but I there are two things I think are sub optimal:
Especially the second/third point can be very confusing because there is a discrepancy on what is happening in openHAB and what is shown in the external system. If one could enforce a unit and scale on an internal level things would be much more consistent. Then
As you see if the unit and scale is part of a number item it's immediately clear what is happening throughout openHAB and all ambiguity is removed. Additional Nodes:
|
See also #2253 |
This is the only part that's missing with what's currently being proposed. Right now, if you post "3000W", the Item carries "3000W". It'll be converted upon saving to persistence to kW and restored as kW. Personally, I'm a little uncomfortable with this type of conversion, but I'm also uncomfortable with the conversion on persistence. But I can see how it can be useful to normalize the units everywhere when a But what of the case where a
1.b. is troubling when it comes to persistence. But this should be exceedingly rare I would hope. |
If we do it the way I proposed it's a non issue:
Then the cases become easy:
|
You are missing a case and it's the case I'm worried about.
It's case 6 I'm worried about. When the user doesn't supply a default unit but the Item is defined to have units and a unit was supplied in the update. But given the direction of #3248 is going case 6 is also solved. If we remove the Item type from the Number and require the use of |
Closed, superseded by #3282. |
Persistence so far does not store/restore UoM but only the value.
I suggest to now forcefully convert a QuantityType item to its base unit before we persist it to statically work around our current lack to store the unit and to avoid having to refactor all of our persistence implementation.
Following up on #3121, now with #3143 merged we have default units for all item UoM types.
This added conversion will break some installations where users chose to apply units other than the one that science defined to be the base unit for a physical dimension. It's a philosophy discussion whether that's breakage or rather as I see it the opposite, overdue fixing of a long-standing problem, but either way it's a breaking change.
From a user pov it breaks e.g. their OH charts.
I suggest to make it an option so users can choose for themselves whether to apply it to their environment or not.
For details and discussion see #3121.
The text was updated successfully, but these errors were encountered: