Power measuring automation with Fritz 200


I have a question about nalysis of captured values with a Fritz 200 power plug.

The following item is defined:

Number Power1 "Aktuelle Leistung [%.2f W]" { channel="avmfritz:FRITZ_DECT_200:1:087610351029:power" }

and in the sitemap I can display the current power consumption and chart:

	Text item=Power1 icon="energy"
	Chart item=Power1 period=4h refresh=30000

I am using a rrd4j persistence:

Strategies {
    everyMinute:"0 * * * * ?"
    everyHour : "0 0 * * * ?"
    everyDay  : "0 0 0 * * ?"

    default = everyUpdate

Items {
    Power1 : strategy = everyMinute, restoreOnStartup
     * : strategy = everyChange, restoreOnStartup

I am logging the data of a fridge in the basement, so it goes on and off every 30min or so.
What I would like to do, is to display an average (or total) consumption for 24h and maybe a floating average for the last 1-2h, and compare it to a threshold to detect if it stops service and then generate an alarm.

Any Idea how this can be realized?

Hi Holger,

you are abled to calculate the average (or total) consumption based on the data stored in the persistence module. I would do it like this:


Number fritzDECT200Power "Power [%.2f W]" {

Number fritzDECT200AvgPower "Avg Power [%.2f W]"
Number fritzDECT200SumPower "Sum Power [%.2f W]"


import org.joda.time.*

rule "calculate FRITZ!DECT 200 values"
    Item fritzDECT200Power changed
    val avgPower = fritzDECT200Power.averageSince(now.minusDays(1), "rrd4j")
    val sumPower = fritzDECT200Power.sumSince(now.minusDays(1), "rrd4j")
    postUpdate(fritzDECT200AvgPower, avgPower)
    postUpdate(fritzDECT200SumPower, sumPower)

Here are some more infos about persistence in script and rules: https://github.com/openhab/openhab1-addons/wiki/Persistence.

Based on those items you are able to write your rules for comparing values and send notifications.

Please be aware that this examples may contain errors or typos, I wrote it down untested.


thanks for pointing me in this direction, but I get still some errors:
The averageSince is ok, but the sumSince generates an error: “The method sumSince(DateTime, String) is undefined for the type NumberItem” ???

Also the postUpdate is not working: “The method or field fritzDECT200SumPower is undefined” ?? But it is defined in the items!

SumPower shows the value of the actual power, AvgPower = “-”

You’ll need to cast the datetime items in to an IntValue. to do the math and to be able to power the update. Technically the sumpower should error but somehow kind of works.

You’ll mean like this:

rule "calculate FRITZ!DECT 200 values"
    Item fritzDECT200Power changed
then {
    var int avgPower = Power1.averageSince(now.minusDays(1),"rrd4j").intValue
    val int sumPower = Power1.sumSince(now.minusDays(1),"rrd4j").intValue
    postUpdate(fritzDECT200AvgPower, avgPower)
    postUpdate(fritzDECT200SumPower, sumPower)

but I have still the sumPower error.
Somehow the Eclipse designer is strange. It shows an error, but things work, and others don’t and you never know why.

Ok, besidet the error reported by the designer it is working now.
I had an error still in the trigger. This needs to be:

    Item Power1 changed

Thanks for helping!

Now I am confused!

I wanted the rule to trigger every minute to see the real average, so I changed the trigger to:

rule "calculate FRITZ!DECT 200 values"
   Time cron "0 * * * * ?"  //Trigger every minute

The typical load is about 70W and it is about 35% on currently. So an average of 26W makes sense.
If I look to the sitemap, press F5 in the browser, I see 25 or 26W, ok.
After a Minute I get an update and see the actual value, so 0W or 7xW.

What is going on here ???

1 Like

Hi Holger,

nice to hear that the above solution works.

I thought a little bit about your questions and I got some issues with my example I posted before. I think the sumSince method on the Power item does not return the real consumption. The measured Power is stored only every minute in the database, which does not match the real power consumption, only snapshots. I think you should switch the calculation of the total consumption to deltaSince on an Energy item.

Maybe you should create an item

Number Energy1 "Verbrauch [%.3f kWh]" { channel="avmfritz:FRITZ_DECT_200:1:XXXXXXXXX::energy" }

Number fritzDECT200DiffEnergy "Verbrauch (24h) [%.3f kWh]"

add it to your persistence and add following calculation to your rule

val diffEnergy = Energy1.deltaSince(now.minusDays(1), "rrd4j").floatValue
postUpdate(fritzDECT200DiffEnergy, diffEnergy)

What do you think?

Hi Christoph,

thanks for thinking a bit further.

Hmm, the deltaSince gives a value back between 2 points. I think this is not what I would need.
I need an integral about the power over time. So adding all samples every minute up and devide then trough the timesteps should be correct (with some inaccuracy).
But the total is not so much my interest, it is more the moving average so that I can see if something happens and then generate an alarm message in case,

By the way, is there any possibility to read the persistence data and export to Excel to do some maths?

Hi Holger,

I tested both ways yesterday (sumSince over 24h of power and deltaSince over 24h of energy) and they result nearly in the same values. Maybe there was a difference in the third decimal place. So it may be ignored. Both ways are valid.

I am no expert in persistence, so I am sorry to say that I am not able to answer your question about the Excel export. If you find a way or get an answer for that from anyone else please let me know. I am interested, too. Did you try the search function of this forum?

No, I did no further research, the Excel thing just came into my mind…

This morning I had some strange values coming out of the persistence, also the graph was totally wrong. Seem that the switch to summertime distorted something. I made a restart and now everything is ok again.

I currently use an 24h average and a 2h average, My Idea is to do something like If (2h-average/24h-average)<0.5 then send a notification as indication that something is not ok…

Hmm, I see again strainge things in the graph:

What you see on the left is a correct cooling cycle, but since 16:15 this makes no sense.
What is happening here???

One step back… it looks like the Fritz-Box is the bad guy! OH did not get any reply from the box, that gives the strange behaviour. After reset It now works ok again…