* You may need to change the device type to this device handler after you pair it to your hub. I'm not sure why it doesn't always automatically pair using this handler even though the fingerprint matches...
* Also, you need to hit the button on the back of the HEM Gen5 a couple (two-three) times to get it to flash the red light on the front rapidly to ensure it's in inclusion mode. It isn't in the right mode if it's just flashing slow.
* Once the red light is solid, look in your things list and find it, could be just called z-wave, then change it's name and device type using the graph api to this custom handler to make it start working.
* The config with default intervals will send right away after you set the HEM Gen5 to this handler, please wait a few minutes before sending the config again or changing the intervals under preferences.
* The purpose of the config button is just really to resend the config with monitor interval prefs, as sometimes the config isn't fully applied, See the list of config items at the bottom of this code.
* You may need to send the config a few times, with about 2 minutes delay between to get all the properties to take. Not sure why-but if you look in the debug log in the graph api for this device you can see if they all applied.
* I had to unplug and replug my device after extensive testing and repeatedly setting the config over and over. Could be it works for you the first time, or you may need to pull power and re plug too in order to get all the Pole 1/2 data to show in the app.
*
* Known Issues:
* Issue 1:
* Not sure if this is the device handler or just a general SmartThings IOS App issue but sometimes when you set the preferences, it just spins in the app.
* If you are watching the log you can see it did set the preferences. Not sure why the app gets stuck, but just reload the app and should be fine.
* Issue 2:
* Not really a problem, more like a limitation; the clamps 1/2 data packets are sent to the ST hub based on monitor intervals for reports groups 1-3 which you can set in the device preferences.
* What this means is that, if you are paying attention to the tile data, you'll notice the center Total values don't quite work out to be the sum of Pole 1/2 values.
* This is simply because the base HEM data can be "polled" whereas the clamp 1/2 data is sent. And only sent on a schedule.
*
* Change log:
* v0.1 - released 04/04/16:
* Added support for secure inclusion and command encapsulation
* v0.2 - released 04/05/16:
* Added configuration settings using some preference variables that you can control from the app
* v0.3 - released 04/05/16:
* Added clamp1 and clamp2 data display, may have to hit configure a few times (wait at least 2 minute each time) to make the top left and right boxes show data from the clamps.
* v0.4 - released 04/06/16:
* Changed the "main" tile to display a clean total kWh, although the ST app seems to make everything on the main Things list all CAPS so it's actually displayed as KWH...
* v0.5 - released 04/07/16:
* Changed the main thing list device icon to st.Lighting.light14 cause it has a leaf!.
* v0.6 - released 04/07/16:
* Added a cost per kWh preference and a cost tile that is calculated on kWh.
* Also added a timestamp of last reset button tap to work with above cost feature.
* v0.7 - released 04/08/16:
* Removed individual value tile polling actions and polling function.
* Cleaned up and well-formed code
* v0.8 - released 04/15/16:
* Slightly adjusted the size of the tiles to fit all tiles into the App screen without scrolling.
* Further commented and cleaned up the code in preparation for submission to SmartThings as an official device handler.
* Submitted for consideration by SmartThings.
*
* To do:
* Features:
* Color code tiles or tile values for hi/low usage conditions.
* Possibly integrate a second tile set page with peak/min usage of watts and/or amps values over time.
* Integrate PlotWatt or other online Energy tracking API based service.
* Fixes:
* Determine why app sometimes freezes when setting preferences, I have seen this with other devices, e.g. Arrival Sensor, Jasco Wall Switches, etc...
*
*/
// metadata
metadata{
definition(name:"Aeon HEM Gen5(zwave plus)",namespace:"DuncanIdahoCT",author:"Dillon A. Miller"){
descriptionText:"This sensor failed to complete the network security key exchange. If you are unable to control it via SmartThings, you must remove it from your network and add it again.")
log.debug"---CONFIGURATION REPORT V1--- ${device.displayName} parameter ${cmd.parameterNumber} with a byte size of ${cmd.size} is set to ${cmd.configurationValue}"
//NOTE ScaledPreviousMeterValue does not always contain a value
defpreviousValue=cmd.scaledPreviousMeterValue?:0
//Here is where all HEM polled values are defined. Scale(0-7) is in reference to the Aeon Labs HEM Gen5 data for kWh, kVAh, W, V, A, and M.S.T. respectively.
//If scale 7 (M.S.T.) is polled, you would receive Scale2(0-1) which is kVar, and kVarh respectively. We are ignoring the Scale2 ranges in this device handler.
//This is where the HEM clamp1 and clamp2 (subdevice) report values are defined. Scale(2,5) is in reference to the Aeon Labs HEM Gen5 (subdevice) data for W, and A respectively.
//Z-Wave Command Class 0x60 (multichannelv3) is necessary to interpret the subdevice data from the HEM clamps.
//In addition, "cmd.commandClass == 50" and "encapsulatedCommand([0x30: 1, 0x31: 1])" below is necessary to properly receive and inturpret the encasulated subdevice data sent to the SmartThings hub by the HEM.
//The numbered "command class" references: 50, 0x30v1, and 0x31v1 do not seem to be true Z-Wave Command Classes and any correlation is seemingly coincidental.
//It should also be noted that without the above, the data received will not be processed here under the 0x60 (multichannelv3) command class and you will see unhandled messages from the HEM along with references to command class 50 as well as Meter Types 33, and 161.
//sourceEndPoint 1, and 2 are the Clamps 1, and 2.
defdispValue
defnewValue
defformattedValue
defMAX_AMPS=220
defMAX_WATTS=24000
if(cmd.commandClass==50){//50 is likely a manufacturer specific code, Z-Wave specifies this as a "Basic Window Covering" so it's not a true Z-Wave Command Class.
defencapsulatedCommand=cmd.encapsulatedCommand([0x30:1,0x31:1])// The documentation on working with Z-Wave subdevices and the technical specs from Aeon Labs do not explain this adequately, but it's necessary.
//log.debug ("Command from endpoint ${cmd.sourceEndPoint}: ${encapsulatedCommand}")
//This is where the tile action "refresh" is defined. Refresh is very basic. It simply gets and displays the latest values from the HEM exclusive of the clamp subdevices.
zwave.meterV3.meterGet(scale:0),//kWh
zwave.meterV3.meterGet(scale:2),//Wattage
zwave.meterV3.meterGet(scale:4),//Volts
zwave.meterV3.meterGet(scale:5),//Amps
]
commands(request)
}
defreset(){
//This is where the tile action "reset" is defined. Reset is only meant to be used once a month on the end/beginning of your electric utility billing cycle.
//Tapping reset will send the meter reset command to HEM and zero out the kWh data so you can start fresh.
//This will also clear the cost data and reset the last reset timestamp. Finally it will poll for latest values from the HEM.
//This has no impact on Pole1 or Pole2 (clamp1 and clamp2 subdevice) tile data as that is sent via reports from the HEM.
//This is where the tile action "configure" is defined. Configure resends the configuration commands below (using the variables set by the preferences section above) to the HEM Gen5 device.
//If you're watching the debug log when you tap configure, you should see the full configuration report come back slowly over about a minute.
//If you don't see the full configuration report (seven messages) followed by the association report, tap configure again.