Hubitat with Homemade Temperature, Humidity, Pressure and Light sensor

Humidity looks fine.

It's your stock code

Added
log.info "AdjustTemp: ${val}"

Produces
info AdjustTemp: val 4.06

Maybe I should do the same for humidity ?

Added
log.info "HumidityEvent: ${result.value}"

Produces
info HumidityEvent: 33.73

I'll post the logs tonight once the device goes wonky.

Hi Brian,
did you ever get around to reprinting your "case"

And on que the temperature changed right at 32F/0C

dev:27952019-10-30 10:33:56.748 pm info AdjustTemp: 655.23
dev:27952019-10-30 10:32:56.750 pm info AdjustTemp: 654.9
dev:27952019-10-30 10:31:58.742 pm info HumidityEvent: 49.73
dev:27952019-10-30 10:29:03.388 pm info AdjustTemp: 655.12
dev:27952019-10-30 10:27:56.707 pm info AdjustTemp: 655.23
dev:27952019-10-30 10:26:57.721 pm info HumidityEvent: 49.94
dev:27952019-10-30 10:25:56.700 pm info AdjustTemp: 0.01
dev:27952019-10-30 10:23:56.675 pm info AdjustTemp: 0.15
dev:27952019-10-30 10:21:56.675 pm info HumidityEvent: 50.49
dev:27952019-10-30 10:20:56.668 pm info AdjustTemp: 0.04
dev:27952019-10-30 10:18:56.680 pm info HumidityEvent: 49.49
dev:27952019-10-30 10:18:56.674 pm info AdjustTemp: 0.16
dev:27952019-10-30 10:16:56.630 pm info AdjustTemp: 0.28
dev:27952019-10-30 10:14:56.615 pm info HumidityEvent: 48.24
dev:27952019-10-30 10:13:56.609 pm info AdjustTemp: 0.43
dev:27952019-10-30 10:13:01.681 pm info HumidityEvent: 49.28
dev:27952019-10-30 10:10:56.609 pm info AdjustTemp: 0.31
dev:27952019-10-30 10:08:56.569 pm info AdjustTemp: 0.2

It breaks at this....

private def parseTemperatureEvent(def descMap)
{    		
    float temp = adjustTemp((zigbee.convertHexToInt(descMap.value) / 100.00).toFloat())

	return createTempertureEvent(temp)   
}

Actually I think the problem is that you are using metric programming and not including imperial measurements. I am basing that on the incorrect value for pressure too which in done in kPa instead of inHg

private def createPressureEvent(float pressure)
{
    def result = [:]
    result.name = "pressure"
    result.translatable = true
    result.unit = "kPa"
    result.value = pressure.round(1)
    result.descriptionText = "${device.displayName} ${result.name} is ${result.value} ${result.unit}"
	return result
}

The only reference to temperature scale is

private def createTempertureEvent(float temp)
{
    def result = [:]
    result.name = "temperature"
    result.value = temperature
    result.unit = "°${location.temperatureScale}"
    
    
    result.value = convertTemperatureIfNeeded(temp,"c",1) 
    result.descriptionText = "${device.displayName} ${result.name} is ${result.value} ${result.unit}"
    
    return result
}

You don't carry this throughout any coding when you should as it throws off any sort of proper calculations for non metric countries.

He he, you say [quote="sgrayban, post:564, topic:1816"]
I think the problem is that you are using metric programming and not including imperial measurements.
[/quote]
Actually I think the problem is to many places still using imperial ?
Remind me again, of how many countries still use imperial ? :stuck_out_tongue_winking_eye::rofl::stuck_out_tongue_closed_eyes:

That doesn't matter and it's a moot point seeing that Hubitat either is set for metric or imperial and that's a fact.

I find your comment rude and condescending. There is nothing wrong with either measurements as I can use either one...

And just for $#$@ and giggles I set my hub to use metric (C) and the value is still wrong..

image

image

No offense was intended. Hence the smileys

