eclipse-archived / smarthome

Eclipse SmartHome™ project
https://www.eclipse.org/smarthome/
Eclipse Public License 2.0
862 stars 783 forks source link

[MQTT 2.4] No way of publishing with retain #6745

Open robygi opened 5 years ago

robygi commented 5 years ago

I made a thing:

Thing topic mytopic "Description"  {
     Type string : mytopicstring "Description2" [
         stateTopic="OH2/mytopic",
         commandTopic="OH2/mytopic",
         retained=true
    ]
}

Then I linked it via PAPER UI to the following item:

String mytestItem "My test item" { channel="mqtt:topic:mytopic:mytopicstring" }

I wrote a rule for the switch item test :

rule "Test switch changed"
when
     Item test changed
then
    if (test.state == ON) {
        sendCommand(mytestItem, "testvalue1")
    } else {
        sendCommand(mytestItem, "testvalue2")
    }

When the item test changes no message is publish to the mqtt broker. The log shows the following messages:

12:59:53.733 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'test' received command ON
12:59:53.759 [INFO ] [smarthome.event.ItemStateChangedEvent] - test changed from OFF to ON
12:59:53.770 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'mytestItem' received command testvalue1
12:59:53.781 [INFO ] [arthome.event.ItemStatePredictedEvent] - mytestItem predicted to become testvalue1
12:59:55.646 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'test' received command OFF
12:59:55.663 [INFO ] [smarthome.event.ItemStateChangedEvent] - test changed from ON to OFF
12:59:55.677 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'mytestItem' received command testvalue2
12:59:55.687 [INFO ] [arthome.event.ItemStatePredictedEvent] - mytestItem predicted to become testvalue1

Even using postUpdate instead of sendCommad no message is published to mqtt. The log is as follow:

12:57:25.657 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'test' received command ON
12:57:25.688 [INFO ] [smarthome.event.ItemStateChangedEvent] - test changed from OFF to ON
12:57:25.710 [INFO ] [smarthome.event.ItemStateChangedEvent] - mytestItem changed from testvalue2 to testvalue1
12:57:27.279 [INFO ] [smarthome.event.ItemCommandEvent     ] - Item 'test' received command OFF
12:57:27.304 [INFO ] [smarthome.event.ItemStateChangedEvent] - test changed from ON to OFF
12:57:27.408 [INFO ] [smarthome.event.ItemStateChangedEvent] - mytestItem changed from testvalue1 to testvalue2

It seems that with sendCommand the value of the item is “predicted” to became always the last updated value (in this case testvalue1, from a previous test), while with postUpdate the value in OH is changed accordingly to the statement but in both cases there is no publish to mqtt.

maggu2810 commented 5 years ago

Please use triple backticks for code blocks, multiline pre-formatted text etc. One backticks should be used for in-line highlight / code parts only.

robygi commented 5 years ago

@maggu2810 I apologize for the mistake. I've corrected it now.

maggu2810 commented 5 years ago

No problem, it is just better to read this way.

nejck-ikservis commented 4 years ago

Any update on that?