SAMPLE searched: Rule how to sum up monthly KW production from Solar panel.

962 views
Skip to first unread message

karsten.k...@gmail.com

unread,
Mar 3, 2014, 8:10:15 AM3/3/14
to ope...@googlegroups.com
Hi,

i am looking for summing up the KW production per day/ month.

I am reading the data ongoingly using a 1wire module. I get KW from the module. Need to recalculate that to KW/h and summ up the monthly production.

Any suggestion/ sample rules i might be able to use?

Thanks in advance
Karsten

Pauli Anttila

unread,
Mar 3, 2014, 12:11:04 PM3/3/14
to ope...@googlegroups.com
Here is my rule to calculate cumulative and daily energy consumption from instant power. Rule assume that instant power is Watts not KW's.

var long LastUpdate = 0
rule "Energy consumption calculation"
when 
Item InstantPower received update
then
var long currentTime = now.millis

if (LastUpdate != 0) {
var long timeElapsed = currentTime - LastUpdate

if (timeElapsed > 0) {
var Number power = InstantPower.state as DecimalType
var Number energyConsumption = (power * timeElapsed) / 3600000 / 1000 // kWh
postUpdate(CumulativeEnergyConsumption, CumulativeEnergyConsumption.state as DecimalType + energyConsumption)
postUpdate(DailyEnergyConsumption, DailyEnergyConsumption.state as DecimalType + energyConsumption)
}
}

LastUpdate = currentTime
end
rule "Clear daily consumption"
when
Time cron "0 0 0 * * ?"  // every day
then
postUpdate(DailyEnergyConsumption, 0)
end
 

-Pali



--
You received this message because you are subscribed to the Google Groups "openhab" group.
To unsubscribe from this group and stop receiving emails from it, send an email to openhab+u...@googlegroups.com.
To post to this group, send email to ope...@googlegroups.com.
Visit this group at http://groups.google.com/group/openhab.
For more options, visit https://groups.google.com/groups/opt_out.

karsten.k...@gmail.com

unread,
Mar 4, 2014, 4:31:22 AM3/4/14
to ope...@googlegroups.com
ok thanks, will try this - consumption versus creation should be no difference :)

Are you storing the daily values somewhere in persistence? and even more add them to a consumption chart?

thanks
Karsten

Manolis N

unread,
Mar 4, 2014, 8:41:09 AM3/4/14
to ope...@googlegroups.com
This is mine:

//******************************************
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
Reply all
Reply to author
Forward
0 new messages