Skip to content
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

Open Exchange Rate Integration has a 4 decimal limit, which prevents use of various metals/currencies #103945

Closed
Extrapilot1 opened this issue Nov 14, 2023 · 6 comments · Fixed by #103972

Comments

@Extrapilot1
Copy link

The problem

In the Open Exchange Rate integration, the API returns textual values for currencies and metals. The Integration converts those to entities. Problem is, it is clipping the returned data to 4 decimal places. For certain entities, this is a problem. Example, Gold (XAU) is returned as Ounces/USD, so the value will be something like 0.0005143. 1/x gets you the dollar cost of an ounce of gold, but the integration only returns 0.0005. Same problem for various currencies. The Vietnamese currency currently trades at 0.000041/USD for example.

It would be better if the integration had a config option that permitted selection of decimal points, but it would be fine to return 8 points, where I dont believe there is need for precision beyond that for any supported currencies or metals.

What version of Home Assistant Core has the issue?

2023.11.2

What was the last working version of Home Assistant Core?

No response

What type of installation are you running?

Home Assistant OS

Integration causing the issue

Open Exchange Rate

Link to integration documentation on our website

https://www.home-assistant.io/integrations/openexchangerates/

Diagnostics information

Code is operating as designed- problem is simply the truncation at 4 decimals where more resolution is required for some currencies and metals.

Example YAML snippet

No response

Anything in the logs that might be useful for us?

Just an example of the APi return, where you can see that many currencies, and metals, require 6-7 decimal accuracy- XAG, XAU, 

2023-11-13 16:30:30.926 DEBUG (MainThread) [homeassistant.components.openexchangerates] Result: disclaimer='Usage subject to terms: https://openexchangerates.org/terms' license='https://openexchangerates.org/license' timestamp=1699916400 base='USD' rates={'AED': 3.67295, 'AFN': 72.713683, 'ALL': 97.597966, 'AMD': 402.989391, 'ANG': 1.803718, 'AOA': 829.3567, 'ARS': 349.9446, 'AUD': 1.568772, 'AWG': 1.8, 'AZN': 1.7, 'BAM': 1.831531, 'BBD': 2.0, 'BDT': 110.839528, 'BGN': 1.828, 'BHD': 0.377016, 'BIF': 2846.593393, 'BMD': 1.0, 'BND': 1.360959, 'BOB': 6.916283, 'BRL': 4.9077, 'BSD': 1.0, 'BTC': 2.7415215e-05, 'BTN': 83.395303, 'BWP': 13.644238, 'BYN': 3.296811, 'BZD': 2.017325, 'CAD': 1.379627, 'CDF': 2544.522403, 'CHF': 0.90182, 'CLF': 0.033444, 'CLP': 923.90237, 'CNH': 7.292153, 'CNY': 7.2903, 'COP': 4025.416479, 'CRC': 531.347629, 'CUC': 1.0, 'CUP': 25.75, 'CVE': 103.320245, 'CZK': 22.985263, 'DJF': 177.862377, 'DKK': 6.970591, 'DOP': 56.86525, 'DZD': 134.648257, 'EGP': 30.901232, 'ERN': 15.0, 'ETB': 55.818807, 'EUR': 0.934611, 'FJD': 2.30635, 'FKP': 0.814608, 'GBP': 0.814608, 'GEL': 2.69, 'GGP': 0.814608, 'GHS': 11.953455, 'GIP': 0.814608, 'GMD': 67.125, 'GNF': 8620.649776, 'GTQ': 7.836307, 'GYD': 211.187737, 'HKD': 7.80945, 'HNL': 24.768702, 'HRK': 7.042155, 'HTG': 132.818266, 'HUF': 352.582196, 'IDR': 15682.700524, 'ILS': 3.86564, 'IMP': 0.814608, 'INR': 83.23591, 'IQD': 1310.06638, 'IRR': 42275.0, 'ISK': 143.83, 'JEP': 0.814608, 'JMD': 155.827116, 'JOD': 0.7093, 'JPY': 151.68416667, 'KES': 152.163897, 'KGS': 89.32, 'KHR': 4120.413816, 'KMF': 460.950202, 'KPW': 900.0, 'KRW': 1317.526631, 'KWD': 0.308735, 'KYD': 0.834012, 'KZT': 465.833126, 'LAK': 20757.546983, 'LBP': 15040.01841, 'LKR': 327.274493, 'LRD': 187.74997, 'LSL': 19.59845, 'LYD': 4.874006, 'MAD': 10.226341, 'MDL': 17.963034, 'MGA': 4525.607202, 'MKD': 57.739789, 'MMK': 2101.691064, 'MNT': 3450.0, 'MOP': 8.04958, 'MRU': 39.390478, 'MUR': 44.203542, 'MVR': 15.25, 'MWK': 1114.84, 'MXN': 17.615328, 'MYR': 4.708, 'MZN': 63.899991, 'NAD': 20.02, 'NGN': 803.669268, 'NIO': 36.634358, 'NOK': 11.084943, 'NPR': 133.422309, 'NZD': 1.701901, 'OMR': 0.384932, 'PAB': 1.0, 'PEN': 3.791169, 'PGK': 3.779958, 'PHP': 55.954992, 'PKR': 283.982622, 'PLN': 4.138225, 'PYG': 7440.219185, 'QAR': 3.642809, 'RON': 4.6479, 'RSD': 109.740145, 'RUB': 91.848624, 'RWF': 1231.25648, 'SAR': 3.750724, 'SBD': 8.398674, 'SCR': 13.440438, 'SDG': 601.0, 'SEK': 10.843901, 'SGD': 1.359028, 'SHP': 0.814608, 'SLL': 20969.5, 'SOS': 571.593757, 'SRD': 38.075, 'SSP': 130.26, 'STD': 22281.8, 'STN': 22.931099, 'SVC': 8.756848, 'SYP': 2512.53, 'SZL': 18.754507, 'THB': 35.996, 'TJS': 10.94901, 'TMT': 3.5, 'TND': 3.1535, 'TOP': 2.398287, 'TRY': 28.601101, 'TTD': 6.779979, 'TWD': 32.333501, 'TZS': 2502.592533, 'UAH': 36.24994, 'UGX': 3775.823466, 'USD': 1.0, 'UYU': 39.882045, 'UZS': 12290.667224, 'VES': 35.326413, 'VND': 24381.324268, 'VUV': 118.722, 'WST': 2.8, 'XAF': 613.064703, 'XAG': 0.04482597, 'XAU': 0.00051384, 'XCD': 2.70255, 'XDR': 0.760875, 'XOF': 613.064703, 'XPD': 0.0010144, 'XPF': 111.528773, 'XPT': 0.00115897, 'YER': 250.349961, 'ZAR': 18.7105, 'ZMW': 22.82514, 'ZWL': 322.0}

