postUpdate of proxy items

Is it correct to say that whenever you have a proxy item (or virtual item) which does not trigger any rules and should just store and dispaly data, it is ok to use postUpdate and not sendCommand?
What’s the effect behind the scenes? Is postUpdate processed faster/ with less resources?

EDIT: what about persistence? Is postUpdate affecting persistence maybe?

See Rules | openHAB for details. At a high level, you sendCommand when you are trying to cause something to happen (e.g. turn on the light). postUpdate is for updating an Item to reflect a new state.

Note that not all commands result in an update. Not all commands can be an Item’s state (e.g. INCREASE/DECREASE). The update to the Item that results from a command may not be the same as the command even if it’s a valid state for the Item.

Thanks Rich, that’s clear. I was more wondering about if postUpdate uses less resources / is faster as sendCommand.
Sure, it is more of an academical view as sendCommand is processed within a few hundreds of a second or maybe there are any other “advantages” in case of proxy Items (which do not trigger any other rule).

Maybe an example. If you have two lines of code:


I would assume by using sendCommand that there might be cases where you read the proxyItem’s state (line 2) but it hasn’t been “updated” (by line 1) yet.

Ultimately the question is the wrong question. The amount of resources doesn’t matter. sendCommand and postUpdate have to completely different purposes. They are not interchangable.

If your only intent is to change the state of an Item, you should always use postUpdate. If you are wanting to cause a device to do something, you should always use sendCommand. Whether one uses more or less resources is irrelevant.

That problem exists even with postUpdate. The processing of the event takes place in the background in parallel. Indeed, if you used sendCommand, there’s a higher likelihood that the Item’s state will not yet have reached the new state, but even with postUpdate that’s not guaranteed.

So in short, you should never have those two lines like that. You already know what was sent to proxyItem, Don’t try to pull it back out of the Item immediately after sendCommand or postUpdate. That is never guaranteed to work.

1 Like