Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mqtt] support availability transformation in generic mqtt thing #10226

Closed
mdeanda opened this issue Feb 24, 2021 · 5 comments · Fixed by #12167
Closed

[mqtt] support availability transformation in generic mqtt thing #10226

mdeanda opened this issue Feb 24, 2021 · 5 comments · Fixed by #12167
Labels
enhancement An enhancement or new feature for an existing add-on

Comments

@mdeanda
Copy link

mdeanda commented Feb 24, 2021

i have a few devices that send availability messages to some topic /status that are json and include a little bit of extra metadata:

ONLINE:

{"status":"ONLINE", "timestamp": .... }

OFFLINE:
{"status":"OFFLINE", ...}

oh3 doesn't let me extract the "status" field from the json so the thing always shows up as offline

@mdeanda mdeanda added the enhancement An enhancement or new feature for an existing add-on label Feb 24, 2021
@jochen314
Copy link
Contributor

The availability is thought of to be used with and LWT message from the device.
Ithe the device can still send messages, then it is still available.

@mdeanda
Copy link
Author

mdeanda commented Mar 7, 2021

@jochen314 yeah its how i'm using it, but in my device, (an esp32 using autoconnect) i have the device auto-restart if it detects the network dropped and it actually reconnects (and sends the "online") before the LWT message gets to the oh3 client. for example:

time   normal flow                                  after device restart
-------------------------------------------------------------------------
   1   online
   2   online
   3   online
   4   online
... [network is detected as down somewhere in here]
  10                                                online
  11   offline (lwt)
  12                                                online
  13                                                online

so my solution for this situation was to just send online messages every few minutes. all my messages from the app i made are as json and include timestamps for potential tracking/logging use. by sending the messages every few minutes, it prevents a restarted device from getting stuck in offline because of a slow-to-arrive LWT message.

@jochen314
Copy link
Contributor

There should not be an out-of-order of messages in a single topic.
When the device

  1. Sends an 'Online' message on topic 'state' (QoS: 2, retained: true) once online.
  2. Sets an LWT 'Offline' on topic 'state' (QoS: 2, retained: true)

Then openhab will get the messages in the correct order.

@openhab-bot
Copy link
Collaborator

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/mqtt-lwt-things-definition-availability-topic/103065/22

@jimtng
Copy link
Contributor

jimtng commented Jan 30, 2022

This is a duplicate of #10632

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature for an existing add-on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants