MQTT: Previous state

Rich, stop, please. Your understanding me is mixed up.
No item creation. No MQTT back control.
I just use MQTT as interactive item state transport.
OH sends to my application new states. I receive new states and can immediately generate some events.
Another way - OH save new states in DB. I sends query to database every N sec (ms) to get new states.
As you see, the second way (as most part of PH persistence ways) is not preferable.

And all i’ve asked - is it possible to send previous state (like “item state was changed from <> to <>”) via MQTT (MQTT persistance OR MQTT event-bus). And I got the answer - NO, ITS IMPOSSIBLE. And i’ve found another decision. Thanks for replies.

If you had provided these details after I asked for them, twice, I wouldn’t have had to speculate and could have saved us both some time.

This is exactly what MQTT Event Bus and MQTT Persistence does. Every update to every Item in OH gets immediately published as MQTT messages.

Actually this is the first time you have actually asked the question with enough detail to understand what you are trying to do.

And yes, with just Event Bus or Persistence that is true, you can’t do this. But you could easily write a single rule to publish the event states in this format using the MQTT Action.

Ultimately it will probably be easiest to cache the old state in your application

I thought I’ve explained it before, sorry for my English so.

I can’t write rule for ALL items. Maximum I could do - to configure group, add all items there and write rule for group, but it’s not good decision too.

Because…?

And like I said. It is probably easiest if you cached the previous value in your application anyway.

Why is it necessary to send both states in the message? Your application already knows the current state, and when it is updated it will receive the new state. You have all the information already, just not in the exact format you seem to be looking for.

1 Like

I just don’t like this way. 1st - i need to create group and rule. 2nd - i need to add all new items to this group. 3rd - i’ve already tried to perform rule to group. Unsuccessful. The rule works for 1 item and doesn’t for group.

My application knows the current state now. After solution of this topic. I’ve asked before that.
I think OH knows the previous state too that was changed to new one. Easier to send it as feature than implement state caches in every external application. And sync this cache to database.

OK, so the question that Imba actually wanted to ask is this:
is there a way for OH to send the “current state” and the “previous state” in one message/request?

Only if persistence is set up and you do so from a Rule.