[SOLVED] How to check client device (ESP8266) offline

I am using ESP8266 to send LDR sensor value to openhab (2.4) via MQTT.
Problem is when ESP8266 is offline then openhab captured last value of LDR but it is not getting flushed.

Can any one please help me.

Sorry for wrong English.

So you want the value to change to UNDEF if no further updates are received?

1 Like

You are correct @J-N-K

Two ways (there may be more) come to mind to achieve what you want, but it will depend on your setup:

  • you could use the expire binding; this will work best if your sensor is configured to send updates at regular intervals and if you set the expire time to, say, three times the the update interval just to make sure that it does not flip/flop too often.
  • you can configure in MQTT a LWT (last will and testament) message, subscribe to it and have a rule trigger if this channel gets updated and set your item to UNDEF. (This approach presumes that you have not switched off the heartbeat functions)

Thank you very much @lipp_markus i have followed 1st method it is working like charm.

  1. I have installed expire binding.
  2. I have added LDR as string item in .items file
  3. I have done changes in item as below.
String LDRR   "LDRR" (gFF, Lights) { expire="30s,state=NOTReachable" }
1 Like