Telegram rule and updated items race condition?

The Telegram binding has a number of channels, for example lastMessageText, lastMessageUsername or chatId. When I write a rule that reacts on one of those, can I be sure that the other items were updated for the received message before the rule fires, or can there be a race condition (i.e. the rule code runs, but one of the items that were not in the rule conditions still has the value of the previously received message)?

No, you cannot be certain.

The simple kludge is to run a short delay before processing.

The more assured way, where you are expecting all of a “set” of Items to be updated -

Thank you for the pointer to a workaround. As I’m new to openHAB, I have a feeling that this is a core functionality that is lacking. This is something that should be able to be put into the rule conditions (i.e. react on multiple items if they were all updated in the last x milliseconds)

Everybody thinks that the feature that they want should be a core function. In reality, this particular problem does not often arise - probably by luck, as everything has sorted itself out by the time a rule plods along to use values.

But of course you are very welcome to offer enhancement suggestions in github.
It sounds like something that could be implemented as a Group Item function.

Group:Switch:BATCH(600)

Switch turns ON when all members are updated within a 600mS window, turns OFF at next member update.

By setting up some groups…

Group:DateTime:LATEST gTelegramLatest "Last Telegram update times: Latest"
Group:DateTime:EARLIEST gTelegramEarliest "Last Telegram update times: Earliest"

String lastMessageText "Last message text [%s]" {channel = "telegram:telegramBot:620b3747:lastMessageText"}
DateTime lastMessageText_Lastupdate "Last message text: time [%1$tA, %1$tB %1$te, %1$tY at %1$tl:%1$tM%1$tp]" (gTelegramLatest, gTelegramEarliest) {channel = "telegram:telegramBot:620b3747:lastMessageText" [profile="timestamp-update"]}

String lastMessageURL "Last message URL [%s]" {channel = "telegram:telegramBot:620b3747:lastMessageURL"}
DateTime lastMessageURL_Lastupdate "Last message URL: time [%1$tA, %1$tB %1$te, %1$tY at %1$tl:%1$tM%1$tp]" (gTelegramLatest, gTelegramEarliest) {channel = "telegram:telegramBot:620b3747:lastMessageURL" [profile="timestamp-update"]}

… you can then do some checks in your rules to ensure all Items are in sync. This example checks to see if all Telegram Items have been updated within 5 seconds…

from java.time.temporal import ChronoUnit

if gTelegramEarliest.state.zonedDateTime.until(gTelegramLatest.state.zonedDateTime, ChronoUnit.SECONDS) < 5:
    # do stuff
1 Like