How to count compressor cycles of my heating pump?

Hi, i have a waterkotte heating pump and the ecotouch binding is working very good.

The heating pump has no function to count the compressor starts.

I get new values from my heating pump every 60 seconds. Compressor state can be ON or OFF.

How can i count the compressor starts?

Will something like this work?

if compressor.state changes from 0 to 1
     compressor_cycles = compressor_cycles + 1

Or do you know a better solution?

And my second question:

If i would persist the state with maybe db40, can i show the cycles of a given time period? Maybe how many start/stop in the last 7 days?

Simply create a rule:
When compressor changed to on
Compressor Start = Compressor Start + 1
End rule

I’m not completely sure about the syntax, but check the wiki for that, or let me know then I’ll check it later…

Ok, i think i will get this on my own. I can persist the data and so i get the values even if i restart openhab.

But what´s with the second part of my question? Can i read this data out of a persistence?


rule "Kompressor Starts zählen"
		Item HeatPump_state_compressor1 changed from OFF to ON
		HeatPump_compressor_count = HeatPump_compressor_count + 1

This is not working. Do i have to do this with variables? Or do i have to write it something like HeatPump_compressor_count.state as DecimalType ?


Number HeatPump_compressor_count "Verdichter Impulse [%d]"


rule "Kompressor Starts zählen"
		Item HeatPump_state_compressor1 changed from OFF to ON
		postUpdate(HeatPump_compressor_count, HeatPump_compressor_count.intValue + 1)

and if you put the HeatPump_compressor_count into the persistence cfg for rrd4j or mysql (or whereever) it is continously logged.

I guess you could also do it with a mapping linked to the heatpump_state_compressor1 and then mention it in the persistence cfg that it is written every change, or if you want to make a chart, every minute.

I want to put this into some persitence.

But can i read the persistence and maybe display “compressor starts of the last 7 days”?

If i only log the counting-item, i can see how many counts i had 7 days ago. So i have to do some math to get the value.

But is this the only way? Or can i read the counts directly from the persistence?

If you persists the counter, you can do some mathmatics with them. Check google for it, because this isnt self-explanatory :slight_smile:
But for example:

postUpdate(HeatPump_today, HeatPump_compressor_count.deltaSince(now.toDateMidnight).intValue)

Will put the compressor starts of today into the item, which you can easily display. And of course this can be done for all times you want, but it is not that easy (for me to explain) to define the “when thing”

Ok, thank you! That´s exactly what i want. I have some similar rules (min max Temp heting pump brine for the last 7 days and so on…)

When i can do it the same way, then it´s ok.

This is not working.

rule "Kompressor Starts zählen"
        Item HeatPump_state_compressor1 changed from OFF to ON
        postUpdate(HeatPump_compressor_count, HeatPump_compressor_count.intValue + 1)

Where could be the error?


In every rule i only use “end” and all other rules are working without any problems.

I tested with some “val”, but this was also no success.

I made a logging-info to check, if the rule is triggered at all with “changed from off to on”.

If this will not work, i will have to make a helping rule to trigger, when compressor was off and first gets command on. If i only trigger received “command on”, i will get counts every 60 seconds.

Here’s a copy of my rule also counting starts of the heatpump compressor:

rule"Log kompressor start/stop"
	Item Heatpump_Compressor_start changed to ON
	postUpdate(Heatpump_start, (Heatpump_start.state as DecimalType + 1.0))

This works and can be displayed with persistence also…

What exactly is “not working”?

Check your events.log if there is a change in HeatPump_state_compressor1
Do some logInfo(“TEST”;"Count: "+HeatPump_compressor_count.intValue) in your rule.
Is there anything in the openhab.log? Coming up with an error?

It seems, that the rule gets not triggered??? I made a logging on first position after the “then”-part. But since this time, compressor was off.

Count is alway 0. Formerly it was “-” , but i made a rule (and removed it afterwards) to send “0” as initial value to the item.

The problem is: I get “Compressor ON” every minute. Also if “Compressor” is not initiated and i get command “on”, i will get 1 count. (Maybe on openhab startup)

But i only want to get a count, when compressor was “off” and changes to"on".

I don´t think, there is any error in the log-files.

I changed the rule to this:

postUpdate(HeatPump_compressor_count, HeatPump_compressor_count.state as DecimalType + 1)

Now it seems to work…

.state as DecimalType

and not .intValue

Thank you for your help.

Which database is the right one to persist this counts? I dont´want to install an external database like mySQL.

So i can use db4o - is this right?

rrd4j is no good choice, because the values will get rounded.
mapDB will only store the last value.

What´s the difference between .intValue and .state as DecimalType???

There is no longer support for db4o in OH 2. If you ever want to generate nice charts I would highly recommend InfluxDB and Grafana. Short of that I’d look into SQLite.

ItemName.state is how you get the current state of your Item.

Each type of Item has its own type of state. A Number Item has a DecimalType for its state whereas a DateTime Item will have a DateTimeType. When you want to do math with an Item’s state, you need to tell the Rules that the state is a DecimalType (as DecimalType).

.intValue is a method on DecimalType which returns the value of the state as a primitive int.

1 Like

But for InfluxDB and SQLite i need to install an external database?

No longer all in openhab-directory like mapDB, rrd4j and 4dbo?

SQLite is an embedded database that I think stores its data in the OH directory. Influx is an external DB.

I use rrd4j for all charting this (Must!) and it is not rounding (or didn’t I get your point?).
So use this, but I would prefer mysql so you can do your own sql statements to check things. Calculation within rules would be the same.

rrd4j “compresses” the data as it gets older by taking several near by values and replacing them all with a single average of those values. So as your data gets older the values become more and more spare and less and less precise.

Therefore, for example, you may have a value every minute but once the data becomes a couple of days old you will have one value every ten minutes which is the average of the once per minute values in that ten minute period.

This is what @halloween means by rounding.

In practice for many if not most use cases this isn’t a problem because the precision of data a week, month, year or older doesn’t have to be as high as recent data. But some use cases do require all the precision for this older data.