openhab / openhab-addons

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

[jeelink] TX22 rain state calculation is wrong #10358

Closed berny92at closed 1 year ago

berny92at commented 3 years ago

The rain data from a TX22 sensor is calculate incorrect:

e.g. [ternal.lacrosse.Tx22ReadingConverter] - Creating reading from: OK WS 61 1 255 255 255 0 12 255 255 255 255 255 255 0

[.internal.lacrosse.Tx22SensorHandler] - updating states for thing WS-1600 (8fa277977e): sensorId=61: channel=0, temp=null, hum=null, batLow=false, batNew=false rain=24 windDirection=null windSpeed=null windGust=null pressure=null

In the TX22 data the values for the rain are the 8th & 9th values (0 12) The correct result for rain is 6 (not 24 as calculated)

The correct formular is: rain = ( v1 256 + v2 ) 0.5

My assumption is, that the first part is divided ba 0.5 (and not multiplied)

lsiepel commented 1 year ago

@berny92at i might look at this issue. As this is an older issue, can you confirm this is still a valid issue (with openHAB 3.4.1) and are you available to test?

berny92at commented 1 year ago

Thank you for looking into this.

Yes I can confirm that this still exists. I'm using Jeeling Binding v 3.4.1 Logs from just about now:

2023-01-14 01:16:07.001 [TRACE] [ternal.lacrosse.Tx22ReadingConverter] - Creating reading from: OK WS 16 1 4 45 255 0 9 255 255 255 255 255 255 0 2023-01-14 01:16:07.018 [DEBUG] [.internal.lacrosse.Tx22SensorHandler] - updating states for thing WS-1600 (ws1600): sensorId=16: channel=0, temp=6.9, hum=null, batLow=false, batNew=false rain=18 windDirection=null windSpeed=null windGust=null pressure=null

jeelink calculated rain value = 18 correct value would be 4.5

I'm available for testing.

lsiepel commented 1 year ago

Yeah, i can confirm this. The decoding of the message is provided with this comment:

/**
                 * Format
                 * 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
                 * -------------------------------------------------------------------
                 * OK WS 14 1 4 208 53 0 0 7 8 0 29 0 31 1 4 1 I D=0E 23.2°C 52%rH 0mm Dir.: 180.0° Wind:2.9m/s
                 * Gust:3.1m/s new Batt. 1025 hPa
                 * OK WS ID XXX TTT TTT HHH RRR RRR DDD DDD SSS SSS GGG GGG FFF PPP PPP
                 * | | | | | | | | | | | | | | | | | |-- Pressure LSB (optional, FF/FF = none)
                 * | | | | | | | | | | | | | | | | |------ Pressure MSB (optional)
                 * | | | | | | | | | | | | | | | |---------- Flags *
                 * | | | | | | | | | | | | | | |-------------- WindGust * 10 LSB (0.0 ... 50.0 m/s) FF/FF = none
                 * | | | | | | | | | | | | | |------------------ WindGust * 10 MSB
                 * | | | | | | | | | | | | |---------------------- WindSpeed * 10 LSB(0.0 ... 50.0 m/s) FF/FF = none
                 * | | | | | | | | | | | |-------------------------- WindSpeed * 10 MSB
                 * | | | | | | | | | | |------------------------------ WindDirection * 10 LSB (0.0 ... 365.0 Degrees)
                 * FF/FF = none
                 * | | | | | | | | | |---------------------------------- WindDirection * 10 MSB
                 * | | | | | | | | |-------------------------------------- Rain * 0.5mm LSB (0 ... 9999 mm) FF/FF = none
                 * | | | | | | | |------------------------------------------ Rain * 0.5mm MSB
                 * | | | | | | |---------------------------------------------- Humidity (1 ... 99 %rH) FF = none
                 * | | | | | |-------------------------------------------------- Temp * 10 + 1000 LSB (-40 ... +60 °C)
                 * FF/FF = none
                 * | | | | |------------------------------------------------------ Temp * 10 + 1000 MSB
                 * | | | |---------------------------------------------------------- Sensor type (1=TX22, 2=NodeSensor)
                 * | | |------------------------------------------------------------- Sensor ID (0 ... 63)
                 * | |---------------------------------------------------------------- fix "WS"
                 * |------------------------------------------------------------------- fix "OK"
                 *
                 * Flags: 128 64 32 16 8 4 2 1
                 * | | |
                 * | | |-- New battery
                 * | |------ ERROR
                 * |---------- Low battery
                 */

The actual parsing does:

Integer rain = "255".equals(matcher.group(6)) ? null
                        : (Integer.parseInt(matcher.group(6)) * 256 + Integer.parseInt(matcher.group(7))) * 2;

So i change that in 0.5

lsiepel commented 1 year ago

Test version 3.4.2. is here: https://1drv.ms/u/s!AnMcxmvEeupwjqVCE_YtH3yeZG5hXA?e=a1d7Hv

Please enable debug logging if you encounter any errors. Two changes:

berny92at commented 1 year ago

For the rain-bug: works correct now:

308 │ Active │  80 │ 3.4.2.202301141352     │ openHAB Add-ons :: Bundles :: JeeLink Binding

Logfile output:

2023-01-15 17:25:23.087 [TRACE] [ternal.lacrosse.Tx22ReadingConverter] - Creating reading from: OK WS 16 1 255 255 255 0 20 2 163 0 0 255 255 0
2023-01-15 17:25:23.089 [DEBUG] [.internal.lacrosse.Tx22SensorHandler] - updating states for thing WS-1600 (ws1600): sensorId=16: channel=0, temp=null, hum=null, batLow=false, batNew=false rain=10 windDirection=67.5 windSpeed=0.0 windGust=null pressure=null

Rain value Jeelink binding: 10 Correct rain value: 10