@sihui, does the LWT get sent if the broker itself goes down? I was under the assumption that the LWT was sent by the broker when a client goes down and there is no LWT message for when the broker itself goes down.
One approach I documented here. Basically, have a Switch get updated to ON every time a message is received and set a Timer (Expire binding) to set it to OFF after a certain period of time. When it goes to OFF you know that the device hasn’t reported in awhile and is probably offline.
This works best if you have relatively regular messages so you can say with confidence “if I don’t receive a message in x minutes I know the service is down.”
One thing you can do is implement this heartbeat yourself inside OH itself. Set up two MQTT Items, one outgoing and one incoming on the same topic. Periodically post a message and set the timer described above on the incoming Item.