Help adding tile in DH

Hi, I have multiple temperature/humidity sensors. I would like to compare absolute humidity inside to outside.
The humidity sensors shows relative humidity.

It would be nice if I could just see the absolute humidity on the sensors then I could quickly compare with outside sensor.

The DH I am using is this:
https://pastebin.com/x8vfpTw5

I would like a new tile that displays the following SUM:
(6,112*2,71828^((17,67*TEMP)/(TEMP+243,5))*RH*2,1674)/(273,5+TEMP)

TEMP = temp from sensor
RH = Relativ humidity from sensor

I am absolutely new to Groovy.

Could anyone help me in the right direction?

Hi @SLKDK, are you trying to add that tile from values from another sensor?

1 Like

Hi @johnconstantelo , just value from same sensor.

I guess I need to add function so I can create tile to pull value from like device.absolutehumidity

Hope you can help me further :slight_smile:

1 Like

I can help, but give me a day or two? I’ve got 1 other project to polish off.

1 Like

Hi @SLKDK, I haven’t forgot about you. I’ve had a crazy busy week at work. I’ll work on this over the weekend.

1 Like

Hi @johnconstantelo no worries mate. I am just glad that you will help me. Please take your time :slight_smile:

Hi @SLKDK, almost done!

See the post right below this one.

Hi @SLKDK,

Here you go!

https://raw.githubusercontent.com/constjs/jcdevhandlers/master/devicetypes/jscgs350/xiaomi-temperature-sensor-with-abs-humidity.src/xiaomi-temperature-sensor-with-abs-humidity.groovy

Changes are:

  • Added custom attribute called absoluteHumidity (line 25)
  • Added absolute humidity value to the main “hero” tile (lines 57-59)
  • Added a separate tile just in case you wanted that too (lines 67-69)
  • Made sure the tile shows up for the device (line 78)
  • Added all the code to calculate the value and send it to ST (lines 98-110)

I probably could have cleaned up my code a bit, but the way I did it helped me make sure the math, variables, and the results were right. Feel free to clean it up, and/or adjust the look and feel. As soon as the device refreshes, or updated values get set, the tiles will update.

I was able to test the same code on an ST temp/humidity sensor and it worked, so please check on your device. You’ll also now find that custom attribute is exposed and available for SmartApps:

My sources to make sure I had the formula correct:

My source to make sure the values were correct:

Let me know how this works out!

2 Likes

Wow @johnconstantelo thank you so much! Not only for adding the tile but also explaining me what you did. I actually understand it :slight_smile:

I have tried to modify the main tile with my new knowledge. The reason for this is that I would like to see temperature and RH in the overview in a “Room”. So I don’t have to click on every temp/humidity sensor I have to see both temperature and humidity.

But I have a couple of questions regarding this:

Is it possible to still colour the background based on temperature?
Sometimes the RH in main tile is 1 update behind the smaller detail tile. Can’t figure out why?

Please see my updated DH code here: https://pastebin.com/UXFh2dUZ

Screenshot:

1 Like

No problem, glad to be able to help someone out.

No unfortunately. That’s because what’s being passed into currentValue doesn’t match up with any values within backgroundColors. BUT, see below for a solution!

That is related to a platform bug I believe. I have a few devices that are doing this, as well as a few other users. I have a support ticket open with ST on this.

You can still do this, and keep the main temperature tile the way it was so it changes color.

Here’s updated code that adds a new tile that’s only used for displaying results in a Room view:
https://raw.githubusercontent.com/constjs/jcdevhandlers/master/devicetypes/jscgs350/xiaomi-temperature-sensor-with-abs-humidity.src/xiaomi-temperature-sensor-with-abs-humidity.groovy

Room View: (this is an ST sensor)

Main Tile: (this is an ST sensor)

1 Like

Thank you again :slight_smile:

I see where I got it wrong. Should have added it as a valuetile and then just added that valuetiles name in the ‘main’.

So nice of you for helping and I am learning at the same time! :slight_smile:

1 Like

Anytime, and you’re very welcome. That’s what this Community is all about!

2 Likes