Hi !

I have a problem with persistence and out of ideas how to build a rule :confused:

What I want to achieve is to count how many times I used fireplace. Fireplace has controller which provide me open/close signal (via GPIO) if requested temp is achieved. Some times in the first phase it is 20-40minutes it changes open/close few time (because temp is fluctuate) . Which I want to avoid and filter it.

So I have this rule:

rule "Fireplace starter update"
Item Fire changed from CLOSED to OPEN
postUpdate(Fire_Counter, 1+ (Fire_Counter.state as DecimalType))

It will not work, because rule is triggered by this item change, so condition will be not meet. How to check similar condition (item change history), but without last time or last minute ?

Maybe any other idea how to count it ?

I’m reading that your core problem is that your fireplace valve is controlled by a thermometer, so it cycles on/off as necessary to maintain your preset temperature. So each time it opens/closes probably isn’t what you want to count (since you didn’t turn it off/on), that you’re instead looking for how many times you did it.

And I’m making the assumption that the fireplace controller itself isn’t openhab controllable, right?

Could you take an average of Fire.state over the last hour (I’d map OPEN to 1, CLOSED to 0), and then every time the rolling average goes above 0.5 increment Fire_Counter ? (The actual comparison number you’d have to determine by experimentation, of course!) It wouldn’t get you an immediately accurate count, but it should give you a decent approximation of usage over time.

Yes it is fireplace controller, so it is not openhab device :). I can set on which parameter switch will be change, but it have to be buffer temperature. Sometimes it is change, but only on the beginning, like yesterday:

Green line is fireplace, I can not make it bigger but ca 22:00 it changed two times, then it was constant OPEN ( at 9:00 o’clock I have just check controller manually, that’s why it changed). It should count a change on 21:00 and dont react on next 120minutes changes.
So algorithm should check if it first time changed from closed to open on last 120minutes or nor, if yes counter++. Average can give me result which I think will be hard to recognize - which state it is in fact.

The problem is that your device shut off and restarted quickly, which is going to be tricky (but not impossible) to detect.

But a rising average (in blue) is going to be pretty easy to code, and would also completely filter out your event after 9:

I’m all about being lazy when coding! :smiley:

It is not bad solution :). Question is what will be average from open and close values?

That will depend on how long you average the value for! I’d suggest averaging over at least ten minutes, and picking a value (say 0.5) and acting when the average goes above/below that point.

The amount of time and the number will both probably need fine tuning, but they’re things that have to be found through experimentation. I suggest lots of outputting to the log.

ok, but values are: Open (not 0), Close (not 1) - so even I will check 80minut, when 40minutes was Close and 40mun was Open, what will be average if contact has just two values ?