stuartpittaway / diyBMSv4ESP32

diyBMS v4 code for the ESP32 and new controller hardware
Other
166 stars 78 forks source link

Feature request: MQTT Last Will Topic (LWT) #261

Closed Roelaynd closed 7 months ago

Roelaynd commented 7 months ago

Please correct me if I'm wrong, but it appears that the MQTT integration has no LWT (Last Will Topic)?

Could you please add this functionality if it isn't already? The other MQTT devices I have here have their LWT configured as "Online" when the connection is there and "Offline" when not. The benefit is that when logged, it can give insight in connection stability and such. Also it is an easy way to check for (Home Assistant) automations if the connection is still available and to act accordingly.

Background information: https://www.hivemq.com/blog/mqtt-essentials-part-9-last-will-and-testament/

stuartpittaway commented 7 months ago

Added LWT to the MQTT configuration.

This outputs a new "alive" parameter in the status JSON data. Normally a value of "1" is output during normal operation, should the controller go offline, that changes to zero - it can take a minute or two for the MQTT broker to realise.

emon/diybms/status {"alive":0}

Roelaynd commented 7 months ago

Will test when I've got the possibility somewhere in the next two weeks.

Roelaynd commented 7 months ago

It does indeed take a minute or two for the broker to notice, also signalling the alive status takes a couple of minutes. Works great for the purpose anyway!