I have an issue when I want to transfer humidty data from my ESP32 to openHAB via MQTT and Homie. The value gets converted to decimal instead of staying percentage.
I use Leifhomielib for the ESP32. It is working fine for everything except percent-values.
The homie node looks like this:
Unit is set to %.
openHAB is receiving the value as decimal instead of percentage:
2020-04-29 22:11:44.291 [vent.ItemStateChangedEvent] - OU_Backyard_RelativeHumidity changed from 0.5009 % to 0.5005 %
I realized now that this wasnât a problem before.
On my second stable installation the percent values get changed to decimals too.
This must have happened through an update.
Unfortunately I donât know how to contribute to solve the issue. I can only give out logs.
I tried a workaround and just multiplied the outgoing value times 100.
openHAB is realizing it is out of range now.
2020-04-30 08:53:07.883 [WARN ] [ab.binding.mqtt.generic.ChannelState] - Command '5434.96' not supported by type 'PercentageValue': Value must be between 0 and 100
My second question is solved:
2020-04-30 08:48:38.645 [vent.ItemStateChangedEvent] - OU_Backyard_AbsoluteHumidity changed from 11.32 g/mÂł to 11.29 g/mÂł
I havn´t tried myself, but I would assume a JS script in the transformation path for the thing could be used to multiply by 100. It works for modbus, where I use it. But I´m not sure MQTT support it (It should do as default, in my opinion).
This is how it looks like in modbus2 binding:
Thing data inp204 [ readStart="204", readValueType="int16", readTransform="JS(divide100.js)" ]
This is the script for multiply by 100:
filename:
multiply100.js
// Wrap everything in a function
(function(i) {
return Math.round(parseFloat(i, 10) * 100);
})(input)
// input variable contains data passed by openhab
So if you insert this part into your thing setupâŚ
readTransform="JS(multiply100.js)"
copy the multiply100.js to your transform folder
Make sure you have the transformation service added.
⌠it might work.
If not⌠I would say some maintainer of mqtt have a job to do
Every other item from this Homie device is working as expected. Only humidity has problems by dividing the value by 100.
Does your item look similar?
Thanks for assisting me!