Set status of items from tahoma plugs correctly after system restart

After a system restart all my tahoma plugs have no status. But I would like to be able to see the status in my Basic UI. For this reason I want to make a rule which always is activated after system restart. I know how to publish a command so that the plug sends it status via MQTT, but I’m not sure how I can read this in my rule so I can postUpdate(<new_state>) it to my item.

  • Hardware: Synology NAS DS716+ with Paketinstallation for OpenHAB and Mosquitto
  • Java Runtime Environment: Java 8 1.8.0_241
  • openHAB version: 2.5.2

Here my rule with comments where I don’t know how to solve it. I need help with the line which says pseudo-code.

rule “Reset plug status after system startup”

when
System started

then
val brokerName = “mqtt:broker:mosquitto”
val actions = getActions(“mqtt”, brokerName)
actions.publishMQTT(“cmnd/plug/tasmota/01/POWER”,“”, false)

// MQTT console on the plug shows now the following response:
//MQT: stat/plug/tasmota/01/RESULT = {"POWER":"ON"}
//MQT: stat/plug/tasmota/01/POWER = ON

// read the result here:
val result = receivedResultOnTopic(stat/plug/tasmota/01/POWER) //pseudo code (please help)

//write it in the item without causing any implicit actions
PlugTasmota01.postUpdate(result) 

end

Uh, if you just send your “prompt” message, why wouldn’t the normal MQTT binding subscription take care of the eventual response?

There is no way to listen in the middle of a rule for an MQTT message that may come in seconds or years or never.

EDIT - thinking on this, if the usual command topic for your channel is the same (or perhaps it’s a read-only Item), you should be able, perhaps with the help of a transform, to configure it to do what you want as an action for a REFRESH command to the Item.
All the topic configuration stuff is then staying with the channel, you need only issue
myItem.sendCommand(REFRESH)

@rossko57: You are absolutly right. The following code is fully working:

rule “Reset plug status after system startup”
when
System started
then
logInfo(“Plugs”, “Reset plug status after system startup”)
val brokerName = “mqtt:broker:mosquitto”
val actions = getActions(“mqtt”, brokerName)
actions.publishMQTT(“cmnd/plug/tasmota/01/POWER”,“”, false)
actions.publishMQTT(“cmnd/plug/tasmota/02/POWER”,“”, false)
actions.publishMQTT(“cmnd/plug/tasmota/03/POWER”,“”, false)
end

The alternativ with REFRESH would be much nicer but is not working in my case because the topic which gives the status is:tele/plug/tasmota/03/STATE = …
This topic is not connected so I stay with version 1.

not working:

rule “Reset plug status after system startup”
when
System started
then
logInfo(“Plugs”, “Reset plug status after system startup”)
PlugTasmota01.sendCommand(REFRESH)
PlugTasmota02.sendCommand(REFRESH)
PlugTasmota03.sendCommand(REFRESH)
end

Thank you @rossko57