[Solved] OH2 Rule not executing

Hello community,

i seem to have hit a snag with my OH2 testing - trying to run my first rule.
Basically, i’m getting counter values from KNX and want to persist additional values (for charts, later) after some calculation.

This is the rule i’m talking about:

var Number prevHeizung = 0
var Number curHeizung = 0
var Number resHeizung = 0

rule "Stromzahler Heizung Berechnung"
when
  Item Stromzahler_Heizung received command
then
  prevHeizung = Stromzaehler_Heizung.previousState.state
  curHeizung = receivedCommand
  log.Info("Previous Heizung: " + prevHeizung)
  log.Info("Current Heizung: " + curHeizung)
  
  if (prevHeizung == NULL) {
      prevHeizung = 0
  }
  
  resHeizung = curHeizung - prevHeizung
  
  if (resHeizung < 0) { resHeizung = 0 }
  Stromzaehler_Heizung_Watt.sendCommand(resHeizung * 60)
end

After saving, openhab.log shows me that it reloaded the rule, but when the next command comes for Stromzaehler_Heizung, only the new value gets persisted, nothing is shown about the rule and the other value is not updated.

My best guess is that i’m missing something pretty obious, so please, someone, tell me what’s wrong :blush:

It should read
logInfo (“MyRule”,"Current Heizung: " + curHeizung)
logInfo expects at least two strings.

Are you sure that Stromzaehler_Heizung receives commands? Maybe it’s only updated, then the rule should trigger on received update, not on received command

Thank you @opus, i wasn’t aware of that. However, i would expect an exception in openhab at least at runtime when i try to run an invalid command in a rule - which it doesn’t. Actually, the only output from openhab after saving the rule is

2017-01-02 22:01:53.371 [INFO ] [el.core.internal.ModelRepositoryImpl] - Loading model 'stromzaehler.rules'

Plus, i added those logInfos just to see the values, because nothing got updated - hence my guess that i’m missing something pretty obvious.

@Udo_Hartmann I had postUpdate() in use before and changed it, because nothing got updated - but to no avail. Actually, i use the same rule for another counter as well, which updates more frequently, and the eventlog shows this (but nothing about the Power items):

2017-01-03 12:42:55.053 [ItemCommandEvent          ] - Item 'Stromzaehler_Heizung' received command 219381
2017-01-03 12:42:55.059 [ItemStateChangedEvent     ] - Stromzaehler_Heizung changed from 219380 to 219381
...
2017-01-03 12:43:07.460 [ItemCommandEvent          ] - Item 'Stromzaehler_Gesamt' received command 2168318
2017-01-03 12:43:07.464 [ItemStateChangedEvent     ] - Stromzaehler_Gesamt changed from 2168315 to 2168318

The items are defined as follows:

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

not the same Item as

1 Like

Thank you @rossko57 for the hawkeye - it was really just that typo!