1 Like

Would you mind to add one more logging at

private def parseTemperatureEvent(def descMap)

I would like to know what is the raw value sent from the sensor. If you can log the descMap.value and zigbee.convertHexToInt(descMap.value), we should be able to narrow down the issue.

Thanks
Iman

I am pretty sure I printed the new design and it worked well with the battery pack.

I can't check because I am in Japan right now...

So this is what you want ?

descMap.value: 01B6

Yes, thanks, what is the value 01B6 translated to in the call to

It would be useful for me to understand the issue when we can map the descMap.value and val. Is 01B6 translated to 4.38 C?

Thanks
Iman

AdjustTemp: 5.270876

It looks like it's adjusting in F correctly. The error comes in play right at 32F then $val goes crazy.

descMap.value: 01F2 - createTempertureEvent: 5.120965

Even when I set the hub to use C for temperature its wrong

Hmm, This is not quite I expected. 1F2 should come out to 498. This should be pass to AdjustTemp method. If it is logged first thing in the method, it should print 4.98. The log should be 2 decimal digit like your post below. Zigbee sensor send temperature in Celsius multiples by 100 encoded in integer.

The value is filtered which may be higher if filter is enabled. The number is close enough. I will assume that the AdjustTemp: 5.270876 is log after the adjustment.

Now, from your last night result, I have a theory. Here it is 655.23 C looked like ‭FFF3‬ in the descMap.value. The FFF3 is a 16 bit signed integer. It should be converted to -13. In turn, it should be converted to -0.13 in Celsius. The theory is that zigbee.convertHexToInt(FFF3) should return -13. Instead, I suspect it returns 65523. If this is correct, I have to find a way to convert the hex to signed integer using better way.

If the theory above is correct, your sensor should be ok. The driver can be fixed. We can find a way to convert a hex to integer the right way. But, I want to make sure that we confirm the value on the val AdjustTemp method first thing before any code executed in the method.

Thanks
Iman

That is exactly what is happening.

I spent hours trying to convert it correctly but I didn't succeed at all.

How ever I was able to fix the pressure to show US standards.

It is a groovy. There should be another way to convert hex string to singed integer. I will update you when I found a solution. I hate to write the code doing the conversion by myself. BTW, which version of hubitat do you use? Since the code depend on zigbee.convertHexToInt, this is a bug that could have been fixed also by the hubitat team.

My opinion about unit is that the code should convert what every the zigbee sent with Zigbee intended. For example, DTH should capture Temperature in C and Pressure in kPa. The GUI should convert them for display to current locale of the hub is set. This is easier said than done. I believe Temperature has done so well. We just need to send value as Zigbee reported in C. The display should display in F or C automatically depending on the locale. In the case of pressure, the same should also be done. Sensor should report in Zigbee standard. The GUI should convert them to kPa or Hg based on the hub locale setting.

Rev C-4

It didn't. My solution which works like a charm and should work with any hub version.

private def createPressureEvent(float pressure)
{
    def result = [:]
    result.name = "pressure"
    result.translatable = true
    result.scale = "${location.temperatureScale}"
    if (result.scale != "F") {
    result.unit = "kPa"
    result.value = pressure.round(1)
    } else {
    result.unit = "inHg" // US and it's territories uses inches of mercury
    result.value = pressure.round(2)
    }
    result.descriptionText = "${device.displayName} ${result.name} is ${result.value} ${result.unit}"
	return result
}

@mike.maxwell any comment on this ? It's not working on my C-4 hub.

use the following:
Long hexStrToUnsignedInt(String hexStr)
or
Long hexStrToSignedInt(String hexStr)
then the other way:
String intToHexStr(Integer value, Integer minBytes = 1)

2 Likes

@mike.maxwell, thank you.

@anon61068208, I think we want to try to use Long hexStrToSignedInt(String hexStr) for temperature.

1 Like

absolutely, zigbee temperature attributes are signed...

2 Likes