Item state is not updated in a rule

Hi,

I have been using OH2.0 for some time and recently moved to 2.1
I get this weird behavior that I don’t remember I saw before - the state of an item is updated after the rule started running:

Number   boiler_p         "Power"             (Boiler)
rule "Boiler settings update"
  when
    Item boiler_p received command
  then
    logInfo("Boiler", receivedCommand.toString + " " + boiler_p.state);
    Thread::sleep(500);
    logInfo("Boiler", receivedCommand.toString + " " + boiler_p.state);
end

When I change the item’s state through the UI, the log output is usually:

2017-07-05 12:59:46.497 [INFO ] [clipse.smarthome.model.script.Boiler] - 1 1
2017-07-05 12:59:47.003 [INFO ] [clipse.smarthome.model.script.Boiler] - 1 1

or

2017-07-05 12:59:48.754 [INFO ] [clipse.smarthome.model.script.Boiler] - 0 0
2017-07-05 12:59:49.254 [INFO ] [clipse.smarthome.model.script.Boiler] - 0 0

but once in a while I get this:

2017-07-05 12:59:51.074 [INFO ] [clipse.smarthome.model.script.Boiler] - 1 0
2017-07-05 12:59:51.574 [INFO ] [clipse.smarthome.model.script.Boiler] - 1 1

which means boiler_p.state variable didn’t get it’s right value when the rule started executing, but was updated some time after that.

Any idea what’s going on?

Thanks in advance
Guy.

could you please show your items?

Just added the item to the post :slight_smile:

Here is the complete file:

String   Arduino          "Arduino"                                { serial="COM3@57600", autoupdate="false" }
Number   livingTemp01     "Temperature [%.1f °C]"  <temperature> 
Number   livingHum01      "Humidity [%.1f %%]"     <humidity>
Switch   Arduino_toggle   "Arduino Toggle"


Switch   ac_power         "Power"                  <switch>          (Appliance) { autoupdate="false" }
Switch   ac_i_feel        "I Feel"                 <smoke>           (Appliance)
Number   ac_mode          "Mode"                   <settings>        (Appliance)
Number   ac_temp          "Temperature [%d °C]"    <temperature>     (Appliance)
Number   ac_fan           "Fan Speed"              <fan>             (Appliance)

Switch   boiler_sw                                                   (Boiler)
Number   boiler_p         "Power"                  /*<switch>*/          (Boiler)
Number   boiler_h         "Start (Hours)[%d]"      <clock>           (Boiler)
Number   boiler_m         "Start (Minutes)[%02d]"  <clock>           (Boiler)
Number   boiler_d         "Duration[%d]"           <clock>           (Boiler)

isn’t this just a timing issue? if an item received a command, the state has to be updated, which could last a few milliseconds.

what changes, if you don’t trigger the rule with “received command” rather than “received update”? I think that should “solve” it, right?

1 Like

To add a bit of explanation, sending an Item a Command does not automatically or immediately change its state.

Most items have the autoupdate feature left on by default, which you can think of like another binding. Eventually, autoupdate receives the Command and creates a state change for the Item. That might be before or after other bindings have dealt with the command (some bindings will update the Item then, some will wait for a response from an end device, some do nothing), and before or after rules have been triggered by the command etc.

You can have rules behaving more predictably by careful decisions about triggering on command, or on update, or on change.

You can make the Item behaviour different by turning autoupdate off for that Item.

3 Likes

spy0r, rossko57 - thanks a lot for the explanations - this solved my problem :slight_smile: