6

In a rules file in openHAB I can execute postUpdate and sendCommand. What is the difference?

I noticed, that when I use postUpdate(zwaveLamp1, ON), only its value is changed, no actions are performed - the light stays dark. sendCommand(zwaveLamp1, ON) will perform the bound action and switch the light on and the item is updated.

Whats the use case of postUpdate? What is it good for?

sja
  • 2,064
  • 2
  • 18
  • 22

5 Answers5

1

Commands are discrete, whereas states appear to be more fleeting. That is, if you run a rule triggered by "Item X received command", you can use the variable "receivedCommand" in the rule to execute something, and the rule gets triggered for every command. However, you have to read the current state off the Item or use previousState for the previous state.

I found for an item that updates its state a lot, the gets triggered for one change, but by the time you read the item's state it may have changed again; it's always the current value that is returned. That's exactly how it should be. If, however, you're using the state as a pseudo incoming queue from MQTT or some external source, you'll lose messages. If they come in as commands, you won't.

Alex
  • 11
  • 1
1

If you want to update the current state of any element of interface or device (for e.g. temperature), then you can use postUpdate() and if you want to perform any action event (for e.g. light on/off) then you can use sendCommand().

0

Yes, correct from my point of view. postUpdate works "internally" on the Item, sendCommand acts the 'command' towardsthe peripheral/interface. marco

marco_m
  • 16
  • 1
  • 3
0

You can make a switch item bound to nothing; let's say you want to make a switch item EmailToggle. If you put the toggle on your site map you can turn emails on and off; then, upon startup, you can postUpdate it and set it from unitialized to OFF or ON. The toggle can then be used to determine if you want emails to happen based on a rule.

I've seen this work and I've seen it not work. Seems buggy.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
rich
  • 1
0

Check out the updated openHab documentation here : Its much more clear now: A table shows what the effect is of manipulating items:

Command \ Rule Trigger    received update     received command    changed
--------------------------------------------------------------------------
postUpdate                  ⚡ rule fires        ❌               (depends)
sendCommand                   ❌              ⚡ rule fires       (depends)
Change through Binding      ⚡ rule fires      ⚡ rule fires       (depends)
Paschi
  • 143
  • 7