Additional information

No response

@home-assistant
Copy link

Hey there @MartinHjelmare, mind taking a look at this issue as it has been labeled with an integration (openexchangerates) you are listed as a code owner for? Thanks!

Code owner commands

Code owners of openexchangerates can trigger bot actions by commenting:

  • @home-assistant close Closes the issue.
  • @home-assistant rename Awesome new title Renames the issue.
  • @home-assistant reopen Reopen the issue.
  • @home-assistant unassign openexchangerates Removes the current integration label and assignees on the issue, add the integration domain after the command.

(message by CodeOwnersMention)


openexchangerates documentation
openexchangerates source
(message by IssueLinks)

@MartinHjelmare
Copy link
Member

I suggest we simply remove the rounding.

@Extrapilot1
Copy link
Author

If that works, great. I didnt know if there was reason for rounding to begin with (i.e. limit string length). Thanks so much for having a look at it.

@Extrapilot1
Copy link
Author

Extrapilot1 commented Nov 22, 2023

Best I can tell, the problem persists. Im seeing in the log a value for gold as the entry:
'XAU': 0.00050298
In HA. even with the decimal precision set at 0.0000500 display Im seeing 0.00005. I dont know if display rounding limits other parsing/recording, but a template sensor that just does:
value_template: "{{ 1.0|float / (states('sensor.open_exchange_rates_usd_xau')|float}}"

returns the equivalent of 0.0005 also (1/.0005), or 2000.

I restarted the integration, and then restarted Home Assistant- in the hope this was an initial update parse thing (lag), but seems a new read was logged, and yet the raw sensor and the template seem to be unaffected.

@MartinHjelmare
Copy link
Member

The change will be released in the December release as it's technically a breaking change.

@Extrapilot1
Copy link
Author

Sorry- my mistake. I saw reference to open exchange rate in the release notes on today's update and assumed this was the change. I hope you are well- enjoy the week/end-
Rob

@github-actions github-actions bot locked and limited conversation to collaborators Dec 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants