KNX Polling interval

Hello community,

i am trying to achieve that a few items, which are bound to my knx bus, do not get updated as the values are send to the GA by the powermeter, but only at a defined interval of 60 seconds. Only then calculations on this item make sense to me.

The items look as following:

Number  Stromzaehler_Heizung  "Stromzähler Heizung"  (gPersist) { knx="<(60)13.001:0/3/0" }
Number  Stromzaehler_Gesamt  "Stromzähler Gesamt"  (gPersist) { knx="<(60)13.001:0/3/1" }

But still, whenever a new counter value arrives at the GA, the item gets updated, persisted and calculated - every few seconds or so, depending on what i tell the actor should be the number of increments before it posts it to the bus.

Can someone please point me in the right direction?

Hi @astrnad,

In theory, you could set autoupdate=false and then use a rule every 60 secs to update the status of the item by reading it on the KNX Bus.

I don’t know if you can avoid the rule by using the (60) secs auto-refresh parameter in the item definition… maybe this would work:

Number  Stromzaehler_Heizung  "Stromzähler Heizung"  (gPersist) { knx="<(60)13.001:0/3/0", autoupdate="false" }
Number  Stromzaehler_Gesamt  "Stromzähler Gesamt"  (gPersist) { knx="<(60)13.001:0/3/1", autoupdate="false" }

BR,
Dim

@Dim Thank you for the input, but no dice - with the autoupdate set to false, i can see the commands come in for the items in the log, but the value doesn’t change anymore.

That would actually be ok, if there was a way to trigger a read for an item in a rule, but then i found the following post:

I hope that there will be a way soon to trigger a read from a binding for a specific item without touching the items file.

In fact, if the power meter sends the updates every 60 seconds, you don’t have to set any autoRefresh, this parameter is only for those items, where the knx sensor does not provide cyclic transmission, so openHAB asks for the value periodic.

You could define the persistence group not to store at everyChange but only everyMinute.
If calculating values through a rule, you would just trigger the rule with Time cron "0 * * * * ?", once a minute…

I forgot to mention that the actor sends to the bus every n counted impulses, not in a time-oriented manner :sweat:

Even if the value got persisted only once a minute, that would be the wrong count of impulses i think, because the count wouldn’t coincide with every minute and thus my wattage would be off.

Is there any way planned to trigger a read for an item from KNX (or any other binding)?

Ok, now things have become even more uncomprehensible for me (i hope this doesn’t count as hijacking my own thread :smile:):
I tried to be smart and set the rule to calculate a value between the two last historicstates on a cron trigger as @Udo_Hartmann suggested as follows:

var Number prevGesamt = 0
var Number curGesamt = 0
var Number resGesamt = 0

rule "Stromzaehler_Gesamt_Berechnung"
when
  Time cron "0 * * * * ?"
then
  if (Stromzaehler_Gesamt.previousState == null ||
      Stromzaehler_Gesamt.previousState.previousState == null) {
	    prevGesamt = 0
	  }
  if (Stromzaehler_Gesamt.previousState == null) {
    curGesamt = 0
  }
  prevGesamt = Stromzaehler_Gesamt.previousState.previousState.state
  curGesamt = Stromzaehler_Gesamt.previousState.state
  
  resGesamt = curGesamt - prevGesamt
  if (resGesamt < 0) { resGesamt = 0 }
  Stromzaehler_Gesamt_Watt.postUpdate(resGesamt * 60)
end

This invokes a error every minute in openhab.log:

2017-01-07 09:46:00.047 [ERROR] [ntime.internal.engine.ExecuteRuleJob] - Error during the execution of rule Stromzaehler_Gesamt_Berechnung: An error occured during the script execution: The name '<XMemberFeatureCallImplCustom>.previousState' cannot be resolved to an item or type.

So i need to find out how to access the previousState of a previousState if that exists.

Nevertheless even though i set the persistence to everyMinute, no item gets persisted anymore…

Strategies {
	// if no strategy is specified for an item entry below, the default list will be used
	everyMinute	: "0 * * * * ?"
	every5Minutes : "0 */5 * * * ?"
   	everyHour   : "0 0 * * * ?"
   	everyDay    : "0 0 0 * * ?"
   	default = everyChange
}

Items {
    // persist all items once a day and on every change and restore them from the db at startup
    //* : strategy = everyChange, everyDay, restoreOnStartup

	gPersist* : strategy = everyMinute, restoreOnStartup
	
    // additionally, persist all temperature and weather values every hour
    //   gTemperatur* : strategy = every5Minutes, restoreOnStartup
}

If the actuator sends every n counts, isn’t it possible to reconfigure it? If not, is the R-flag set (german: L-Flag)? Otherwise, the actor would not respond to read requests.

In question of the error: No, there is no such state as myItem.previousState.previousState.state. Easiest way would be to get the previous state and store it at the end of the rule, so next time this would be the state before previousState.

But you also could work with a historicState right before the previousState.

EDIT: typo :slight_smile: actuator, not actor… :wink:

I’m afraid it’s a simple Binary Input device (MDT BE-08000.01 Input 8-fold, 4TE, potential-free), it can handle all kinds of things (amongst being Light-Switches with press-and-hold etc), but setting it to sending every minute doesn’t seem to be possible. I can only set the increments after which it pushes the counter to the bus and change the flanks on which it reacts with the counter. 1000 impulses equal 1 kWh in my setup, and it’s transmitting every 5 impulses. R (L)-Flag is set for both of the inputs, so reading should be possible.

Could you elaborate on storing the previousState (do you mean define another item and persist it?) and historicState?

Did you test reading from ETS?

Hi @Udo_Hartmann,

thank you for your continuing support on this (and other) issue :smile:

I just fired up my ETS4 and read from the GA (see screenshot below), the actor answers fine. What’s strange is though that OH2 seems to write the value to the bus again (but i think i read about that issue on another topic).

In question of historicState… There are many different ways to use this. A simple rule:

// myCounter, myMinuteCount are items of type Number
rule "my rule"
when
    Item myCounter changed
then
    myMinuteCount.postUpdate((myCounter.state as DecimalType) - (myCounter.historicState(now.minusMinutes(1)).state as DecimalType))
end

This would calculate the number of pulses in the last 60 Seconds, with an accuracy of +4/-0, as maybe the counter was updated 59.9 Seconds ago…

I changed my rule according to your suggestion, now i can see that the wattage item gets updates from the rule. I would like to see how this plays out, but i think something is off with my persistence settings for these items, as neither the impuls counter nor the wattage item gets persisted, even though there are new values posted.

Number  Stromzaehler_Gesamt        "Stromzähler Gesamt"                   (gPersist) { knx="<13.001:0/3/1" }
Number  Stromzaehler_Gesamt_Watt   "Stromzähler Gesamt Leistung [%s W]"   (gPersist)

and


Strategies {
	// if no strategy is specified for an item entry below, the default list will be used
	everyMinute	: "0 * * * * ?"
        every5Minutes : "0 */5 * * * ?"
   	everyHour   : "0 0 * * * ?"
   	everyDay    : "0 0 0 * * ?"
   	default = everyChange
}

Items {
    // persist all items once a day and on every change and restore them from the db at startup
    //* : strategy = everyChange, everyDay, restoreOnStartup

    gPersist* : strategy = everyMinute, restoreOnStartup
        gHeizung* : strategy = every5Minutes, restoreOnStartup
	
}

But there is no hint in the logs as to why they don’t get persisted to jdbc (the other items in group gHeizung do fine…)

I even had to insert a starting value for the impulse counter manually into the database to keep the rule from crashing because there was no historicState to be found…

Hmm… that’s strange, I don’t see any mistakes. What kind of database do you use through jdbc?

Is jdbc the default persistence service?

It’s a MariaDB, using jdbc.mariadb as default driver (set through PaperUI everywhere i could find). As i said, the other group persists fine (even though there where some initial hickups like persisting values twice).

I can’t actually remember, but the impulse counter value was persisted once, but testing around with the rule i changed the item so many times i can’t remember what the combination was when it was persisted. I’ll dig into knx and karaf to see what the debug logs have to say about that.

Thank you @Udo_Hartmann!