Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between postUpdate and sendCommand in openHAB

Tags:

openhab

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?

like image 769
sja Avatar asked Mar 11 '15 08:03

sja


2 Answers

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.

like image 175
Alex Avatar answered Nov 12 '22 07:11

Alex


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().

like image 27
Prashant Goswami Avatar answered Nov 12 '22 07:11

Prashant Goswami