Java Runtime Environment: which java platform is used and what version
openHAB version: 2
Issue of the topic
I like to calculate the totalpower of my wallplugs. therfore i put in the items
Number Z_way_number_WallPlug8_totalpower "Wallplug8 [%.1f]" {channel="zway:zwayDevice:d5ec35fd:8:sensorMultilevel-ZWayVDev_zway_8-0-50-0"}
Number Z_way_number_WallPlug8_totalpower "Wallplug9 [%.1f]" {channel="zway:zwayDevice:d5ec35fd:9:sensorMultilevel-ZWayVDev_zway_9-0-50-0"}
Number totalpower "[%.2f]"
my rule
rule "totalpower"
when
Time cron "0/10 0 0 ? * * *" // Every 10 seconds
then
var float vv = Z_way_number_WallPlug8_totalpower.floatValue + Z_way_number_WallPlug9_totalpower.floatValue
totalpower.postUpdate(vv)
logInfo("vv",vv)
end
Is there a reason you’re trying to do in a rule rather than as an aggregate group?
On phone else I’d link to the documentation. But you can do sum and average on all items in a group and it stores that value and updates it whenever any group items update
Time cron "0/10 0 0 ? * * *"
// ^ ^ ^ ^ ^ ^ ^
// | | | | | | Every year
// | | | | | Every day of Week
// | | | | Every Month
// | | | Day of Month does not matter
// | | Hour has to be 0 (!)
// | Minute has to be 0 (1)
// Every 10 Seconds, beginning with 0
So your rule will trigger each 10 seconds when it’s 12:00 a.m. use asterisks for minute and hour
When it comes to total power consumption, please be aware that power sensors will do integral math themselves, so the given number is already a measurement for a time segment. Your power calculation has to use the same time segment as the power sensor.
rule "totalpower"
when
Time cron "0/10 * * ? * * *"
then
var float totalpower = (group_house_totalpower.members[m].state as DecimalType).sum
number_totalpower.postUpdate(totalpower)
end
but error is
'state' is not a member of 'java.util.concurrent.CopyOnWriteArrayList';
doing these kind of calculations within a rule that fires upon a cron schedule is somewhat inefficient
the best method is to use a persistence service.
You can then use the persisted states within a rule.
If you want to calculate the comsumtion this is not the way.
You need to calculate the energy in kwh or wh
It is quite impossible to calculate it just measuring the power at a defined period but if you want a very rough energy value by measuring the istant power every 10 second you need to use the following formula:
Energi10s=totalpower*10/3600 this will be a very rough value of the energy comsubtion each 10 sec.
I also suggest to measure the total energy each 10 sec as totalenergy=totalenergy+energy10s
Later I suggest to use persistance so you can calculate the daily, month and year energy
Take care that this energy measurement is very very rough …
Regards
Lorenzo
don’t mix the topics
Persistence Service configuration tells openHAB to store on predefined intervals the state of the Items
Your persistence config will store everyMinute the state of the Items which are members of the group_house_actualpower Group (and will also perform restoreOnStartup).