Yeasterdays energy used from Aeon Labs HEM

Posted on
Thu Jun 25, 2015 12:11 am
jlTech offline
Posts: 21
Joined: Jun 20, 2015

Yeasterdays energy used from Aeon Labs HEM

Can i somehow get the energy value for yeasterday from my Aeon Labs Energy Meter? Want to show it on a control page and send pushover message

Posted on
Thu Jun 25, 2015 9:09 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Yeasterdays energy used from Aeon Labs HEM

try this:

create variables
yesterdayRawEnergy
yesterdayEnergy

create a schedule to run at 0:00
add script in action:
- read variable yesterdayRawEnergy
- read currentRaw (accumEnergy?) number from device
- newEnergy=currentRaw -yesterdayRawEnergy
- store newEnergy into yesterdayEnergy
- store currentRaw into variable yesterdayRawEnergy

and convert variable / device numbers into float before you do math with them and convert to string before storing them into variables

then variable yesterdayEnergy will show yesterdays energy used in KWH


if you need the "real" code let me know. just typing this psydo code on my laptop.


Karl

Posted on
Thu Jun 25, 2015 11:17 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Yeasterdays energy used from Aeon Labs HEM

here the script that should do it..
Code: Select all
try:
   EnergyYesterdayRawID= indigo.variables["EnergyYesterdayRaw"]
except:
   indigo.variable.create("EnergyYesterdayRaw","0")
   EnergyYesterdayRawID= indigo.variables["EnergyYesterdayRaw"]

try:
   EnergyYesterdayID= indigo.variables["EnergyYesterday"]
except:
   indigo.variable.create("energyYesterday","0")
   EnergyYesterdayID= indigo.variables["EnergyYesterday"]


EnergyYesterday = float(EnergyYesterdayID.value)
EnergyYesterdayRaw = float(EnergyYesterdayRawID.value)


energyNowID=indigo.devices[374645596] # "MeterTotalLeftBox"

energyNow= float(energyNowID.states["accumEnergyTotal"])

usedYesterday = energyNow - EnergyYesterdayRaw

## for debugging only
indigo.server.log("EnergyYesterday     "+str(EnergyYesterday)) 
indigo.server.log("EnergyYesterdayRaw  "+str(EnergyYesterdayRaw))
indigo.server.log("energyNow           "+str(energyNow))
##

indigo.variable.updateValue("EnergyYesterday", str(usedYesterday))
indigo.variable.updateValue("EnergyYesterdayRaw", str(energyNow))

Karl

Posted on
Thu Jun 25, 2015 12:09 pm
RogueProeliator offline
User avatar
Posts: 2501
Joined: Nov 13, 2012
Location: Baton Rouge, LA

Re: Yeasterdays energy used from Aeon Labs HEM

One thing to note - that script doesn't account for resetting the accumulated energy total (some people do this monthly or weekly or really anything); the original poster did not mention this but might not be a bad idea to add a check in there if

This isn't 100% reliable, but could check if today's accumulation is less then yesterdays, assume it was reset and use the accumulated total as the difference?

Adam

Posted on
Thu Jun 25, 2015 1:56 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Yeasterdays energy used from Aeon Labs HEM

I know this is a very simple version. You could also add today's value extrapolated (#secsincemidnight/7xthousand)*currentvalue. And many more things.


Sent from my iPhone using Tapatalk

Posted on
Thu Jun 25, 2015 4:31 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: Yeasterdays energy used from Aeon Labs HEM

This one takes care of several conditions and can be run every xx minutes. Put it into a schedule that runs every e.g. 10 minutes and starts at 00:01

It will create all variables if they do not exist and will update them..

It formats the energy values in the variables using %6.1f should be enough for most situations. Creates e.g. 31.5 in the EnergyYesterday variable that value is in Kwh

Karl

Code: Select all
## if you reset your energy device at midnight, this must run AFTER the reset, call from a schedule at 0:01 + every x minutes
## calculates:
#   1. energy consumed yesterday
#   2. energy consumed today
#   3. energy consumption prediction for today, linear extrapolation from #2 and seconds since midnight
#
# v0.2:  fixed switch at midnight

