rule "powerstats"
when
Item zwavetotal received update
then
logInfo( "rules.powerstats", "starting..")
var Number totalPower = zwavetotal.state as DecimalType
var Number avToday = (zwavetotal.averageSince(now.minusHours(now.getHourOfDay))/1000).intValue
var Number avMonth = (zwavetotal.averageSince(now.minusDays(now.getDayOfMonth()))/1000).intValue
var Number avTotal = (zwavetotal.averageSince(now.minusDays(now.getDayOfYear))/1000).intValue
var Number eToday = totalPower - zwavetotal.historicState(now.minusHours(now.getHourOfDay)).state as DecimalType
var Number eYesterday = totalPower - zwavetotal.historicState(now.minusHours(now.getHourOfDay).minusDays(1)).state as DecimalType
var Number avYesterday = ((eYesterday - eToday)/24).intValue
if(totalenergy .historicState(now.minusDays(now.getDayOfMonth())) !=null){
var Number eMonth = totalPower - zwavetotal.historicState(now.minusDays(now.getDayOfMonth())).state as DecimalType
postUpdate( Energy_used_month, eMonth )
}
postUpdate( Energy_used_today, eToday )
postUpdate( AvPower_today, avToday )
postUpdate( AvPower_yesterday, avYesterday )
postUpdate( AvPower_month, avMonth )
postUpdate( AvPower_total, avTotal )
logInfo( "rules.powerstats", "finished..")
end
//******************************************
Not sure if this the best way to do it, but it works.
I am only displaying these values, but you could store them on a new item with a daily cron rule, so you can plot that item on a chart.
-Manolis