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

[mqtt] Wrong decimal representation in Number channels #6662

Closed
bodiroga opened this issue Dec 11, 2018 · 9 comments
Closed

[mqtt] Wrong decimal representation in Number channels #6662

bodiroga opened this issue Dec 11, 2018 · 9 comments

Comments

@bodiroga
Copy link
Contributor

Hi @davidgraeff!

I don't know if I'm doing something wrong, but I'm seeing strange values in mqtt number channels. In my case I'm using a Homie device with latest ESH code base (I have done a git pull before the tests). Here you have what is being publish on the mqtt broker (using mosquitto_sub client):

homie/homie-3-temperature-sensor/temperature/temperature 24.49
homie/homie-3-temperature-sensor/temperature/humidity 57.70

And this is what is being received by the item (through the channel):

2018-12-11 13:57:32 - mqtt_homie300_embedded_mqtt_broker_homie_3_temperature_sensor_temperature_temperature updated to 0.24490000
2018-12-11 13:57:32 - mqtt_homie300_embedded_mqtt_broker_homie_3_temperature_sensor_temperature_temperature changed from 0.22350000 to 0.24490000
2018-12-11 13:57:32 - mqtt_homie300_embedded_mqtt_broker_homie_3_temperature_sensor_temperature_humidity updated to 0.57700000
2018-12-11 13:57:32 - mqtt_homie300_embedded_mqtt_broker_homie_3_temperature_sensor_temperature_humidity changed from 0.65640000 to 0.57700000

(Same values can be seen in Paper UI control tab, all values are 100 times smaller)

The configuration of the channel seems to be correct:

  • Unit: %
  • Settable: false
  • Format: 0-100
  • Name: Indoor humidity
  • Retained: true
  • Data type: float

I don't see anything wrong in the device, but something has changed recently, because a couple of weeks ago everything went smoothly. Any clue? 😕

Thanks for your support!

Aitor

@bodiroga bodiroga changed the title [mqtt] Wrong decimal representation is Number channels [mqtt] Wrong decimal representation in Number channels Dec 11, 2018
@davidgraeff
Copy link
Contributor

davidgraeff commented Dec 11, 2018

Someone has reported this on the forum as well.
Instead of parsing values myself I'm using the ESH core class TypeParser with the latest commit.
It seems to misinterpret values, but I wonder why the test suite didn't catch this.

This is a show stopper for OH 2.4, bummer.

Could be related to openhab/openhab-core#436

@maggu2810
Copy link
Contributor

Need to look at the code but it looks like a mix of DecimalType and PercentType.

@davidgraeff
Copy link
Contributor

TypeParser takes a list of possible types as an argument. In my list PercentageType appears before DecimalType. I guess what happens is that PercentageType grabs any value between 0 and 100 and outputs a value between 0-1 if converted to a string.

@maggu2810
Copy link
Contributor

maggu2810 commented Dec 11, 2018

For PercentType the value must be in range [0;100].
If the percent type value is requested as DecimalType (see PercentType.as(...) method), the value is divided by 100.

davidgraeff pushed a commit to davidgraeff/smarthome that referenced this issue Dec 11, 2018
Because TypeParser preferred PercentageType, all number values between 0-100 where always interpreted as percentage.
Fixed by only allowing DecimalType.

Signed-off-by: davidgraeff <david.graeff@web.de>
@bodiroga
Copy link
Contributor Author

I can confirm that the fix has solved the problem, that was really fast!

Thank you guys! 👍

@vzorglub
Copy link
Contributor

I have just upgraded to #1459
And it is not fixed

2018-12-12 10:57:07.319 [vent.ItemStateChangedEvent] - LargeBedroom_ThermostatAmbientTemp changed from 0.169 °C to 0.182 °C

Value sent 18.2

@bodiroga
Copy link
Contributor Author

Hi @vzorglub!

With "1459" you are talking about openHAB's snapshot version number, right? If that's the case, don't worry, as Kai pointed out here, the openHAB snapshot version usually doesn't include the latest ESH repo code, a build has to be manually triggered. My test has been done using the Eclipse IDE and there everything works correctly now, so the issue is, in fact, fixed 😉

Please, delete your newly created issue 👍

@vzorglub
Copy link
Contributor

vzorglub commented Dec 12, 2018 via email

@bodiroga
Copy link
Contributor Author

Ask @kaikreuzer, kindly, to build a new stable version of ESH and this fix will be included in the next snapshot 😉

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

No branches or pull requests

4 participants