Aeon HEM Reset Manager

With the ST push toward the new crap app, I have decided to move over to HE. On SE I had learned enough to customize some apps. One of the apps I really liked was the Aeon HEM Reset Manager by jscgs350 can an HE pro here tell me if this app can be modified to work on HE? Thx

/**

  • Aeon HEM Reset Manager
  • Copyright 2018 XLR8ED
  • Based on initial code by jscgs350 published in 2016
  • Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
  • in compliance with the License. You may obtain a copy of the License at:
  • Unless required by applicable law or agreed to in writing, software distributed under the License is distributed
  • on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
  • for the specific language governing permissions and limitations under the License.
  • Overview

  • This SmartApp resets the Aeon HEM on a user specified day every month at a time you specify.
  • Revision History

  • 11-22-2016 : Initial release
  • 02-16-2017 : Fixed scheduling issue and improved handling when the app is initially installed and when it's updated.
  • 12-12-2018 : Corrected for v5 HEM

*/

definition(
name: "Aeon HEM Reset Manager",
namespace: "XLR8ED",
author: "XLR8ED",
description: "Resets the HEM on a specified day/time of every month",
category: "My Apps",

preferences {
section("Choose an Aeon HEM to reset:") {
input(name: "meter", type: "capability.energyMeter", title: "Which Aeon HEM ? (tap here)", description: null, required: true, submitOnChange: true)
}
section("Reset Time of Day") {
input "time", "time", title: "At this time of day"
}
section("Reset Day of Month") {
input "day", "number", title: "On this day of the month"
}
}

def installed() {
log.debug "Aeon HEM Reset Manager SmartApp installed, now preparing to schedule the first reset."
}

def updated() {
log.debug "Aeon HEM Reset Manager SmartApp updated, so update the user defined schedule and schedule another check for the next day."
unschedule()
def scheduleTime = timeToday(time, location.timeZone)
def timeNow = now()
log.debug "Current time is ${(new Date(timeNow)).format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
log.debug "Scheduling meter reset check at ${scheduleTime.format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
schedule(scheduleTime, resetTheMeter)
}

def initialize() {
unschedule()
def scheduleTime = timeToday(time, location.timeZone)
def timeNow = now()
log.debug "Current time is ${(new Date(timeNow)).format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
scheduleTime = scheduleTime + 1 // Next day schedule
log.debug "Scheduling next meter reset check at ${scheduleTime.format("EEE MMM dd yyyy HH:mm z", location.timeZone)}"
schedule(scheduleTime, resetTheMeter)
}

def resetTheMeter() {
Calendar localCalendar = Calendar.getInstance(TimeZone.getDefault());
def currentDayOfMonth = localCalendar.get(Calendar.DAY_OF_MONTH);
log.debug "Aeon HEM meter reset schedule triggered..."
log.debug "...checking for the day of month requested by the user"
log.debug "...the day of the month right now is ${currentDayOfMonth}"
log.debug "...the day the user requested a reset is ${day}"
if (currentDayOfMonth == day) {
log.debug "...resetting the meter because it's when the user requested it."
meter.resetMeter()
} else {
log.debug "...meter reset not scheduled for today because it's not when the user requested it."
}
log.debug "Process completed, now schedule the reset to check on the next day."
initialize()
}

I have a HEM myself and I currently reset it on the 29th of each month using webcore. Right now I still have my HEM on ST but I control it with pistons in webcore on HE using hubconnect. I am probably going to have to move it over completely to HE soon though.

You could create a simple rule in RM to do this as well You just need run a custom action on your HEM on the day you want it to reset. The reset command may vary based on the driver you use, but someone can help you with that when your ready I am sure.

Other than a required tweak to your definition() section, nothing else looks obviously 'wrong' for HE.

definition(
name: "Aeon HEM Reset Manager",
namespace: "XLR8ED",
author: "XLR8ED",
description: "Resets the HEM on a specified day/time of every month",
category: "My Apps",
iconUrl: "",
iconX2Url: ""
)

If you add it into Apps Code like that, does it save and work as expected?

Thanks terminal3 & tomw

I am finally beginning the transition from ST to HE this week, HEM will probably be one of the last devices to move over since I had it logging and charting to Google Sheets.