bspranger / Xiaomi

my Xiaomi Device Handlers for Smartthings
Apache License 2.0
521 stars 1.36k forks source link

Issue: 510% humidity report #73

Closed ronvandegraaf closed 6 years ago

ronvandegraaf commented 6 years ago

I am using the humidity reports for a custom Smart Home Monitor rule. When Humidity goes under 40% or over 60%.

Only the last couple of days I got multiple 510% reports. Everytime it's the same extreme high value: '510'. SmartThings can also report 51% als a correct value.

Event report description | Bedroom Sensor Humidity is 510% name | humidity rawDescription | humidity: 51% translatable | false unit | % value | 510

alecm commented 6 years ago

That's odd - I'll run a hot shower when I get home... are you using the old or the Aqara?

alecm commented 6 years ago

I wasn't able to recreate - with the old Xiaomi - my Aqara has to be re-paired

bspranger commented 6 years ago

Can you post the actual live log from the IDE? Or is that what your data is from?

alecm commented 6 years ago

hiya - so I had something similar - briefly had a report of 650 humidity!

So - take a look

image

raw description is 65% - this converts to 650

in this one

image

the raw is 48.38% which converts to 48%

Cluster 0x0405 is relative humidity Attribute 0x0000 Measured value is defined as 100 x Relative humidity Where 0% <= Relative humidity <= 100% and has the uint16 range 0 to 0x2710 (0 to 10000 decimal) (from zigbee cluster library)

So input 4838 = 48.38% relative humidity 6500 should be 65.00% relative humidity but it's somehow coming in as 650

I think it has to do w/ dropping the decimals when they are parsed and value is .00 - or in the conversion that happens after... (the BigDecimal part is a little beyond me right now without spending more time on it)...

veeceeoh commented 6 years ago

Since, unlike the battery reporting, both Xiaomi temp/humidity sensors use standard ZigBee clusters for reporting temperature & humidity, I think we can just borrow the much simpler relevant code from the SmartSense ZigBee Temp/Humidity sensor device handler. Here's the relevant section to adapt to the two Xiaomi device handlers:

def parse(String description) {
    log.debug "description: $description"

    // getEvent will handle temperature and humidity
    Map map = zigbee.getEvent(description)
    if (!map) {
        Map descMap = zigbee.parseDescriptionAsMap(description)
        if (descMap.clusterInt == 0x0001 && descMap.commandInt != 0x07 && descMap?.value) {
            map = getBatteryResult(Integer.parseInt(descMap.value, 16))
        } else if (descMap?.clusterInt == zigbee.TEMPERATURE_MEASUREMENT_CLUSTER && descMap.commandInt == 0x07) {
            if (descMap.data[0] == "00") {
                log.debug "TEMP REPORTING CONFIG RESPONSE: $descMap"
                sendEvent(name: "checkInterval", value: 60 * 12, displayed: false, data: [protocol: "zigbee", hubHardwareId: device.hub.hardwareID])
            } else {
                log.warn "TEMP REPORTING CONFIG FAILED- error code: ${descMap.data[0]}"
            }
        }
    } else if (map.name == "temperature") {
        if (tempOffset) {
            map.value = (int) map.value + (int) tempOffset
        }
        map.descriptionText = temperatureScale == 'C' ? '{{ device.displayName }} was {{ value }}°C' : '{{ device.displayName }} was {{ value }}°F'
        map.translatable = true
    } else if (map.name == "humidity") {
        if (humidityOffset) {
            map.value = (int) map.value + (int) humidityOffset
        }
    }

    log.debug "Parse returned $map"
    return map ? createEvent(map) : [:]
}

As luck would have it, I finally received my Aqara Temp / Humidity sensor in the mail today, so this weekend I will try re-working the code to hopefully fix this issue.

veeceeoh commented 6 years ago

I have adapted that SmartSense Temp/Humidity snesor DTH code, and it works great! No more humidity percentages in the 100s!

The only downside is that temperature is reported as an integer. I looked at bunch of other temp sensor DTHs, and that is the standard.

I have no problem with dropping the one decimal place of "accuracy", but let's see what everyone else thinks. I can always revert back to the old code for just the temperature reports.