## define your variable and device names here
vEnergyYesterday      = "EnergyYesterday"        # this is the name of the variable that shows the KwH consumed yesterday
vEnergyYesterdayRaw    = "EnergyYesterdayRaw"   # this is the name of the variable of the raw number read from the energy device at mignight
vEnergyToday          = "EnergyToday"          # this is the name of the variable that shows todays current engery consumed in KwH
vEnergyTodayPredicted    = "EnergyTodayPredicted" # this is the name of the variable that shows todays predicted total engery consumed in KwH
vEnergyDayNumber      = "EnergyDayNumber"      # this is the name of the variable that is used to keep trak if we have calculated yesterdays consumption. it is the day in the month number
dEnergy             = "MeterTotalLeftBox"    # this is the device name from where we read the energy info
dEnergyState         = "accumEnergyTotal"     # this is the state name of the device we read


# get dates and seconds
import datetime
rightNow          = datetime.datetime.now()
theDay             = rightNow.day
secondsSinceMidnight = (rightNow.hour * 3600) + (rightNow.minute * 60) + rightNow.second
secondsInAday       = float(60*60*24)


## get the values and if the variables dont exits, create them
try:
   vEnergyYesterdayRawID= indigo.variables[vEnergyYesterdayRaw]
except:
   indigo.variable.create(vEnergyYesterdayRaw,"0")
   vEnergyYesterdayRawID= indigo.variables[vEnergyYesterdayRaw]

##
try:
   EnergyYesterdayID= indigo.variables[vEnergyYesterday]
except:
   indigo.variable.create(venergyYesterday,"0")
   EnergyYesterdayID= indigo.variables[vEnergyYesterday]

##
try:
   vEnergyTodayPredictedID = indigo.variables[vEnergyTodayPredicted]
except:
   indigo.variable.create(vEnergyTodayPredicted,"0")
   vEnergyTodayPredictedID = indigo.variables[vEnergyTodayPredicted]

##
try:
   vEnergyTodayID = indigo.variables[vEnergyToday]
except:
   indigo.variable.create(vEnergyToday,"0")
   vEnergyTodayID = indigo.variables[vEnergyToday]

##
try:
   vEnergyDayNumberID = indigo.variables[vEnergyDayNumber]
except:
   indigo.variable.create(vEnergyDayNumber,"-1")
   vEnergyDayNumberID = indigo.variables[vEnergyDayNumber]


EnergyYesterdayRaw    = float(vEnergyYesterdayRawID.value) # this is the raw number from yesterday

energyNowID         = indigo.devices[dEnergy]
energyNow         = float(energyNowID.states[dEnergyState]) #  this is the new raw number from the device


# now calculate

if energyNow < EnergyYesterdayRaw: # need to reset?  works if reset happens at midnight, if it hapens during the day this is wrong, but you can only take care of some many variations ;-(
   EnergyYesterdayRaw =0


if theDay != int(vEnergyDayNumberID.value):  # if this is a new day, update yesterdays value
   indigo.variable.updateValue(vEnergyYesterday   , ("%6.1f"%(energyNow - EnergyYesterdayRaw)).strip(" "))
   indigo.variable.updateValue(vEnergyDayNumber   , str(theDay))
   indigo.variable.updateValue(vEnergyYesterdayRaw, str(energyNow ))
   EnergyYesterdayRaw = energyNow


EnergyToday              = energyNow - EnergyYesterdayRaw
EnergyTodayPredicted    = EnergyToday * secondsInAday/max(secondsSinceMidnight,1.)

indigo.variable.updateValue(vEnergyToday,          ("%6.1f"%EnergyToday).strip(" "))
indigo.variable.updateValue(vEnergyTodayPredicted, ("%6.1f"%EnergyTodayPredicted).strip(" "))


indigo.server.log("rightNow             "+str(rightNow))
indigo.server.log("theDay               "+str(theDay))
indigo.server.log("secondsSinceMidnight "+str(secondsSinceMidnight))
indigo.server.log("EnergyYesterdayRaw   "+str(EnergyYesterdayRaw))
indigo.server.log("EnergyToday          "+str(EnergyToday))
indigo.server.log("EnergyTodayPredicted "+str(EnergyTodayPredicted))



it creates variables like this:
Attachments
Screen Shot 2015-06-25 at 6.36.25 PM.png
Screen Shot 2015-06-25 at 6.36.25 PM.png (14.38 KiB) Viewed 1903 times

Posted on
Thu Jun 25, 2015 10:46 pm
jlTech offline
Posts: 21
Joined: Jun 20, 2015

Re: Yeasterdays energy used from Aeon Labs HEM

Working great Karl, thanks for all your help. :)

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 11 guests

cron