Converting integer to Hex

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?

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…

String hex = Integer.toHexString(val);

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

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 :frowning:

1 Like

Two good places to visit:

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

Quick quick quick Groovy overview:

2 Likes

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

1 Like

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:

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.

Glad I could help, and thank you!.

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)

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.

1 Like

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).

1 Like