# Converting integer to Hex

**URL:** <https://community.smartthings.com/t/converting-integer-to-hex/57568>\
**Category:** General Discussion\
**Tags:** developers\
**Created:** [September 15, 2016, 7:06pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568 "2016-09-15T19:06:56Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aruffell](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/aruffell/32/42775_2.png) [@aruffell](https://community.smartthings.com/u/aruffell)\
**Post date:** [September 15, 2016, 7:06pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/1 "2016-09-15T19:06:56Z")

</div>

I am updating a DTH for the Aeon HEM that takes delay parameters for the devices configuration in HEX. How to I convert the integer values I collect from preferences over to HEX. I’ve done some searching but cannot find how to do it in Groovy. Any suggestions?

---

<div class="post-metadata">

**Author:** ![tgauchat](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tgauchat/32/49516_2.png) [@tgauchat](https://community.smartthings.com/u/tgauchat)\
**Post date:** [September 15, 2016, 7:17pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/2 "2016-09-15T19:17:35Z")

</div>

> [@aruffell](#):
>
> I’ve done some searching but cannot find how to do it in Groovy. Any suggestions?

Search for any **Java** math method (the Class may or may not be importable into the SmartThings sandbox).

I’ll do a quick search. It’s also not very hard to code, actually…

---

<div class="post-metadata">

**Author:** ![tgauchat](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tgauchat/32/49516_2.png) [@tgauchat](https://community.smartthings.com/u/tgauchat)\
**Post date:** [September 15, 2016, 7:18pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/3 "2016-09-15T19:18:56Z")

</div>

```auto
String hex = Integer.toHexString(val);

int parsedResult = (int) Long.parseLong(hex, 16);

```

---

<div class="post-metadata">

**Author:** ![aruffell](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/aruffell/32/42775_2.png) [@aruffell](https://community.smartthings.com/u/aruffell)\
**Post date:** [September 15, 2016, 7:24pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/4 "2016-09-15T19:24:26Z")

</div>

Thanks Terry! I will try it out soon!

The only programming languages I formally studied were COBOL and C for DOS over 20 years ago so I am totally rusty… but automating my home is reviving my interest in learning them again if only I had enough time ☹

---

<div class="post-metadata">

**Author:** ![tgauchat](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/tgauchat/32/49516_2.png) [@tgauchat](https://community.smartthings.com/u/tgauchat)\
**Post date:** [September 15, 2016, 7:38pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/5 "2016-09-15T19:38:30Z")

</div>

Two good places to visit:

A live Groovy tester (not sure what Java functions it supports):

- [http://groovyconsole.appspot.com/](http://groovyconsole.appspot.com/)

Quick quick quick Groovy overview:

- [https://learnxinyminutes.com/docs/groovy/](https://learnxinyminutes.com/docs/groovy/)

---

<div class="post-metadata">

**Author:** ![johnconstantelo](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/johnconstantelo/32/111869_2.png) [@johnconstantelo](https://community.smartthings.com/u/johnconstantelo)\
**Post date:** [September 15, 2016, 10:43pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/6 "2016-09-15T22:43:42Z")

</div>

> [@aruffell](#):
>
> I am updating a DTH for the Aeon HEM that takes delay parameters for the devices configuration in HEX

Hi @aruffell, I did the exact same thing for the HEM (v1), but I didn’t have to use HEX. Here’s a link to my code if you’d like to review:

[https://raw.githubusercontent.com/constjs/jcdevhandlers/master/devicetypes/jscgs350/my-aeon-home-energy-monitor.src/my-aeon-home-energy-monitor.groovy](https://raw.githubusercontent.com/constjs/jcdevhandlers/master/devicetypes/jscgs350/my-aeon-home-energy-monitor.src/my-aeon-home-energy-monitor.groovy)

---

<div class="post-metadata">

**Author:** ![aruffell](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/aruffell/32/42775_2.png) [@aruffell](https://community.smartthings.com/u/aruffell)\
**Post date:** [September 16, 2016, 3:55pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/7 "2016-09-16T15:55:12Z")

</div>

Thank you for sharing your code. At a glance I’ve noticed several things I can take inspiration from! Based on my research on the engineering specs of the HEM v2 it appears that the delay parameters are accepted in Hex format - is that not so?

/\*  
100 Set 101-103 to default. Default: N/A Size: 1  
101 Which reports need to send in Report group 1 (See flags in table below). Default: 0x00 00 00 02 Size: 4  
102 Which reports need to send in Report group 2 (See flags in table below). Default: 0x00 00 00 01 Size: 4  
103 Which reports need to send in Report group 3 (See flags in table below). Defualt: 0 Size: 4  
110 Set 111-113 to default. Default: N/A Size: 1  
111 The time interval of sending Report group 1 (Valid values 0x01-0xFFFFFFFF). Default: 0x00 00 00 05 Size: 4  
112 The time interval of sending Report group 2 (Valid values 0x01-0xFFFFFFFF). Default: 0x00 00 00 78 Size: 4  
113 The time interval of sending Report group 3 (Valid values 0x01-0xFFFFFFFF). Default: 0x00 00 00 78 Size: 4  
\*/

My current code is here:

> **[alexruffell/Aeon-HEMv2-Gen2-SmartThings-Device-Handler](https://github.com/alexruffell/Aeon-HEMv2-Gen2-SmartThings-Device-Handler)**
>
> Contribute to Aeon-HEMv2-Gen2-SmartThings-Device-Handler development by creating an account on GitHub.

I wonder whether your check for negative values, and huge values, is what I need to prevent my HEM from freezing up. Every so often it just stops sending data back.

---

<div class="post-metadata">

**Author:** ![johnconstantelo](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/johnconstantelo/32/111869_2.png) [@johnconstantelo](https://community.smartthings.com/u/johnconstantelo)\
**Post date:** [September 17, 2016, 3:45am UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/8 "2016-09-17T03:45:06Z")

</div>

> [@aruffell](#):
>
> Thank you for sharing your code. At a glance I’ve noticed several things I can take inspiration from!

Glad I could help, and thank you!.

> [@aruffell](#):
>
> Based on my research on the engineering specs of the HEM v2 it appears that the delay parameters are accepted in Hex format - is that not so?

It can accept HEX, but the way I’ve done it for the HEM v1 and the Aeon metering switch all worked too, plus it’s easier ;-). Here is another example but for the HEMv2 using the same process I’m using (all the way at the bottom):

(My DH was actually based of of this one)

> <https://github.com/SANdood/Aeon-HEM-v2/blob/master/Aeon%20HEMv2.groovy>

> [@aruffell](#):
>
> I wonder whether your check for negative values, and huge values, is what I need to prevent my HEM from freezing up. Every so often it just stops sending data back.

I’ve not run into a situation where a high number froze the HEM, but I have after a power outage and it failed over to the batteries and then when power was restored it stopped reporting. I ended up just taking the batteries out.

---

<div class="post-metadata">

**Author:** ![BrianAker](https://yyz2.discourse-cdn.com/smartthings/user_avatar/community.smartthings.com/brianaker/32/20442_2.png) [@BrianAker](https://community.smartthings.com/u/BrianAker)\
**Post date:** [December 31, 2017, 11:10pm UTC](https://community.smartthings.com/t/converting-integer-to-hex/57568/9 "2017-12-31T23:10:46Z")

</div>

There are a few z-wave devices which do not check for overflow when they receive a set configuration, Aeon has one or two such devices. Configuration values come in 1,2,3,4 sizes. Sending a value larger then what is allocated causes overflow (which can create unknown states in the devices).
