openhab / openhab-addons

Add-ons for openHAB
https://www.openhab.org/
Eclipse Public License 2.0
1.9k stars 3.6k forks source link

[Netatmo] Temperature values with many digits after decimal point #4054

Closed andyzlen closed 6 years ago

andyzlen commented 6 years ago

Minor issue but hopefully will be considered:

Expected Behavior

Values provided by channel “Temperature” should contain only one digit after decimal point -as accuracy of Netatmo weather stations is ± 0.3°C / ± 0.54°F according to Netatmo technical specs.

Current Behavior

Values from channel “Temperature” contain 18 digits after decimal point, e.g. “19.8999996185302734375 °C”

Your Environment

OpenHab 2.3 (release) binding-netatmo - 2.3.0 Raspbian Jessie

cweitkamp commented 6 years ago

Bindings are meant to deliver precise data. If you need only one decimal you can archive it easily by applying a pattern / format on the state of your item linked to a channel.

andyzlen commented 6 years ago

Thank you @cweitkamp for your quick answer and your reference to the item patterns. I understand the general rule for bindings “Do not change original things values” which should not be touched.

My current OH installation contains many temperature items with “Temperature [%.1f °C]” or “Temperature [%.1f %unit%]” using channels from 4 different bindings. Therefore, I would explain my use case which is behind my proposal: My home is completely “Alexa-enabled”, among others Alexa skill “Netatmo” is activated. But the question ““Alexa, ASK NETATMO what’s the temperature in the children’s room” is approaching a WAF* of ZERO. This is why I tagged the relevant items in OH to allow the more catchy question ““Alexa, what’s the temperature in children’s room”. In this case- you know - the original Netatmo value is directly passed via openhabcloud to Alexa engine and of course ignoring my [%.1f %unit%] item configuration. Then Alexa e.g. tells me (and my wife) “The temperature in the children’s room is twenty-three-point-eight-nine-nine-nine-nine-six-one-eight-five-three-zero-two-seven-three-four-three-seven-five degree”. And – as expected: WAF=0. Then I started to manipulate original Netatmo value in a rule. As the Netatmo binding supports units since OH 2.3 which is a great feature to handle conversions easily but a nasty task if you want to manipulate values in rules – what I wanted to do. At the end – after three hard days of testing I gave up and opened this issue.

Now after five more hours I got a result based on further investigation on the related topics in OH community, see below. Here are several attempts, only first one was successful:

  1. Math.round: val onedigit = Math::round(((Netatmo_Temperature.state as QuantityType\).doubleValue)*10 )/10.0
  2. DecimalFormat utility: val DecimalFormat df = new DecimalFormat("#.#") val Number dformat = Double.valueOf(df.format((Netatmo_Wohnz_Temperatur_Alexa.state as QuantityType\).doubleValue)) => RuleEngine ERROR: “Rule ‘Set Netatmo item’: For input string: "23,1" Reason after investigation: df.format returns e.g. “23,1”, not 23.1 (have no reason why) which can not be converted by standard to Number type.
  3. String::format val stringf = String::format("%.1f", ( (Netatmo_Wohnz_Temperatur_Alexa.state as QuantityType\).doubleValue) ) Same problem as in case 2.: String::format returns e.g. “23,1”, not 23.1

List of references with discussions in community I used for my testing:

*WAF - wife acceptance factor

cweitkamp commented 6 years ago

@andyzlen Thanks for the detailed explanation. I understand your use case and the two resulting issues which are:

  1. Suppress superfluous decimals / Round numeric values to specified precision (number of digits after the decimal point) for TTS services
  2. Apply localized number format on numeric values

I second your opinion that it could be useful and more user-friendly to find a solution for both of them. But none of them is neither an issue of the Netatmo binding, nor of any other binding. On the one hand we could ask for adding this feature in the official Amazon Alexa Skill repository, on the other hand maybe it is even better - because it is a general problem for every TTS service - to ask for adding this feature in the framework (ESH) repository.

andyzlen commented 6 years ago

@cweitkamp. Thank you for your suggestion which could help also other members of the OH community. For allowing round numeric values to specified precision (number of digits after the decimal point) for TTS services I will open an issue with the proposal to provide a new “Voice” parameter in PaperUI – Configuration-System (org.eclipse.smarthome.voice): “number of digits after the decimal point for TTS services”. Handling of localized numeric values was discussed in another thread “Sending strings to Number-item is not locale independent!”. I would agree with @watou that this would be a great challenge to implement.